Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

TestManager.cpp

Committer:
donatien
Date:
2012-09-14
Revision:
42:e423e7204e5c
Parent:
40:32b0558320ea
Child:
44:6d0ac4747f5b

File content as of revision 42:e423e7204e5c:

#include "TestManager.h"
#include "Tests.h"

// adds a test into the master test index
void TestManager::addTest(VodafoneTestCase* testCase) {
   _tests.push_back(testCase);
}

VodafoneTestCase* TestManager::constructTest(int testID) {
   switch(testID) {
      case 0: break;
      case 1: break;
      case 2: break;
      case 3: break;
      case 4: break;
      case 5: break;
      case 6: break;
      case 7: break;
      case 8: break;
      case 9: break;
      case 10: return (VodafoneTestCase*) new Test10(_modem);
      case 11: break;
      case 12: return (VodafoneTestCase*) new Test12(_modem);
      case 13: return (VodafoneTestCase*) new Test13(_modem);
      case 14: return (VodafoneTestCase*) new Test14(_modem);
      case 15: break;
      case 16: return (VodafoneTestCase*) new Test16(_modem);
      case 17: break;
      case 18: break;
      case 19: break;
      case 20: break;
      case 21: return (VodafoneTestCase*) new Test21(_modem);
      case 22: return (VodafoneTestCase*) new Test22(_modem);
      case 23: return (VodafoneTestCase*) new Test23(_modem);
      case 24: break;
      case 25: return (VodafoneTestCase*) new Test25(_modem);
      case 26: return (VodafoneTestCase*) new Test26(_modem);
      case 27: break;
      case 28: break;
      case 29: break;
      case 30: break;
      case 31: break;
      case 32: break;
      case 33: break;
      case 34: break;
      case 35: break;
      case 36: break;
      case 37: break;
      case 38: break;
      case 39: break;
      case 40: break;
      case 41: break;
      case 42: break;
      case 43: break;
      case 44: break;
      case 45: break;
      case 46: break;
      case 47: break;
      case 48: break;
      case 49: break;
      case 50: return (VodafoneTestCase*) new Test50(_modem);
      case 51: break;
      case 52: break;
      case 53: break;
      case 54: break;
      case 55: break;
      case 56: return (VodafoneTestCase*) new Test56(_modem);
      case 57: break;
      case 58: break;
      case 59: break;
      default: return NULL;
   };
   return NULL; //< For compiler warning
}

TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) {
   //_testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool));
   //resetTestOutcomes();
}

void TestManager::resetTestOutcomes() {
   for(int i=0; i<NUMBER_OF_TESTS; i++) {
      _testOutcomes[i] = false;
   }
}

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) {
   //resetTestOutcomes();
   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];
      
      if(_testOutcomes[testIndex]==false) {
         LOG("Test %d:",testIndex);
         //LOG(gTestDescriptions[testIndex]);
      }
   }
}

/*
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];
      if(executeTest(testIndex)) {
         successfullTests++;
      }
   }
   return successfullTests;
}

bool TestManager::executeTest(int testID) {
   VodafoneTestCase* test = constructTest(testID);//getTest(testID);
   if(test==NULL) {
      LOG("Error. Test %d is not in test list! This will be counted as a failure.",testID);
      //delete test;
      return false;
   }
      
   LOG("Running test %d...",testID);
   //if(test->execute()) { //FIX Donatien
   /*
     Error was there:
     If execute() is called directly, setupTest() and endTest() are NOT called!
     In Tests 21 & 22 these routines were used to allocate/deallocate the buffer where
      the USSD result was supposed to be stored
     This pointer being random, random stuff happened when the USSDInterface tried to copy the response to this address
   */
   if(test->run()) 
   {
      LOG("...OK");
      delete test;
      return true;
   }
   LOG("...FAIL");
   delete test;
   return false;
}

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