Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

TestManager.cpp

Committer:
nherriot
Date:
2012-09-12
Revision:
31:9231acdde9ff
Parent:
30:dd2beda340c6
Child:
33:16126e029d58

File content as of revision 31:9231acdde9ff:

#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));

   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));
}

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) {
   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());
         continue;
      }
      
      VodafoneTestCase* test = _tests[list[i]];
      if(test->_lastRunOutcome==false) {
         LOG("Test %d:",list[i]);
         LOG(gTestDescriptions[list[i]]);
      }
   }
}

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());
         continue;
      }
      
      VodafoneTestCase* test = _tests[list[i]];
      if(test==NULL) {
         LOG("NULL test!  This will be counted as a failure.");
         continue;
      }
      
      if(test->run()) {
         LOG("...OK");
         successfullTests++;
      } else {
         LOG("...FAIL");
      }
   }
   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.");
      return false;
   }
   
   return _tests[id]->run();
}


bool TestManager::runTest(int id, int numTimes) {
   for(int i=0; i<numTimes; i++) {
      if(!runTest(id))
         return false;
   }
   return true;
}