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

TestCaseDummyDataPoolControlBlock_1.cpp

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