Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
TestManager.cpp@35:6867af70c51c, 2012-09-13 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 13 12:17:18 2012 +0000
- Revision:
- 35:6867af70c51c
- Parent:
- 33:16126e029d58
- Child:
- 36:dd730ff4962e
- Child:
- 37:847f5f86e9ff
Refactoring.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 2:ea883307d02f | 1 | #include "TestManager.h" |
ashleymills | 3:28336c2e94e4 | 2 | #include "Tests.h" |
nherriot | 28:c630a04a7198 | 3 | |
ashleymills | 32:8ff0b67bb58c | 4 | // adds a test into the master test index |
ashleymills | 32:8ff0b67bb58c | 5 | void TestManager::addTest(VodafoneTestCase* testCase) { |
ashleymills | 33:16126e029d58 | 6 | _tests.push_back(testCase); |
ashleymills | 32:8ff0b67bb58c | 7 | } |
ashleymills | 32:8ff0b67bb58c | 8 | |
ashleymills | 32:8ff0b67bb58c | 9 | TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { |
ashleymills | 32:8ff0b67bb58c | 10 | // using direct array indexing instead of searching each time |
ashleymills | 32:8ff0b67bb58c | 11 | // dummy tests are inserted by the addTest function |
ashleymills | 35:6867af70c51c | 12 | _tests.push_back((VodafoneTestCase*)new Test10(m)); |
ashleymills | 35:6867af70c51c | 13 | addTest((VodafoneTestCase*)new Test12(m)); |
ashleymills | 35:6867af70c51c | 14 | addTest((VodafoneTestCase*)new Test13(m)); |
ashleymills | 35:6867af70c51c | 15 | addTest((VodafoneTestCase*)new Test16(m)); |
ashleymills | 35:6867af70c51c | 16 | addTest((VodafoneTestCase*)new Test21(m)); |
ashleymills | 35:6867af70c51c | 17 | addTest((VodafoneTestCase*)new Test22(m)); |
ashleymills | 35:6867af70c51c | 18 | addTest((VodafoneTestCase*)new Test23(m)); |
ashleymills | 35:6867af70c51c | 19 | addTest((VodafoneTestCase*)new Test25(m)); |
ashleymills | 35:6867af70c51c | 20 | addTest((VodafoneTestCase*)new Test26(m)); |
ashleymills | 35:6867af70c51c | 21 | addTest((VodafoneTestCase*)new Test50(m)); |
ashleymills | 35:6867af70c51c | 22 | addTest((VodafoneTestCase*)new Test56(m)); |
ashleymills | 2:ea883307d02f | 23 | } |
ashleymills | 2:ea883307d02f | 24 | |
ashleymills | 22:5b1feecf2aeb | 25 | int TestManager::getTestProfileLength(TestProfile profile) { |
ashleymills | 26:9eefab9e28df | 26 | if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned |
ashleymills | 22:5b1feecf2aeb | 27 | return gTestProfileLengths[profile]; |
ashleymills | 22:5b1feecf2aeb | 28 | } else { |
ashleymills | 22:5b1feecf2aeb | 29 | LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); |
ashleymills | 22:5b1feecf2aeb | 30 | return 0; |
ashleymills | 22:5b1feecf2aeb | 31 | } |
ashleymills | 22:5b1feecf2aeb | 32 | } |
ashleymills | 22:5b1feecf2aeb | 33 | |
ashleymills | 22:5b1feecf2aeb | 34 | int TestManager::executeTestProfile(TestProfile profile) { |
ashleymills | 24:8f0f9551122a | 35 | int numPassed = 0; |
ashleymills | 32:8ff0b67bb58c | 36 | if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned |
ashleymills | 24:8f0f9551122a | 37 | numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); |
ashleymills | 22:5b1feecf2aeb | 38 | } else { |
ashleymills | 22:5b1feecf2aeb | 39 | LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); |
ashleymills | 22:5b1feecf2aeb | 40 | return 0; |
ashleymills | 22:5b1feecf2aeb | 41 | } |
ashleymills | 24:8f0f9551122a | 42 | int numTests = getTestProfileLength(profile); |
ashleymills | 24:8f0f9551122a | 43 | LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); |
ashleymills | 27:0297dbc3252b | 44 | LOG("Listing failures:"); |
ashleymills | 27:0297dbc3252b | 45 | listFailures(gTestProfiles[profile], gTestProfileLengths[profile]); |
ashleymills | 24:8f0f9551122a | 46 | return numPassed; |
ashleymills | 22:5b1feecf2aeb | 47 | } |
ashleymills | 22:5b1feecf2aeb | 48 | |
ashleymills | 27:0297dbc3252b | 49 | void TestManager::listFailures(const int *list, const int listLen) { |
ashleymills | 27:0297dbc3252b | 50 | for(int i=0; i<listLen; i++) { |
ashleymills | 27:0297dbc3252b | 51 | int testIndex = list[i]; |
ashleymills | 33:16126e029d58 | 52 | VodafoneTestCase* test = getTest(testIndex); |
ashleymills | 33:16126e029d58 | 53 | if(test==NULL) { |
ashleymills | 33:16126e029d58 | 54 | LOG("ERROR: Test %d is not in test list!.",testIndex); |
ashleymills | 27:0297dbc3252b | 55 | continue; |
ashleymills | 27:0297dbc3252b | 56 | } |
ashleymills | 27:0297dbc3252b | 57 | |
ashleymills | 27:0297dbc3252b | 58 | if(test->_lastRunOutcome==false) { |
ashleymills | 33:16126e029d58 | 59 | LOG("Test %d:",test->_testCaseNumber); |
ashleymills | 33:16126e029d58 | 60 | LOG(test->_description); |
ashleymills | 27:0297dbc3252b | 61 | } |
ashleymills | 27:0297dbc3252b | 62 | } |
ashleymills | 22:5b1feecf2aeb | 63 | } |
ashleymills | 22:5b1feecf2aeb | 64 | |
ashleymills | 32:8ff0b67bb58c | 65 | VodafoneTestCase* TestManager::getTest(int index) { |
ashleymills | 32:8ff0b67bb58c | 66 | for(int i=0; i<_tests.size(); i++) { |
ashleymills | 32:8ff0b67bb58c | 67 | if(index==_tests[i]->_testCaseNumber) |
ashleymills | 32:8ff0b67bb58c | 68 | return _tests[i]; |
ashleymills | 32:8ff0b67bb58c | 69 | } |
ashleymills | 32:8ff0b67bb58c | 70 | return NULL; |
ashleymills | 32:8ff0b67bb58c | 71 | } |
ashleymills | 32:8ff0b67bb58c | 72 | |
ashleymills | 19:26fbed33d4e7 | 73 | int TestManager::executeTestList(const int *list, const int listLen) { |
ashleymills | 2:ea883307d02f | 74 | int successfullTests = 0; |
ashleymills | 19:26fbed33d4e7 | 75 | LOG("Running %d tests...",listLen); |
ashleymills | 19:26fbed33d4e7 | 76 | for(int i=0; i<listLen; i++) { |
ashleymills | 19:26fbed33d4e7 | 77 | int testIndex = list[i]; |
ashleymills | 33:16126e029d58 | 78 | VodafoneTestCase* test = getTest(testIndex); |
ashleymills | 33:16126e029d58 | 79 | if(test==NULL) { |
ashleymills | 33:16126e029d58 | 80 | LOG("Error. Test %d is not in test list! This will be counted as a failure.",testIndex); |
ashleymills | 19:26fbed33d4e7 | 81 | continue; |
ashleymills | 19:26fbed33d4e7 | 82 | } |
ashleymills | 19:26fbed33d4e7 | 83 | |
ashleymills | 33:16126e029d58 | 84 | LOG("Running test %d...",testIndex); |
ashleymills | 33:16126e029d58 | 85 | if(test->execute()) { |
ashleymills | 2:ea883307d02f | 86 | LOG("...OK"); |
ashleymills | 2:ea883307d02f | 87 | successfullTests++; |
ashleymills | 2:ea883307d02f | 88 | } else { |
ashleymills | 2:ea883307d02f | 89 | LOG("...FAIL"); |
ashleymills | 2:ea883307d02f | 90 | } |
ashleymills | 2:ea883307d02f | 91 | } |
ashleymills | 2:ea883307d02f | 92 | return successfullTests; |
ashleymills | 2:ea883307d02f | 93 | } |
ashleymills | 2:ea883307d02f | 94 | |
ashleymills | 33:16126e029d58 | 95 | bool TestManager::executeTest(int id) { |
ashleymills | 33:16126e029d58 | 96 | VodafoneTestCase* test = getTest(id); |
ashleymills | 33:16126e029d58 | 97 | if(test==NULL) { |
ashleymills | 33:16126e029d58 | 98 | LOG("Error. Test %d is not in test list! This will be counted as a failure.",id); |
ashleymills | 19:26fbed33d4e7 | 99 | return false; |
ashleymills | 19:26fbed33d4e7 | 100 | } |
ashleymills | 19:26fbed33d4e7 | 101 | |
ashleymills | 33:16126e029d58 | 102 | return _tests[id]->execute(); |
ashleymills | 4:1f8e079924ba | 103 | } |
ashleymills | 4:1f8e079924ba | 104 | |
ashleymills | 4:1f8e079924ba | 105 | |
ashleymills | 33:16126e029d58 | 106 | bool TestManager::executeTest(int id, int numTimes) { |
ashleymills | 4:1f8e079924ba | 107 | for(int i=0; i<numTimes; i++) { |
ashleymills | 33:16126e029d58 | 108 | if(!executeTest(id)) |
ashleymills | 4:1f8e079924ba | 109 | return false; |
ashleymills | 4:1f8e079924ba | 110 | } |
ashleymills | 4:1f8e079924ba | 111 | return true; |
ashleymills | 2:ea883307d02f | 112 | } |