Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Thu Sep 06 14:28:01 2012 +0000
Revision:
26:9eefab9e28df
Parent:
24:8f0f9551122a
Child:
27:0297dbc3252b
Started changing test framework to add dependencies.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 2:ea883307d02f 1 #include "TestManager.h"
ashleymills 3:28336c2e94e4 2 #include "Tests.h"
ashleymills 19:26fbed33d4e7 3 TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) {
ashleymills 19:26fbed33d4e7 4 // using direct array indexing instead of searching each time, so need to put in dummy tests
ashleymills 23:408199b5d2cb 5 for(int i=0; i<10; i++) { _tests.push_back(NULL); }
ashleymills 23:408199b5d2cb 6
ashleymills 23:408199b5d2cb 7 _tests.push_back((VodafoneTestCase*)new Test10(_modem,10));
ashleymills 23:408199b5d2cb 8
ashleymills 23:408199b5d2cb 9 for(int i=11; i<12; i++) { _tests.push_back(NULL); }
ashleymills 23:408199b5d2cb 10
ashleymills 20:18373fb68ad7 11 _tests.push_back((VodafoneTestCase*)new Test12(_modem,12));
ashleymills 20:18373fb68ad7 12 _tests.push_back((VodafoneTestCase*)new Test13(_modem,13));
ashleymills 23:408199b5d2cb 13
ashleymills 23:408199b5d2cb 14 for(int i=14; i<21; i++) { _tests.push_back(NULL); }
ashleymills 23:408199b5d2cb 15
ashleymills 20:18373fb68ad7 16 _tests.push_back((VodafoneTestCase*)new Test21(_modem,21));
ashleymills 20:18373fb68ad7 17 _tests.push_back((VodafoneTestCase*)new Test22(_modem,22));
ashleymills 20:18373fb68ad7 18 _tests.push_back((VodafoneTestCase*)new Test23(_modem,23));
ashleymills 23:408199b5d2cb 19
ashleymills 23:408199b5d2cb 20 for(int i=24; i<25; i++) { _tests.push_back(NULL); }
ashleymills 23:408199b5d2cb 21
ashleymills 22:5b1feecf2aeb 22 _tests.push_back((VodafoneTestCase*)new Test25(_modem,25));
ashleymills 22:5b1feecf2aeb 23 _tests.push_back((VodafoneTestCase*)new Test26(_modem,26));
ashleymills 23:408199b5d2cb 24
ashleymills 23:408199b5d2cb 25 for(int i=27; i<50; i++) { _tests.push_back(NULL); }
ashleymills 23:408199b5d2cb 26
ashleymills 20:18373fb68ad7 27 _tests.push_back((VodafoneTestCase*)new Test50(_modem,50));
ashleymills 2:ea883307d02f 28 }
ashleymills 2:ea883307d02f 29
ashleymills 22:5b1feecf2aeb 30 int TestManager::getTestProfileLength(TestProfile profile) {
ashleymills 26:9eefab9e28df 31 if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned
ashleymills 22:5b1feecf2aeb 32 return gTestProfileLengths[profile];
ashleymills 22:5b1feecf2aeb 33 } else {
ashleymills 22:5b1feecf2aeb 34 LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1);
ashleymills 22:5b1feecf2aeb 35 return 0;
ashleymills 22:5b1feecf2aeb 36 }
ashleymills 22:5b1feecf2aeb 37 }
ashleymills 22:5b1feecf2aeb 38
ashleymills 22:5b1feecf2aeb 39 int TestManager::executeTestProfile(TestProfile profile) {
ashleymills 24:8f0f9551122a 40 int numPassed = 0;
ashleymills 26:9eefab9e28df 41 if(profile <TESTS_END) { // no test for >= 0 since TestProfile is unsigned
ashleymills 24:8f0f9551122a 42 numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]);
ashleymills 22:5b1feecf2aeb 43 } else {
ashleymills 22:5b1feecf2aeb 44 LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1);
ashleymills 22:5b1feecf2aeb 45 return 0;
ashleymills 22:5b1feecf2aeb 46 }
ashleymills 24:8f0f9551122a 47 int numTests = getTestProfileLength(profile);
ashleymills 24:8f0f9551122a 48 LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed);
ashleymills 24:8f0f9551122a 49 return numPassed;
ashleymills 22:5b1feecf2aeb 50 }
ashleymills 22:5b1feecf2aeb 51
ashleymills 19:26fbed33d4e7 52 int TestManager::executeTestList(const int *list, const int listLen) {
ashleymills 2:ea883307d02f 53 int successfullTests = 0;
ashleymills 19:26fbed33d4e7 54 LOG("Running %d tests...",listLen);
ashleymills 19:26fbed33d4e7 55 for(int i=0; i<listLen; i++) {
ashleymills 19:26fbed33d4e7 56 int testIndex = list[i];
ashleymills 19:26fbed33d4e7 57 LOG("Running test %d...",testIndex);
ashleymills 19:26fbed33d4e7 58 if(testIndex>=_tests.size()) {
ashleymills 19:26fbed33d4e7 59 LOG("Test out of bounds. Test index must be betweeen 0 and %d!",_tests.size());
ashleymills 19:26fbed33d4e7 60 continue;
ashleymills 19:26fbed33d4e7 61 }
ashleymills 19:26fbed33d4e7 62
ashleymills 19:26fbed33d4e7 63 VodafoneTestCase* test = _tests[list[i]];
ashleymills 19:26fbed33d4e7 64 if(test==NULL) {
ashleymills 19:26fbed33d4e7 65 LOG("NULL test! This will be counted as a failure.");
ashleymills 19:26fbed33d4e7 66 continue;
ashleymills 19:26fbed33d4e7 67 }
ashleymills 19:26fbed33d4e7 68
ashleymills 19:26fbed33d4e7 69 if(test->run()) {
ashleymills 2:ea883307d02f 70 LOG("...OK");
ashleymills 2:ea883307d02f 71 successfullTests++;
ashleymills 2:ea883307d02f 72 } else {
ashleymills 2:ea883307d02f 73 LOG("...FAIL");
ashleymills 2:ea883307d02f 74 }
ashleymills 2:ea883307d02f 75 }
ashleymills 2:ea883307d02f 76 return successfullTests;
ashleymills 2:ea883307d02f 77 }
ashleymills 2:ea883307d02f 78
ashleymills 4:1f8e079924ba 79 bool TestManager::runTest(int id) {
ashleymills 4:1f8e079924ba 80 if(id<0||id>=_tests.size()) {
ashleymills 4:1f8e079924ba 81 LOG("Test ID must be between 0 and %d",_tests.size());
ashleymills 19:26fbed33d4e7 82 return false;
ashleymills 4:1f8e079924ba 83 }
ashleymills 19:26fbed33d4e7 84 if(_tests[id]==NULL) {
ashleymills 19:26fbed33d4e7 85 LOG("NULL test! This will be counted as a failure.");
ashleymills 19:26fbed33d4e7 86 return false;
ashleymills 19:26fbed33d4e7 87 }
ashleymills 19:26fbed33d4e7 88
ashleymills 4:1f8e079924ba 89 return _tests[id]->run();
ashleymills 4:1f8e079924ba 90 }
ashleymills 4:1f8e079924ba 91
ashleymills 4:1f8e079924ba 92
ashleymills 4:1f8e079924ba 93 bool TestManager::runTest(int id, int numTimes) {
ashleymills 4:1f8e079924ba 94 for(int i=0; i<numTimes; i++) {
ashleymills 4:1f8e079924ba 95 if(!runTest(id))
ashleymills 4:1f8e079924ba 96 return false;
ashleymills 4:1f8e079924ba 97 }
ashleymills 4:1f8e079924ba 98 return true;
ashleymills 2:ea883307d02f 99 }