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

TestCaseControlList_1.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseControlList_1.cpp 00005 // 00006 // Version 1.2 00007 // Date 11.10.03 (Version 1.0) 00008 // 14.10.03 (Version 1.1) 00009 // 16.10.03 (Version 1.2) 00010 // Author R. Totaro 00011 // 00012 // Change Record: 00013 // 00014 // Change Record: 00015 // Version 1.1: Updated to reflect the new structure of the ControlBlock class 00016 // Version 1.2: Now using DC_DummyCopyControlBlock instead of DC_DummyControlBlock 00017 00018 #include "../GeneralInclude/CompilerSwitches.h" 00019 #include "../GeneralInclude/ClassId.h" 00020 #include "../GeneralInclude/Constants.h" 00021 #include "../Data/ControlBlock.h" 00022 #include "../Data/DC_DummyCopyControlBlock.h" 00023 #include "../Data/DC_ControlList.h" 00024 #include "TestCaseControlList_1.h" 00025 00026 #include <math.h> 00027 #include <float.h> 00028 00029 TestCaseControlList_1::TestCaseControlList_1(void) : 00030 TestCaseWithEvtCheck(ID_CONTROLLIST*10+1,"TestCaseControlList_1") { 00031 return; 00032 } 00033 00034 void TestCaseControlList_1::runTestCase(void) { 00035 DC_ControlList *pCL =new DC_ControlList; 00036 const unsigned int nEvt =getNumberOfEvents(); 00037 const unsigned int listSize =2; 00038 const unsigned int numInputs =3; 00039 const unsigned int numOutputs =2; 00040 const unsigned int numParameters=2; 00041 DC_DummyCopyControlBlock *pDCB[listSize]; 00042 00043 // Create and initialize the control blocks needed to 00044 // test the DC_ControlList class 00045 for (unsigned int i=0;i<listSize;i++) { 00046 pDCB[i]=new DC_DummyCopyControlBlock; 00047 00048 // Initialize input, output and parameters 00049 for (unsigned int t=0;t<numInputs;t++) 00050 pDCB[i]->setInput(t,(TD_Float)1.0); 00051 00052 for (unsigned int t=0;t<numOutputs;t++) 00053 pDCB[i]->setOutput(t,(TD_Float)0.0); 00054 00055 for (unsigned int t=0;t<numParameters;t++) 00056 pDCB[i]->setParameter(t,(TD_Float)1.0); 00057 } 00058 00059 // Verify the correctness of the class id 00060 if (pCL->getClassId()!=ID_CONTROLLIST) { 00061 setTestResult(TEST_FAILURE,"Wrong class identifier"); 00062 return; 00063 } 00064 00065 // A new object shall not be configured 00066 if (pCL->isObjectConfigured()) { 00067 setTestResult(TEST_FAILURE,"Newly created object already configured"); 00068 return; 00069 } 00070 00071 // Set the list size and verify it is reported correctly 00072 pCL->setListSize(listSize); 00073 if (pCL->getListSize()!=listSize) { 00074 setTestResult(TEST_FAILURE,"getListSize() failed"); 00075 return; 00076 } 00077 00078 // Load and get the control blocks 00079 for (unsigned int i=0;i<listSize;i++) { 00080 // The object is fully configured only when all the control blocks are loaded! 00081 if (pCL->isObjectConfigured()) { 00082 setTestResult(TEST_FAILURE,"Wrong configuration status"); 00083 return; 00084 } 00085 00086 pCL->setControlBlock(i,pDCB[i]); 00087 00088 if (pCL->getControlBlock(i)!=pDCB[i]) { 00089 setTestResult(TEST_FAILURE,"setControlBlock() failed"); 00090 return; 00091 } 00092 } 00093 00094 // Only now it is configured. Let's check it. 00095 if (!pCL->isObjectConfigured()) { 00096 setTestResult(TEST_FAILURE,"Object not configured"); 00097 return; 00098 } 00099 00100 // Verify that setControlBlock() generates an error report 00101 // when invoked with an invalid index 00102 if (isNonNominalCheckAllowed()) { 00103 pCL->setControlBlock(listSize,pDCB[0]); 00104 if (!verifyLatestEvent(nEvt+1,EVT_ILLEGAL_CL)) { 00105 setTestResult(TEST_FAILURE,"Failure of non-nominal behaviour check"); 00106 return; 00107 } 00108 } 00109 00110 // Let's invoke execute() and verify that it returns the correct code 00111 if (pCL->execute()!=ACTION_SUCCESS) { 00112 setTestResult(TEST_FAILURE,"Wrong execution return code"); 00113 return; 00114 } 00115 00116 // The control block's outputs should have been updated 00117 for (unsigned int i=0;i<listSize;i++) { 00118 if (fabsf((float)pDCB[i]->getOutput(0))<=FLT_EPSILON) { 00119 setTestResult(TEST_FAILURE,"Control block's propagate() not invoked"); 00120 return; 00121 } 00122 } 00123 00124 // Reset the control list and verify the the control blocks' 00125 // states are set to their default value 00126 pCL->reset(); 00127 for (unsigned int i=0;i<listSize;i++) { 00128 if (fabsf((float)(pCL->getControlBlock(i)->getState(0)-1.0f))>=FLT_EPSILON) { 00129 setTestResult(TEST_FAILURE,"Reset failed"); 00130 return; 00131 } 00132 } 00133 00134 setTestResult(TEST_SUCCESS,"Test Successful"); 00135 return; 00136 }
Copyright 2003 P&P Software GmbH - All Rights Reserved