diff --git a/lambda-test/adc-test.c b/lambda-test/adc-test.c index bb54600..396ca3f 100644 --- a/lambda-test/adc-test.c +++ b/lambda-test/adc-test.c @@ -47,14 +47,16 @@ } /* Test "class" */ -const char adc_P[] PROGMEM = "adc"; +static const char class[] PROGMEM = "adc"; /* Test names */ -const char testSetupADC_P[] PROGMEM = "testSetupADC"; -const char testGetVoltage_P[] PROGMEM = "testGetVoltage"; +static const char testSetupADC_P[] PROGMEM = "testSetupADC"; +static const char testGetVoltage_P[] PROGMEM = "testGetVoltage"; /* Tests */ -TestCase const adcTests[] = { - {adc_P, testSetupADC_P, testSetupADC}, - {adc_P, testGetVoltage_P, testGetVoltage} +static TestCase const tests[] = { + {class, testSetupADC_P, testSetupADC}, + {class, testGetVoltage_P, testGetVoltage} }; + +TestClass adcClass = {tests, sizeof(tests) / sizeof(tests[0])}; diff --git a/lambda-test/avrjunit.c b/lambda-test/avrjunit.c index e25a256..79e0c72 100644 --- a/lambda-test/avrjunit.c +++ b/lambda-test/avrjunit.c @@ -14,25 +14,33 @@ #include "USART.h" #include "avrjunit.h" -void runTests(char* const suite, TestCase const tests[], size_t const count) { +void beginSuite(char* const suite) { printString("\n"); char tsbuf[128]; - snprintf(tsbuf, sizeof(tsbuf), - "\n", - suite, count); + snprintf(tsbuf, sizeof(tsbuf),"\n"); + + // send EOT + printString("\n"); + transmitByte(4); +} + +void runClass(TestClass class) { + for (size_t i = 0; i < class.size; i++) { char cbuf[24]; char nbuf[64]; char tcbuf[128]; // TODO use strncat (macro?) - strcpy_P(cbuf, (PGM_P)pgm_read_word(&(tests[i].class))); - strcpy_P(nbuf, (PGM_P)pgm_read_word(&(tests[i].name))); + strcpy_P(cbuf, (PGM_P)pgm_read_word(&(class.tests[i].class))); + strcpy_P(nbuf, (PGM_P)pgm_read_word(&(class.tests[i].name))); snprintf(tcbuf, sizeof(tcbuf), "\n", cbuf, nbuf); printString(tcbuf); - FuncPtr test = (FuncPtr)pgm_read_word(&tests[i].function); + FuncPtr test = (FuncPtr)pgm_read_word(&(class.tests[i].function)); bool result = test(); if (! result) { // failure @@ -40,10 +48,4 @@ } printString("\n"); } - - printString("\n"); - - // send EOT - printString("\n"); - transmitByte(4); } diff --git a/lambda-test/avrjunit.h b/lambda-test/avrjunit.h index 2b49867..926e22f 100644 --- a/lambda-test/avrjunit.h +++ b/lambda-test/avrjunit.h @@ -42,6 +42,11 @@ FuncPtr function; } TestCase; +typedef struct { + const TestCase* tests; + size_t size; +} TestClass; + /** * Runs the test cases in the given array and prints the results * via USART in JUnit XML format, using the given test suite name. @@ -50,6 +55,10 @@ * on the receiving side with a command like so: * (stty speed 9600 sane -echo; cat > tests.xml) < /dev/ttyUSB0 */ -void runTests(char* const suite, TestCase const tests[], uint16_t const count); +void beginSuite(char* const suite); + +void endSuite(void); + +void runClass(TestClass class); #endif /* AVRJUNIT_H_ */ diff --git a/lambda-test/command-test.c b/lambda-test/command-test.c index 0910059..6aaa59a 100644 --- a/lambda-test/command-test.c +++ b/lambda-test/command-test.c @@ -34,14 +34,16 @@ } /* Test "class" */ -const char command_P[] PROGMEM = "command"; +static const char class[] PROGMEM = "command"; /* Test names */ -const char testIsSimulation_P[] PROGMEM = "testIsSimulation"; -const char testIsLogging_P[] PROGMEM = "testIsLogging"; +static const char testIsSimulation_P[] PROGMEM = "testIsSimulation"; +static const char testIsLogging_P[] PROGMEM = "testIsLogging"; /* Tests */ -TestCase const commandTests[] = { - {command_P, testIsSimulation_P, testIsSimulation}, - {command_P, testIsLogging_P, testIsLogging}, +static TestCase const tests[] = { + {class, testIsSimulation_P, testIsSimulation}, + {class, testIsLogging_P, testIsLogging}, }; + +TestClass commandClass = {tests, sizeof(tests) / sizeof(tests[0])}; diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 2b35879..d00f41d 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -23,21 +23,13 @@ int main(void) { initUSART(); - extern const TestCase adcTests[]; - extern const TestCase commandTests[]; - extern const TestCase displayTests[]; - extern const TestCase integersTests[]; - extern const TestCase interruptsTests[]; - extern const TestCase sensorsTests[]; - extern const TestCase stringsTests[]; + extern TestClass adcClass; + extern TestClass commandClass; - runTests("lambda", adcTests, 2); - runTests("lambda", commandTests, 2); - runTests("lambda", displayTests, 7); - runTests("lambda", integersTests, 8); - runTests("lambda", interruptsTests, 4); - runTests("lambda", sensorsTests, 16); - runTests("lambda", stringsTests, 2); + beginSuite("lambda"); + runClass(adcClass); + runClass(commandClass); + endSuite(); return 0; }