Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
TestManager.cpp
00001 #include "TestManager.h" 00002 #include "Tests.h" 00003 00004 // adds a test into the master test index 00005 void TestManager::addTest(VodafoneTestCase* testCase) { 00006 _tests.push_back(testCase); 00007 } 00008 00009 VodafoneTestCase* TestManager::constructTest(int testID) { 00010 switch(testID) { 00011 case 0: return (VodafoneTestCase*) new Test00(_modem); 00012 case 1: return (VodafoneTestCase*) new Test01(_modem); 00013 case 2: return (VodafoneTestCase*) new Test02(_modem); 00014 case 3: return (VodafoneTestCase*) new Test03(_modem); 00015 case 4: return (VodafoneTestCase*) new Test04(_modem); 00016 case 5: return (VodafoneTestCase*) new Test05(_modem); 00017 case 6: return (VodafoneTestCase*) new Test06(_modem); 00018 case 7: return (VodafoneTestCase*) new Test07(_modem); 00019 case 8: return (VodafoneTestCase*) new Test08(_modem); 00020 case 9: return (VodafoneTestCase*) new Test09(_modem); 00021 case 10: return (VodafoneTestCase*) new Test10(_modem); 00022 case 11: return (VodafoneTestCase*) new Test11(_modem); 00023 case 12: return (VodafoneTestCase*) new Test12(_modem); 00024 case 13: return (VodafoneTestCase*) new Test13(_modem); 00025 case 14: return (VodafoneTestCase*) new Test14(_modem); 00026 case 15: return (VodafoneTestCase*) new Test15(_modem); 00027 case 16: break; 00028 case 17: break; 00029 case 18: break; 00030 case 19: break; 00031 case 20: break; 00032 case 21: break; 00033 case 22: break; 00034 case 23: break; 00035 case 24: break; 00036 case 25: break; 00037 case 26: break; 00038 case 27: break; 00039 case 28: break; 00040 case 29: break; 00041 case 30: break; 00042 case 31: break; 00043 case 32: break; 00044 case 33: break; 00045 case 34: break; 00046 case 35: break; 00047 case 36: break; 00048 case 37: break; 00049 case 38: break; 00050 case 39: break; 00051 case 40: break; 00052 case 41: break; 00053 case 42: break; 00054 case 43: break; 00055 case 44: break; 00056 case 45: break; 00057 case 46: break; 00058 case 47: break; 00059 case 48: break; 00060 case 49: break; 00061 case 50: break; 00062 case 51: break; 00063 case 52: break; 00064 case 53: break; 00065 case 54: break; 00066 case 55: break; 00067 case 56: break; 00068 case 57: break; 00069 case 58: break; 00070 case 59: break; 00071 default: return NULL; 00072 }; 00073 return NULL; //< For compiler warning 00074 } 00075 00076 TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { 00077 _testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool)); 00078 resetTestOutcomes(); 00079 } 00080 00081 void TestManager::resetTestOutcomes() { 00082 for(int i=0; i<NUMBER_OF_TESTS; i++) { 00083 _testOutcomes[i] = false; 00084 } 00085 } 00086 00087 int TestManager::getTestProfileLength(TestProfile profile) { 00088 if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned 00089 return gTestProfileLengths[profile]; 00090 } else { 00091 LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); 00092 return 0; 00093 } 00094 } 00095 00096 int TestManager::runTestProfile(TestProfile profile) { 00097 resetTestOutcomes(); 00098 int numPassed = 0; 00099 if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned 00100 numPassed = runTestList(gTestProfiles[profile], gTestProfileLengths[profile]); 00101 } else { 00102 LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); 00103 return 0; 00104 } 00105 int numTests = getTestProfileLength(profile); 00106 LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); 00107 LOG("Listing failures:"); 00108 listFailures(gTestProfiles[profile], gTestProfileLengths[profile]); 00109 return numPassed; 00110 } 00111 00112 void TestManager::listFailures(const int *list, const int listLen) { 00113 for(int i=0; i<listLen; i++) { 00114 int testIndex = list[i]; 00115 00116 if(_testOutcomes[testIndex]==false) { 00117 LOG("Test %d:",testIndex); 00118 LOG(gTestDescriptions[testIndex]); 00119 } 00120 } 00121 } 00122 00123 int TestManager::runTestList(const int *list, const int listLen) { 00124 int successfullTests = 0; 00125 LOG("Running %d tests...",listLen); 00126 for(int i=0; i<listLen; i++) { 00127 int testIndex = list[i]; 00128 if(runTest(testIndex)) { 00129 successfullTests++; 00130 _testOutcomes[testIndex] = true; 00131 } 00132 } 00133 return successfullTests; 00134 } 00135 00136 bool TestManager::runTest(int testID) { 00137 VodafoneTestCase* test = constructTest(testID); 00138 if(test==NULL) { 00139 LOG("Error. Test %d is not in test list! This will be counted as a failure.",testID); 00140 return false; 00141 } 00142 00143 LOG("Running test %d...",testID); 00144 if(test->run()) { 00145 LOG("...OK"); 00146 delete test; 00147 return true; 00148 } 00149 LOG("...FAIL"); 00150 delete test; 00151 return false; 00152 } 00153 00154 bool TestManager::runTest(int id, int numTimes) { 00155 for(int i=0; i<numTimes; i++) { 00156 if(!runTest(id)) 00157 return false; 00158 } 00159 return true; 00160 }
Generated on Sun Jul 17 2022 01:04:13 by
1.7.2