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

TestCaseDummyPointerControlBlock_1.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseDummyPointerControlBlock_1.cpp 00005 // 00006 // Version 1.0 00007 // Date 16.10.03 (Version 1.0) 00008 // Author R. Totaro 00009 // 00010 // Change Record: 00011 00012 #include <math.h> 00013 #include <float.h> 00014 00015 #include "../GeneralInclude/CompilerSwitches.h" 00016 #include "../GeneralInclude/Constants.h" 00017 #include "../GeneralInclude/ClassId.h" 00018 #include "../Data/ControlBlock.h" 00019 #include "../Data/DC_DummyPointerControlBlock.h" 00020 #include "TestCaseDummyPointerControlBlock_1.h" 00021 00022 TestCaseDummyPointerControlBlock_1::TestCaseDummyPointerControlBlock_1(void) : 00023 TestCaseWithEvtCheck(ID_DUMMYPOINTERCONTROLBLOCK*10+1, 00024 "TestCaseDummyPointerControlBlock_1") { 00025 return; 00026 } 00027 00028 void TestCaseDummyPointerControlBlock_1::runTestCase(void) { 00029 const unsigned int nEvt =getNumberOfEvents(); 00030 const unsigned int numStates =1; 00031 const unsigned int numInputs =3; 00032 const unsigned int numOutputs =2; 00033 const unsigned int numParameters=2; 00034 const TD_Float testInputs[] ={(TD_Float)0.3,(TD_Float)0.04,(TD_Float)0.005}; 00035 DC_DummyPointerControlBlock *pDCB =new DC_DummyPointerControlBlock; 00036 TD_Float inputs[numInputs]; 00037 TD_Float outputs[numOutputs]; 00038 00039 // Verify the correctness of the class identifier 00040 if (pDCB->getClassId()!=ID_DUMMYPOINTERCONTROLBLOCK) { 00041 setTestResult(TEST_FAILURE,"Wrong class identifier"); 00042 return; 00043 } 00044 00045 // Verify that the numbers of inputs, outputs, states and parameters are correct 00046 if (pDCB->getNumberOfInputs()!=numInputs) { 00047 setTestResult(TEST_FAILURE,"Wrong number of inputs"); 00048 return; 00049 } 00050 00051 if (pDCB->getNumberOfOutputs()!=numOutputs) { 00052 setTestResult(TEST_FAILURE,"Wrong number of outputs"); 00053 return; 00054 } 00055 00056 if (pDCB->getNumberOfStates()!=numStates) { 00057 setTestResult(TEST_FAILURE,"Wrong number of states"); 00058 return; 00059 } 00060 00061 if (pDCB->getNumberOfParameters()!=numParameters) { 00062 setTestResult(TEST_FAILURE,"Wrong number of parameters"); 00063 return; 00064 } 00065 00066 // Link inputs and outputs and verify its configuration status 00067 for (unsigned int i=0;i<numInputs;i++) { 00068 if (pDCB->isObjectConfigured()) { 00069 setTestResult(TEST_FAILURE,"Wrong configuration status"); 00070 return; 00071 } 00072 00073 pDCB->setInputLink(i,&inputs[i]); 00074 } 00075 00076 for (unsigned int i=0;i<numOutputs;i++) { 00077 if (pDCB->isObjectConfigured()) { 00078 setTestResult(TEST_FAILURE,"Wrong configuration status"); 00079 return; 00080 } 00081 00082 pDCB->setOutputLink(i,&outputs[i]); 00083 } 00084 00085 if (!pDCB->isObjectConfigured()) { 00086 setTestResult(TEST_FAILURE,"Wrong configuration status"); 00087 return; 00088 } 00089 00090 // Reset the control block 00091 pDCB->reset(); 00092 00093 // Verify that the default state was correctly set 00094 // Don't forget to take into account rounding errors: 00095 // this is not a problem on a Windows PC, but it might 00096 // be on other platforms. 00097 if (fabsf((float(pDCB->getState(0)-(TD_Float)1.0)))>=FLT_EPSILON) { 00098 setTestResult(TEST_FAILURE,"Wrong initial state"); 00099 return; 00100 } 00101 00102 // Set the parameters and verify their values 00103 for (int i=0;i<numParameters;i++) { 00104 pDCB->setParameter(i,(TD_Float)2.0); 00105 00106 if (fabsf((float)(pDCB->getParameter(i)-(TD_Float)2.0))>=FLT_EPSILON) { 00107 setTestResult(TEST_FAILURE,"Wrong parameter value"); 00108 return; 00109 } 00110 } 00111 00112 // Now we propagate the inputs and verify that the state 00113 // and outputs are properly updated 00114 for (int i=0;i<numInputs;i++) 00115 inputs[i]=testInputs[i]; 00116 00117 pDCB->propagate(); 00118 00119 if (fabsf((float)(pDCB->getState(0)-(TD_Float)2.345))>=FLT_EPSILON) { 00120 setTestResult(TEST_FAILURE,"Error in state update"); 00121 return; 00122 } 00123 00124 if (fabsf((float)(outputs[0]-(TD_Float)2.345))>=FLT_EPSILON || 00125 fabsf((float)(outputs[1]-(TD_Float)4.690))>=FLT_EPSILON) { 00126 setTestResult(TEST_FAILURE,"Error in output update"); 00127 return; 00128 } 00129 00130 // Set the state and verify its value 00131 pDCB->setState(0,(TD_Float)4.0); 00132 00133 if (fabsf((float)(pDCB->getState(0)-(TD_Float)4.0))>=FLT_EPSILON) { 00134 setTestResult(TEST_FAILURE,"Wrong state value"); 00135 return; 00136 } 00137 00138 if (isNonNominalCheckAllowed()) { 00139 // Try to link input and output with an out-of-range 00140 // index and verify that the correct event is generated 00141 pDCB->setInputLink(numInputs,&inputs[0]); 00142 if (!verifyLatestEvent(nEvt+1,EVT_ILLEGAL_CB)) 00143 return; 00144 00145 pDCB->setOutputLink(numOutputs,&outputs[0]); 00146 if (!verifyLatestEvent(nEvt+2,EVT_ILLEGAL_CB)) 00147 return; 00148 00149 // Try to set state and parameter values with an out-of-range 00150 // index and verify that the correct event is generated 00151 pDCB->setState(numStates,(TD_Float)0.0); 00152 if (!verifyLatestEvent(nEvt+3,EVT_ILLEGAL_CB)) 00153 return; 00154 00155 pDCB->setParameter(numParameters,(TD_Float)0.0); 00156 if (!verifyLatestEvent(nEvt+4,EVT_ILLEGAL_CB)) 00157 return; 00158 } 00159 00160 setTestResult(TEST_SUCCESS,"Test Successful"); 00161 return; 00162 }
Copyright 2003 P&P Software GmbH - All Rights Reserved