Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Revision 33:16126e029d58, committed 2012-09-13
- Comitter:
- ashleymills
- Date:
- Thu Sep 13 10:05:31 2012 +0000
- Parent:
- 31:9231acdde9ff
- Parent:
- 32:8ff0b67bb58c
- Child:
- 34:d9e45aad85f2
- Commit message:
- Changed test framework.
Changed in this revision
--- a/TestManager.cpp Wed Sep 12 16:55:00 2012 +0000 +++ b/TestManager.cpp Thu Sep 13 10:05:31 2012 +0000 @@ -1,36 +1,25 @@ #include "TestManager.h" #include "Tests.h" -TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { - // using direct array indexing instead of searching each time, so need to put in dummy tests - for(int i=0; i<10; i++) { _tests.push_back(NULL); } - - _tests.push_back((VodafoneTestCase*)new Test10(_modem,10)); - - for(int i=11; i<12; i++) { _tests.push_back(NULL); } - _tests.push_back((VodafoneTestCase*)new Test12(_modem,12)); - _tests.push_back((VodafoneTestCase*)new Test13(_modem,13)); - - for(int i=14; i<16; i++) { _tests.push_back(NULL); } - _tests.push_back((VodafoneTestCase*)new Test16(_modem,16)); + +// adds a test into the master test index +void TestManager::addTest(VodafoneTestCase* testCase) { + _tests.push_back(testCase); +} - for(int i=17; i<21; i++) { _tests.push_back(NULL); } - - _tests.push_back((VodafoneTestCase*)new Test21(_modem,21)); - _tests.push_back((VodafoneTestCase*)new Test22(_modem,22)); - _tests.push_back((VodafoneTestCase*)new Test23(_modem,23)); - - for(int i=24; i<25; i++) { _tests.push_back(NULL); } - - _tests.push_back((VodafoneTestCase*)new Test25(_modem,25)); - _tests.push_back((VodafoneTestCase*)new Test26(_modem,26)); - - for(int i=27; i<50; i++) { _tests.push_back(NULL); } - - _tests.push_back((VodafoneTestCase*)new Test50(_modem,50)); - - for(int i=51; i<56; i++) { _tests.push_back(NULL); } - - _tests.push_back((VodafoneTestCase*)new Test56(_modem,56)); +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(_modem)); + addTest((VodafoneTestCase*)new Test12(_modem)); + addTest((VodafoneTestCase*)new Test13(_modem)); + addTest((VodafoneTestCase*)new Test16(_modem)); + addTest((VodafoneTestCase*)new Test21(_modem)); + addTest((VodafoneTestCase*)new Test22(_modem)); + addTest((VodafoneTestCase*)new Test23(_modem)); + addTest((VodafoneTestCase*)new Test25(_modem)); + addTest((VodafoneTestCase*)new Test26(_modem)); + addTest((VodafoneTestCase*)new Test50(_modem)); + addTest((VodafoneTestCase*)new Test56(_modem)); } int TestManager::getTestProfileLength(TestProfile profile) { @@ -43,11 +32,9 @@ } int TestManager::executeTestProfile(TestProfile profile) { - int numPassed = 0; - if(profile <TESTS_END) { // no test for >= 0 since TestProfile is unsigned + 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; @@ -63,39 +50,40 @@ int successfullTests = 0; for(int i=0; i<listLen; i++) { int testIndex = list[i]; - if(testIndex>=_tests.size()) { - LOG("Test out of bounds... Test index must be betweeen 0 and %d!",_tests.size()); + VodafoneTestCase* test = getTest(testIndex); + if(test==NULL) { + LOG("ERROR: Test %d is not in test list!.",testIndex); continue; } - VodafoneTestCase* test = _tests[list[i]]; if(test->_lastRunOutcome==false) { - LOG("Test %d:",list[i]); - LOG(gTestDescriptions[list[i]]); + 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) { - LOG("The executeTestList is: %d", list); - LOG("The executeTestListLength is: %d", listLen); int successfullTests = 0; LOG("Running %d tests...",listLen); for(int i=0; i<listLen; i++) { int testIndex = list[i]; - LOG("Running test %d...",testIndex); - if(testIndex>=_tests.size()) { - LOG("Test out of bounds. Test index must be betweeen 0 and %d!",_tests.size()); + 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; } - VodafoneTestCase* test = _tests[list[i]]; - if(test==NULL) { - LOG("NULL test! This will be counted as a failure."); - continue; - } - - if(test->run()) { + LOG("Running test %d...",testIndex); + if(test->execute()) { LOG("...OK"); successfullTests++; } else { @@ -105,23 +93,20 @@ return successfullTests; } -bool TestManager::runTest(int id) { - if(id<0||id>=_tests.size()) { - LOG("Test ID must be between 0 and %d",_tests.size()); - return false; - } - if(_tests[id]==NULL) { - LOG("NULL test! This will be counted as a failure."); +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]->run(); + return _tests[id]->execute(); } -bool TestManager::runTest(int id, int numTimes) { +bool TestManager::executeTest(int id, int numTimes) { for(int i=0; i<numTimes; i++) { - if(!runTest(id)) + if(!executeTest(id)) return false; } return true;
--- a/TestManager.h Wed Sep 12 16:55:00 2012 +0000 +++ b/TestManager.h Thu Sep 13 10:05:31 2012 +0000 @@ -14,14 +14,19 @@ public: TestManager(VodafoneUSBModem *m); void addTest(VodafoneTestCase *tc); - int executeTestList(const int *list, const int listLen); + void listFailures(const int *list, const int listLen); - int executeTestProfile(TestProfile profile); + + bool executeTest(int id); + bool executeTest(int id, int numTimes); + int executeTestProfile(TestProfile profile); + int executeTestList(const int *list, const int listLen); + + VodafoneTestCase* getTest(int index); int getTestProfileLength(TestProfile profile); - bool runTest(int id); - bool runTest(int id, int numTimes); private: VodafoneUSBModem *_modem; vector<VodafoneTestCase*> _tests; + }; \ No newline at end of file
--- a/Tests/Test10.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test10.h Thu Sep 13 10:05:31 2012 +0000 @@ -7,7 +7,9 @@ class Test10 : public VodafoneTestCase { public: - Test10(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test10(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest10Description; + _testCaseNumber = 10; } virtual void setupTest() {
--- a/Tests/Test12.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test12.h Thu Sep 13 10:05:31 2012 +0000 @@ -20,7 +20,9 @@ char msg[160]; size_t count; - Test12(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test12(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest12Description; + _testCaseNumber = 12; } virtual bool runTest() {
--- a/Tests/Test13.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test13.h Thu Sep 13 10:05:31 2012 +0000 @@ -12,7 +12,6 @@ static const char *gTest13Description = "Waiting for an SMS message with irregular characters and numbers"; - class Test13 : public VodafoneTestCase { public: @@ -21,7 +20,9 @@ size_t count; - Test13(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test13(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest13Description; + _testCaseNumber = 13; } virtual bool runTest() {
--- a/Tests/Test14.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test14.h Thu Sep 13 10:05:31 2012 +0000 @@ -15,7 +15,9 @@ public: - Test14(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test14(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest14Description; + _testCaseNumber = 14; }
--- a/Tests/Test16.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test16.h Thu Sep 13 10:05:31 2012 +0000 @@ -15,7 +15,9 @@ public: - Test16(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test16(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest16Description; + _testCaseNumber = 16; }
--- a/Tests/Test21.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test21.h Thu Sep 13 10:05:31 2012 +0000 @@ -6,7 +6,9 @@ class Test21 : public VodafoneTestCase { public: - Test21(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test21(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest21Description; + _testCaseNumber = 21; } virtual void setupTest() {
--- a/Tests/Test22.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test22.h Thu Sep 13 10:05:31 2012 +0000 @@ -5,7 +5,9 @@ class Test22 : public VodafoneTestCase { public: - Test22(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test22(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest22Description; + _testCaseNumber = 22; } virtual void setupTest() {
--- a/Tests/Test23.cpp Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test23.cpp Thu Sep 13 10:05:31 2012 +0000 @@ -2,7 +2,10 @@ #include "Test23.h" const char gTest23USSDMessage[161] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; -Test23::Test23(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { } +Test23::Test23(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest23Description; + _testCaseNumber = 23; +} // virtual void Test23::setupTest() {
--- a/Tests/Test23.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test23.h Thu Sep 13 10:05:31 2012 +0000 @@ -6,7 +6,7 @@ class Test23 : public VodafoneTestCase { public: - Test23(VodafoneUSBModem *m, int tcNumber); + Test23(VodafoneUSBModem *m); virtual void setupTest(); virtual bool runTest(); virtual void endTest();
--- a/Tests/Test25.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test25.h Thu Sep 13 10:05:31 2012 +0000 @@ -5,7 +5,9 @@ class Test25 : public VodafoneTestCase { public: - Test25(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test25(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest25Description; + _testCaseNumber = 25; } virtual void setupTest() {
--- a/Tests/Test26.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test26.h Thu Sep 13 10:05:31 2012 +0000 @@ -6,7 +6,9 @@ class Test26 : public VodafoneTestCase { public: - Test26(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test26(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest26Description; + _testCaseNumber = 26; } virtual void setupTest() {
--- a/Tests/Test50.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test50.h Thu Sep 13 10:05:31 2012 +0000 @@ -6,9 +6,11 @@ class Test50 : public VodafoneTestCase { public: - Test50(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) { _smsLen = 32; _numberLen = 16; + _description = gTest50Description; + _testCaseNumber = 50; } virtual void setupTest() {
--- a/Tests/Test56.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Test56.h Thu Sep 13 10:05:31 2012 +0000 @@ -6,13 +6,14 @@ // if the method that sends a message returns an error it will fail. // it will report the test as failed if any of the above happens. // it does not wait after it has succesfully sent an SMS. - +static const char* gTest56Description = "Wait for SMS. Send a response."; class Test56 : public VodafoneTestCase { public: - - Test56(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + Test56(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _description = gTest56Description; + _testCaseNumber = 56; }
--- a/Tests/Tests.h Wed Sep 12 16:55:00 2012 +0000 +++ b/Tests/Tests.h Thu Sep 13 10:05:31 2012 +0000 @@ -43,29 +43,6 @@ gNumSoakTests }; - -static const char* gTestDescriptions[] = { - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - gTest10Description, - NULL, - gTest12Description, - gTest13Description, - gTest14Description, - NULL, - gTest16Description, - NULL,NULL,NULL,NULL, - gTest21Description, - gTest22Description, - gTest23Description, - NULL, - gTest25Description, - gTest26Description, - NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - gTest50Description, -}; - /* static const int* gTestDependencies[] = { gTest10Depends,
--- a/VodafoneTestCase.h Wed Sep 12 16:55:00 2012 +0000 +++ b/VodafoneTestCase.h Thu Sep 13 10:05:31 2012 +0000 @@ -13,7 +13,7 @@ class VodafoneTestCase { public: - VodafoneTestCase(VodafoneUSBModem *m, int tcNumber) : _modem(m), _testCaseNumber(tcNumber) , _lastRunTime(0), _lastRunOutcome(false){ + VodafoneTestCase(VodafoneUSBModem *m) : _modem(m) , _lastRunTime(0), _lastRunOutcome(false) { } bool run() { @@ -38,9 +38,10 @@ protected: VodafoneUSBModem *_modem; - const int _testCaseNumber; + public: time_t _lastRunTime; bool _lastRunOutcome; - + int _testCaseNumber; + const char* _description; }; \ No newline at end of file
--- a/main.cpp Wed Sep 12 16:55:00 2012 +0000 +++ b/main.cpp Thu Sep 13 10:05:31 2012 +0000 @@ -38,7 +38,7 @@ LOG("Running tests."); - int numPassed = m->executeTestProfile(TESTS_MANUAL); + int numPassed = m->executeTestProfile(TESTS_AUTOMATED); loopForever(); }