Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

TestCaseManoeuvreManager_2.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseManoeuvreManager_2.cpp 00005 // 00006 // Version 1.0 00007 // Date 08.05.03 00008 // Author R. Totaro 00009 00010 #include "TestCaseManoeuvreManager_2.h" 00011 #include "../GeneralInclude/ClassId.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../GeneralInclude/CompilerSwitches.h" 00014 #include "../Manoeuvre/DC_DummyConfigurableManoeuvre.h" 00015 #include "../Manoeuvre/CC_ManoeuvreManager.h" 00016 00017 static const int nMan=5; 00018 static const int maxActivations=100; 00019 static const struct { 00020 unsigned int continueToFalse; 00021 unsigned int finishedToTrue; 00022 } manoeuvreStateChange[nMan]={ 00023 { 5,4}, // Manouvre finishes after 4 calls to doContinue() 00024 { 4,3}, // Manouvre finishes after 3 calls to doContinue() 00025 { 6,7}, // Continuation flag set to false after 6 calls to doContinue() 00026 {10,9}, // Manouvre finishes after 9 calls to doContinue() 00027 { 8,9} // Continuation flag set to false after 6 calls to doContinue() 00028 }; 00029 static const struct { 00030 int activation; 00031 TD_EventType eventType; 00032 unsigned int offset; 00033 } expectedEvent[nMan]={ 00034 { 4,EVT_MAN_TERMINATED,2*nMan+1}, 00035 { 5,EVT_MAN_TERMINATED,2*nMan+3}, 00036 { 7,EVT_MAN_ABORTED, 2*nMan+5}, 00037 { 9,EVT_MAN_ABORTED, 2*nMan+7}, 00038 {10,EVT_MAN_TERMINATED,2*nMan+9} 00039 }; 00040 00041 TestCaseManoeuvreManager_2::TestCaseManoeuvreManager_2(void) : 00042 TestCaseWithEvtCheck(ID_MANOEUVREMANAGER*10+2,"TestCaseManoeuvreManager_2") { 00043 return; 00044 } 00045 00046 void TestCaseManoeuvreManager_2::runTestCase(void) { 00047 CC_ManoeuvreManager *pMM =new CC_ManoeuvreManager(); 00048 const unsigned int nEvt=this->getNumberOfEvents(); 00049 DC_DummyConfigurableManoeuvre *pDCM[nMan]; 00050 00051 // Initialize the manoeuvre manager 00052 pMM->setPendingManoeuvreListSize(nMan); 00053 00054 // Allocate, load and set the start and continuation flag of the nMan manoeuvres 00055 for (int i=0;i<nMan;i++) { 00056 pDCM[i]=new DC_DummyConfigurableManoeuvre(); 00057 pDCM[i]->setInUse(true); 00058 pMM->load(pDCM[i]); 00059 pDCM[i]->setStartCheckStatus(MAN_CAN_START); 00060 pDCM[i]->setContinuationCheckStatus(MAN_CAN_CONTINUE); 00061 pDCM[i]->setTerminationCheckStatus(MAN_HAS_NOT_TERMINATED); 00062 } 00063 00064 // Invoke once the activate method and verify that the manoeuvres 00065 // have been initialized and that doContinue() has been called. 00066 pMM->activate(); 00067 for (int i=0;i<nMan;i++) { 00068 if (pDCM[i]->getInitializationActionCounter()!=1) { 00069 setTestResult(TEST_FAILURE,"Failed to initialize the manoeuvres"); 00070 return; 00071 } 00072 00073 if (pDCM[i]->getContinuationActionCounter()!=1) { 00074 setTestResult(TEST_FAILURE,"Failed to call doContinue()"); 00075 return; 00076 } 00077 } 00078 00079 // Now let's loop until all the manoeuvres have finished or the 00080 // maximum number of activations has been reached. 00081 // The initial value is 1: pMM->activate() has already been called once. 00082 int activationCalls=1; 00083 00084 do { 00085 // Update the manoeuvres' status 00086 for (int i=0;i<nMan;i++) { 00087 if (pDCM[i]->isInUse()) { 00088 unsigned int n=pDCM[i]->getContinuationActionCounter(); 00089 00090 pDCM[i]->setStartCheckStatus(MAN_CAN_START); 00091 pDCM[i]->setContinuationCheckStatus((n<manoeuvreStateChange[i].continueToFalse)); 00092 pDCM[i]->setTerminationCheckStatus((n>=manoeuvreStateChange[i].finishedToTrue)); 00093 } 00094 } 00095 00096 pMM->activate(); 00097 activationCalls++; 00098 00099 for (int i=0;i<nMan;i++) { 00100 // Verify that all the manoeuvres in use have been scheduled 00101 if (pDCM[i]->isInUse()) { 00102 if (pDCM[i]->getContinuationActionCounter()!=activationCalls) { 00103 setTestResult(TEST_FAILURE,"Failed to call doContinue()"); 00104 return; 00105 } 00106 } 00107 00108 // Now we verify that the manoeuvre has been terminated/aborted 00109 // (depending on its status) and unloaded from the manoeuvre manager. 00110 // The easiest way to do this is to look in the event repository for 00111 // the corresponding events. 00112 if (expectedEvent[i].activation==activationCalls && 00113 (!verifySpecificEvent(nEvt+expectedEvent[i].offset, 00114 expectedEvent[i].eventType) || 00115 !verifyLatestEvent(nEvt+expectedEvent[i].offset+1, 00116 EVT_MAN_UNLOADED))) { 00117 return; 00118 } 00119 } 00120 } while (pMM->getPendingManoeuvres()>0 && activationCalls<maxActivations); 00121 00122 if (activationCalls==maxActivations) { 00123 setTestResult(TEST_FAILURE,"Maximum number of activations reached"); 00124 return; 00125 } 00126 00127 setTestResult(TEST_SUCCESS,"Test Successful"); 00128 return; 00129 }
Copyright 2003 P&P Software GmbH - All Rights Reserved