/** * \file * test cases of project */ #include #include #include "ldf_parser.h" #include "buffer.h" #include "ldf.h" #include "protointerface_test.h" int test(void); int test_BufferVector(void); int test_DEBUGParser(int selection); int test_parser(void); int test_LSB(void); int main(void) { //test_BufferVector(); //test_DEBUGParser(1); test_parser(); //test(); //test_LSB(); return 0; } #define BUFFER_MAX 100 int test(void) { double x; if (scanf("%lf", &x) == 1) printf("double: %f", x); return TRUE; } int test_BufferVector(void) { ProtoInterface protoInterface; BufferVector buffer, *bufferp = &buffer; int testArray[30]; int test; int n; for(n=0; n<30; n++) testArray[n] = n; if (protoInterface_init(&protoInterface, stdout) == 0) return 0; if (bufferVector_init(bufferp, sizeof(int), 16, &protoInterface) == 0) return 0; bufferVector_appendElements(bufferp, testArray, 30); bufferVector_skip(bufferp, 28); bufferVector_appendElements(bufferp, testArray, 30); while (bufferVector_getRemoveElementsCopy(bufferp, &test, 1)) printf("Element: %02d\n", test); bufferVector_destroy(bufferp); protoInterface_destroy(&protoInterface); return TRUE; } #define ASSOCDATA_KEYSTRING_MAX_LEN 20u struct AssocData { char keyString[ASSOCDATA_KEYSTRING_MAX_LEN]; int value; }; static int assocListCompareCB(const void *datap, const void *assocp) { return (strncmp( ((const struct AssocData*) datap)->keyString, (const char*) assocp, ASSOCDATA_KEYSTRING_MAX_LEN)); } static void assocListPrint(const char* keyStringp, struct AssocData *datap) { if (datap) printf("key: %s -> value: %d\n", keyStringp, datap->value); else printf("key: %s -> NOT FOUND!\n", keyStringp); } int test_DEBUGParser(int selection) { ProtoInterface protoInterface; LDFParser parser, *parserp = &parser; int okf = TRUE; okf = (okf && protoInterface_init(&protoInterface, stdout)); okf = (okf && LDFParser_init(parserp, &protoInterface, "input.ldf", 20)); if (selection == 1) okf = (okf && LDFParser_DEBUG_dumpTokenzierTokens(parserp)); else okf = (okf && LDFParser_DEBUG_dumpGrammarTokens(parserp)); if (okf == 0) LDFParser_message_printState(parserp); LDFParser_destroy(parserp); protoInterface_destroy(&protoInterface); return okf; } int test_parser(void) { ProtoInterface protoInterface; LDFParser parser, *parserp = &parser; LDFstruct ldf; int okf = TRUE; const char compositeConfigurationString[] = "testconfig"; okf = (okf && protoInterface_init(&protoInterface, stdout)); okf = (okf && LDF_init(&ldf, &protoInterface, compositeConfigurationString)); okf = (okf && LDFParser_init(parserp, &protoInterface, "input_eventtriggered.ldf", 1000000)); okf = (okf && LDFParser_parse(parserp, &ldf)); if (okf == 0 || (parserp->parserState != LDFPARSER_OK && parserp->parserState != LDFPARSER_ERROR_EOF)) METAMESSAGE(LDFParser_message_printState(parserp)); //LDFParser_message_sourceLocation(parserp); protoInterface_printf(&protoInterface, "\n\tparsing finished!\n"); LDF_destroy(&ldf); LDFParser_destroy(parserp); protoInterface_destroy(&protoInterface); return okf; } int test_LSB(void) { unsigned x = 0xFF80; printf("original value (hex): 0x%04hX\n" , x); printf("original value (unsigned): %hu\n" , x); printf("original value (signed): %hd\n\n" , x); printf("16bit swapped (hex): 0x%04hX\n" , WORDSWAP(x)); printf("16bit swapped (unsigned): %hu\n" , WORDSWAP(x)); printf("16bit swapped (signed): %hd\n" , WORDSWAP(x)); return TRUE; }