Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
TestManager.cpp
- Committer:
- donatien
- Date:
- 2012-09-13
- Revision:
- 36:dd730ff4962e
- Parent:
- 35:6867af70c51c
- Child:
- 38:83085bfd1018
File content as of revision 36:dd730ff4962e:
#include "TestManager.h" #include "Tests.h" // adds a test into the master test index void TestManager::addTest(VodafoneTestCase* testCase) { _tests.push_back(testCase); } TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { // using direct array indexing instead of searching each time // dummy tests are inserted by the addTest function addTest((VodafoneTestCase*)new Test10(m)); addTest((VodafoneTestCase*)new Test12(m)); addTest((VodafoneTestCase*)new Test13(m)); addTest((VodafoneTestCase*)new Test16(m)); addTest((VodafoneTestCase*)new Test21(m)); addTest((VodafoneTestCase*)new Test22(m)); addTest((VodafoneTestCase*)new Test23(m)); addTest((VodafoneTestCase*)new Test25(m)); addTest((VodafoneTestCase*)new Test26(m)); addTest((VodafoneTestCase*)new Test50(m)); addTest((VodafoneTestCase*)new Test56(m)); } int TestManager::getTestProfileLength(TestProfile profile) { if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned return gTestProfileLengths[profile]; } else { LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); return 0; } } int TestManager::executeTestProfile(TestProfile profile) { int numPassed = 0; if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); } else { LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); return 0; } int numTests = getTestProfileLength(profile); LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); LOG("Listing failures:"); listFailures(gTestProfiles[profile], gTestProfileLengths[profile]); return numPassed; } void TestManager::listFailures(const int *list, const int listLen) { for(int i=0; i<listLen; i++) { int testIndex = list[i]; VodafoneTestCase* test = getTest(testIndex); if(test==NULL) { LOG("ERROR: Test %d is not in test list!.",testIndex); continue; } if(test->_lastRunOutcome==false) { LOG("Test %d:",test->_testCaseNumber); LOG(test->_description); } } } VodafoneTestCase* TestManager::getTest(int index) { for(int i=0; i<_tests.size(); i++) { if(index==_tests[i]->_testCaseNumber) return _tests[i]; } return NULL; } int TestManager::executeTestList(const int *list, const int listLen) { int successfullTests = 0; LOG("Running %d tests...",listLen); for(int i=0; i<listLen; i++) { int testIndex = list[i]; VodafoneTestCase* test = getTest(testIndex); if(test==NULL) { LOG("Error. Test %d is not in test list! This will be counted as a failure.",testIndex); continue; } LOG("Running test %d...",testIndex); if(test->execute()) { LOG("...OK"); successfullTests++; } else { LOG("...FAIL"); } } return successfullTests; } bool TestManager::executeTest(int id) { VodafoneTestCase* test = getTest(id); if(test==NULL) { LOG("Error. Test %d is not in test list! This will be counted as a failure.",id); return false; } return _tests[id]->execute(); } bool TestManager::executeTest(int id, int numTimes) { for(int i=0; i<numTimes; i++) { if(!executeTest(id)) return false; } return true; }