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

TestCaseDummyCopyControlBlock_1.cpp

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