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

TestCaseFSM_3.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseFSM_3.cpp 00005 // 00006 // Version 1.0 00007 // Date 14.10.02 00008 // Author A. Pasetti (P&P Software) 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/ClassId.h" 00012 #include "../GeneralInclude/BasicTypes.h" 00013 #include "../GeneralInclude/Constants.h" 00014 #include "../FSM/CC_FSM.h" 00015 #include "../FSM/DC_DummyConfigurableFsmState.h" 00016 #include "../FSM/DC_FsmEvent.h" 00017 #include "../FSM/FsmState.h" 00018 #include "../Base/CC_RootObject.h" 00019 #include "../Event/DC_EventRepository.h" 00020 #include "TestCaseFSM_3.h" 00021 00022 TestCaseFSM_3::TestCaseFSM_3(void) : 00023 TestCaseGenericSetUp(ID_FSM*10+3,"TestCaseFSM_3") { 00024 return; 00025 } 00026 00027 void TestCaseFSM_3::runTestCase(void) { 00028 00029 CC_FSM* pFsm = new CC_FSM(); 00030 00031 // Configure the FSM 00032 pFsm->setNumberOfStates(4); 00033 00034 DC_DummyConfigurableFsmState* pState[4]; 00035 for (TD_FsmStateIndex i=0; i<pFsm->getNumberOfStates(); i++) 00036 pState[i] = new DC_DummyConfigurableFsmState(); 00037 00038 pState[0]->setNextState(pState[1]); 00039 pState[1]->setNextState(pState[2]); 00040 pState[2]->setNextState(pState[3]); 00041 pState[3]->setNextState(pState[0]); 00042 00043 for (TD_FsmStateIndex i=0; i<pFsm->getNumberOfStates(); i++) 00044 pFsm->setState(i,pState[i]); 00045 00046 pFsm->reset(); 00047 00048 // FSM object should now be configured 00049 if ( (pFsm->isObjectConfigured() == NOT_CONFIGURED) ) 00050 { setTestResult(TEST_FAILURE, 00051 "Wrong FSM configuration status after configuration was completed"); 00052 return; 00053 } 00054 00055 // Check the correctness of the class identifier 00056 if ( (pState[0]->getClassId() != ID_DUMMYCONFIGURABLEFSMSTATE) ) 00057 { setTestResult(TEST_FAILURE, 00058 "Wrong class identifier for the dummy configurable FsmState class"); 00059 return; 00060 } 00061 00062 // Activate FSM twice and check that state 0 is executed 00063 pFsm->activate(); 00064 pFsm->activate(); 00065 if ( pState[0]->getActivationCounter() != 2 ) 00066 { setTestResult(TEST_FAILURE, 00067 "Wrong value of activation counter for state 0"); 00068 return; 00069 } 00070 00071 // Verify value of initialization counter 00072 if ( pState[0]->getInitializationCounter() != 1 ) 00073 { setTestResult(TEST_FAILURE, 00074 "Wrong value of initialization counter for state 0"); 00075 return; 00076 } 00077 00078 // Force and check state transition to state 1 00079 pState[0]->setTerminationCheckValue(true); 00080 pFsm->activate(); 00081 if ( pFsm->getCurrentState() != 1) 00082 { setTestResult(TEST_FAILURE, 00083 "State transition to state 1 failed to take place"); 00084 return; 00085 } 00086 00087 // Check that the correct event was created 00088 DC_EventRepository* pRep = CC_RootObject::getEventRepository(); 00089 pRep->latest(); 00090 if ( pRep->getEventType() != EVT_FSM_TRANSITION ) 00091 { setTestResult(TEST_FAILURE, 00092 "Wrong event after state transition"); 00093 return; 00094 } 00095 00096 // Check exit, initialization and activation counters 00097 if ( pState[0]->getExitCounter() != 1 ) 00098 { setTestResult(TEST_FAILURE, 00099 "Wrong value of exit counter for state 0"); 00100 return; 00101 } 00102 if ( pState[1]->getInitializationCounter() != 1 ) 00103 { setTestResult(TEST_FAILURE, 00104 "Wrong value of initialization counter for state 1"); 00105 return; 00106 } 00107 if ( pState[1]->getActivationCounter() != 1 ) 00108 { setTestResult(TEST_FAILURE, 00109 "Wrong value of activation counter for state 1"); 00110 return; 00111 } 00112 00113 // Disable autonomous transition by disabling exit check and verify that 00114 // no transition takes place 00115 pState[1]->setExitCheckValue(false); 00116 pState[1]->setTerminationCheckValue(true); 00117 pFsm->activate(); 00118 if ( pFsm->getCurrentState() != 1) 00119 { setTestResult(TEST_FAILURE, 00120 "Illegal state transition out of state 1 took place"); 00121 return; 00122 } 00123 00124 // Check that the correct event was created 00125 pRep = CC_RootObject::getEventRepository(); 00126 pRep->latest(); 00127 if ( pRep->getEventType() != EVT_FSM_EXIT_FAILED ) 00128 { setTestResult(TEST_FAILURE, 00129 "Wrong event after failure of exit check"); 00130 return; 00131 } 00132 00133 // Check that the last FSM activation caused the execution of state 1 00134 if ( pState[1]->getActivationCounter() != 2 ) 00135 { setTestResult(TEST_FAILURE, 00136 "Wrong value of activation counter for state 1"); 00137 return; 00138 } 00139 00140 // Disable autonomous transition by disabling entry check and verify that 00141 // no transition takes place 00142 pState[1]->setExitCheckValue(true); 00143 pState[2]->setInitializationCheckValue(false); 00144 pFsm->activate(); 00145 if ( pFsm->getCurrentState() != 1) 00146 { setTestResult(TEST_FAILURE, 00147 "Illegal state transition out of state 1 took place"); 00148 return; 00149 } 00150 00151 // Check that the correct event was created 00152 pRep = CC_RootObject::getEventRepository(); 00153 pRep->latest(); 00154 if ( pRep->getEventType() != EVT_FSM_ENTRY_FAILED ) 00155 { setTestResult(TEST_FAILURE, 00156 "Wrong event after failure of exit check"); 00157 return; 00158 } 00159 00160 // Disable autonomous transitions by disabling FSM transitions into state 2 00161 // and verify that no transition takes place 00162 pState[2]->setInitializationCheckValue(true); 00163 pFsm->setTransitionEnableStatus(2, DISABLED); 00164 pFsm->activate(); 00165 if ( pFsm->getCurrentState() != 1) 00166 { setTestResult(TEST_FAILURE, 00167 "Illegal state transition out of state 1 took place"); 00168 return; 00169 } 00170 00171 // Check that the correct event was created 00172 pRep = CC_RootObject::getEventRepository(); 00173 pRep->latest(); 00174 if ( pRep->getEventType() != EVT_FSM_TRANSITION_DISABLED ) 00175 { setTestResult(TEST_FAILURE, 00176 "Wrong event after failure of exit check"); 00177 return; 00178 } 00179 00180 // Disable autonomous transitions by disabling all FSM transitions 00181 // and verify that no transition takes place 00182 pFsm->setTransitionEnableStatus(2, ENABLED); 00183 pFsm->setTransitionEnableStatus(DISABLED); 00184 pFsm->activate(); 00185 if ( pFsm->getCurrentState() != 1) 00186 { setTestResult(TEST_FAILURE, 00187 "Illegal state transition out of state 1 took place"); 00188 return; 00189 } 00190 00191 // Check that the correct event was created 00192 pRep = CC_RootObject::getEventRepository(); 00193 pRep->latest(); 00194 if ( pRep->getEventType() != EVT_FSM_ALL_TRANSITION_DISABLED ) 00195 { setTestResult(TEST_FAILURE, 00196 "Wrong event after failure of exit check"); 00197 return; 00198 } 00199 00200 // Enable autonomous transitions and verify that transition takes place 00201 pFsm->setTransitionEnableStatus(ENABLED); 00202 pFsm->activate(); 00203 if ( pFsm->getCurrentState() != 2) 00204 { setTestResult(TEST_FAILURE, 00205 "State transition to state 2 failed to take place"); 00206 return; 00207 } 00208 00209 // Check exit, initialization and activation counters 00210 if ( pState[1]->getExitCounter() != 1 ) 00211 { setTestResult(TEST_FAILURE, 00212 "Wrong value of exit counter for state 1"); 00213 return; 00214 } 00215 if ( pState[2]->getInitializationCounter() != 1 ) 00216 { setTestResult(TEST_FAILURE, 00217 "Wrong value of initialization counter for state 2"); 00218 return; 00219 } 00220 if ( pState[2]->getActivationCounter() != 1 ) 00221 { setTestResult(TEST_FAILURE, 00222 "Wrong value of activation counter for state 2"); 00223 return; 00224 } 00225 00226 // Attempt to commands transition into non-existent state 00227 if (isNonNominalCheckAllowed()) { 00228 pFsm->makeTransitionRequest(4); 00229 pRep->latest(); 00230 if ( pRep->getEventType() != EVT_ILLEGAL_FS ) 00231 { setTestResult(TEST_FAILURE, 00232 "Failure of non-nominal behaviour check"); 00233 return; 00234 } 00235 } 00236 00237 setTestResult(TEST_SUCCESS,"Test Successful"); 00238 return; 00239 }
Copyright 2003 P&P Software GmbH - All Rights Reserved