#include #include #include #include #include #include #include #include #include #include #include "CppPotpourri.h" #include "StringBuilder.h" #include "ParsingConsole.h" #include "ElementPool.h" #include "GPSWrapper.h" #include "RingBuffer.h" #include "PriorityQueue.h" #include "KeyValuePair.h" #include "LightLinkedList.h" #include "SensorFilter.h" #include "Vector3.h" #include "StopWatch.h" #include "uuid.h" #include "cbor-cpp/cbor.h" #include "Image/Image.h" #include "Identity/IdentityUUID.h" #include "Identity/Identity.h" #include "ManuvrLink/ManuvrLink.h" /******************************************************************************* * Globals *******************************************************************************/ struct timeval start_micros; /******************************************************************************* * Support functions * TODO: Some of this should be subsumed by the general linux platform. * some of what remains should be collected into a general testing framework? * TODO: Research testing frameworks for C++ again. *******************************************************************************/ uint32_t randomUInt32() { uint32_t ret = ((uint8_t) rand()) << 24; ret += ((uint8_t) rand()) << 16; ret += ((uint8_t) rand()) << 8; ret += ((uint8_t) rand()); return ret; } int8_t random_fill(uint8_t* buf, uint len) { uint i = 0; while (i < len) { *(buf + i++) = ((uint8_t) rand()); } return 0; } /* * Not provided elsewhere on a linux platform. */ long unsigned millis() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000L); } /* * Not provided elsewhere on a linux platform. */ long unsigned micros() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * 1000000L + ts.tv_nsec / 1000L); } /* Delay functions */ void sleep_ms(uint32_t ms) { struct timespec t = {(long) (ms / 1000), (long) ((ms % 1000) * 1000000UL)}; nanosleep(&t, &t); } void sleep_us(uint32_t us) { struct timespec t = {(long) (us / 1000000), (long) ((us % 1000000) * 1000000UL)}; nanosleep(&t, &t); } /** * Prints the sizes of various types. Informational only. No test. */ void printTypeSizes(StringBuilder* output) { output->concat("===< Type sizes >=======================================\n-- Primitives:\n"); output->concatf("\tvoid* %u\n", sizeof(void*)); output->concatf("\tFloat %u\n", sizeof(float)); output->concatf("\tDouble %u\n", sizeof(double)); output->concat("-- Singletons:\n"); output->concatf("\tAbstractPlatform %u\n", sizeof(AbstractPlatform)); output->concatf("\tParsingConsole %u\n", sizeof(ParsingConsole)); output->concat("-- Elemental data structures:\n"); output->concatf("\tStringBuilder %u\n", sizeof(StringBuilder)); output->concatf("\tKeyValuePair %u\n", sizeof(KeyValuePair)); output->concatf("\tVector3 %u\n", sizeof(Vector3)); output->concatf("\tLinkedList %u\n", sizeof(LinkedList)); output->concatf("\tElementPool %u\n", sizeof(ElementPool)); output->concatf("\tPriorityQueue %u\n", sizeof(PriorityQueue)); output->concatf("\tRingBuffer %u\n", sizeof(RingBuffer)); output->concatf("\tUUID %u\n", sizeof(UUID)); output->concatf("\tStopWatch %u\n", sizeof(StopWatch)); output->concatf("\tGPSWrapper %u\n", sizeof(GPSWrapper)); output->concatf("\tSensorFilter %u\n", sizeof(SensorFilter)); output->concatf("\tIdentity %u\n", sizeof(Identity)); output->concatf("\tIdentityUUID %u\n", sizeof(IdentityUUID)); output->concat("-- M2M classes:\n"); output->concatf("\tManuvrLink %u\n", sizeof(ManuvrLink)); output->concatf("\tManuvrMsg %u\n", sizeof(ManuvrMsg)); output->concatf("\tManuvrMsgHdr %u\n", sizeof(ManuvrMsgHdr)); output->concatf("\tManuvrLinkOpts %u\n", sizeof(ManuvrLinkOpts)); } void printTestFailure(const char* test) { printf("\n"); printf("*********************************************\n"); printf("* %s FAILED tests.\n", test); printf("*********************************************\n"); } /******************************************************************************* * Something terrible. *******************************************************************************/ #include "StringBuilderTest.cpp" #include "TestDataStructures.cpp" #include "ParsingConsoleTest.cpp" #include "IdentityTest.cpp" #include "ManuvrLinkTests.cpp" /**************************************************************************************************** * The main function. * ****************************************************************************************************/ int main(int argc, char *argv[]) { int exit_value = 1; // Failure is the default result. srand(time(NULL)); gettimeofday(&start_micros, nullptr); StringBuilder out; printTypeSizes(&out); printf("%s\n\n", (const char*) out.string()); out.clear(); if (0 == stringbuilder_main()) { if (0 == data_structure_main()) { if (0 == parsing_console_main()) { if (0 == identity_main()) { if (0 == manuvrlink_main()) { exit_value = 0; } } } } } exit(exit_value); }