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

TestCaseNestedFsmActivatorWithExitCheck_1.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseNestedFsmActivatorWithExitCheck_1.cpp 00005 // 00006 // Version 1.0 00007 // Date 08.07.03 00008 // Author R. Totaro 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/ClassId.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../GeneralInclude/TestConstants.h" 00014 #include "../FSM/DC_FsmEvent.h" 00015 #include "../FSM/DC_DummyFsmState.h" 00016 #include "../FSM/DC_NestedFsmActivatorWithExitCheck.h" 00017 #include "TestCaseNestedFsmActivatorWithExitCheck_1.h" 00018 00019 TestCaseNestedFsmActivatorWithExitCheck_1::TestCaseNestedFsmActivatorWithExitCheck_1(void) : 00020 TestCaseGenericSetUp(ID_NESTEDFSMACTIVATORWITHEXITCHECK*10+1, 00021 "TestCaseNestedFsmActivatorWithExitCheck_1") { 00022 return; 00023 } 00024 00025 void TestCaseNestedFsmActivatorWithExitCheck_1::runTestCase(void) { 00026 const TD_FsmStateIndex numStates =8; 00027 const TD_FsmStateIndex targetState=5; 00028 CC_FSM *pFSM =new CC_FSM; 00029 DC_NestedFsmActivatorWithExitCheck *pNFA =new DC_NestedFsmActivatorWithExitCheck; 00030 DC_DummyFsmState *pFS[numStates]; 00031 DC_FsmEvent *pFE[numStates]; 00032 00033 // Initialize the FSM 00034 pFSM->setNumberOfStates(numStates); 00035 00036 for (TD_FsmStateIndex i=0;i<numStates;i++) { 00037 // Create and load FSM states 00038 pFS[i]=new DC_DummyFsmState; 00039 pFSM->setState(i,pFS[i]); 00040 00041 // Create and configure FSM events 00042 pFE[i]=new DC_FsmEvent; 00043 pFE[i]->setTargetFsm(pFSM); 00044 pFE[i]->setTargetState((i+1)%numStates); 00045 } 00046 00047 pFSM->reset(); 00048 00049 // Verify the correctness of the class id 00050 if (pNFA->getClassId()!=ID_NESTEDFSMACTIVATORWITHEXITCHECK) { 00051 setTestResult(TEST_FAILURE,"Wrong class id"); 00052 return; 00053 } 00054 00055 // The object shall not be configured yet 00056 if (pNFA->isObjectConfigured()) { 00057 setTestResult(TEST_FAILURE,"Newly created object is configured"); 00058 return; 00059 } 00060 00061 // Let's attach the nested FSM to the state and verify that 00062 // object is not yet configured 00063 pNFA->setTargetFsm(pFSM); 00064 00065 if (pNFA->isObjectConfigured()) { 00066 setTestResult(TEST_FAILURE,"Object is wrongly configured"); 00067 return; 00068 } 00069 00070 // After setting the target state the object should be configured 00071 pNFA->setTargetState(targetState); 00072 00073 if (pNFA->getTargetState()!=targetState) { 00074 setTestResult(TEST_FAILURE,"setTargetState() failed"); 00075 return; 00076 } 00077 00078 if (!pNFA->isObjectConfigured()) { 00079 setTestResult(TEST_FAILURE,"Object is not configured"); 00080 return; 00081 } 00082 00083 // Verify that canExit() returns true only when tha machine is 00084 // in the right state 00085 for (TD_FsmStateIndex i=0;i<numStates;i++) { 00086 pFE[i]->execute(); 00087 pNFA->doContinue(); 00088 00089 if ((pNFA->canExit() && pFSM->getCurrentState()!=targetState) || 00090 (!pNFA->canExit() && pFSM->getCurrentState()==targetState)) { 00091 setTestResult(TEST_FAILURE,"canExit() failed"); 00092 return; 00093 } 00094 } 00095 00096 setTestResult(TEST_SUCCESS,"Test Successful"); 00097 return; 00098 }
Copyright 2003 P&P Software GmbH - All Rights Reserved