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

TestCaseBasicDatabase_1.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseBasicDatabase_1.cpp 00005 // 00006 // Version 1.0 00007 // Date 13.09.02 00008 // Author A. Pasetti (P&P Software) 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/ClassId.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../Data/DC_BasicDatabase.h" 00014 #include "TestCaseBasicDatabase_1.h" 00015 00016 #include <math.h> 00017 #include <float.h> 00018 00019 TestCaseBasicDatabase_1::TestCaseBasicDatabase_1(void) : 00020 TestCaseGenericSetUp(ID_BASICDATABASE*10+1,"TestCaseBasicDatabase_1") { 00021 return; 00022 } 00023 00024 void TestCaseBasicDatabase_1::runTestCase(void) { 00025 00026 // Data structure to simulate the default table 00027 // NB: In order to avoid alignment problems, make sure that the 00028 // table is aligned on a double word boundary 00029 // NB: The double array is oversized: the intended size of the 00030 // default table is 12 bytes. 00031 double shadowDefaultTable[3]; 00032 unsigned int* defaultTable = (unsigned int*)shadowDefaultTable; 00033 00034 // The following data simulate the default table of the basic database. 00035 // The table is assumed to contain three integer items. 00036 // NB: this test assumes that the compiler aligns the following three 00037 // in continguous memory location. 00038 defaultTable[0] = 0xAABBCCDD; // first parameter 00039 defaultTable[1] = 0x11223344; // second parameter 00040 defaultTable[2] = 0x55667788; // third parameter 00041 00042 // The following constants represent the parameter identifiers of the 00043 // three entries in the default table 00044 const TD_DatabaseId PD_T1 = 0; 00045 const TD_DatabaseId PD_T2 = 4; 00046 const TD_DatabaseId PD_T3 = 8; 00047 00048 // Data structure to simulate the operational table 00049 // NB: In order to avoid alignment problems, make sure that the 00050 // table is aligned on a double word boundary 00051 double shadowOperationalTable[3]; 00052 int* operationalTable = (int*)shadowOperationalTable; 00053 00054 // Instantiate basic database 00055 DC_BasicDatabase* pDB = new DC_BasicDatabase(); 00056 00057 // Verify correctness of class ID 00058 if (pDB->getClassId() != ID_BASICDATABASE) 00059 { setTestResult(TEST_FAILURE, "Wrong class ID"); 00060 return; 00061 } 00062 00063 // Check that database is not yet configured 00064 if ( pDB->isObjectConfigured() != NOT_CONFIGURED ) 00065 { setTestResult(TEST_FAILURE, "Incorrect configuration status at creation"); 00066 return; 00067 } 00068 00069 // Set the table length and check correctness 00070 pDB->setTableLength(12); 00071 if ( pDB->getTableLength() != 12 ) 00072 { setTestResult(TEST_FAILURE, "Incorrect table length"); 00073 return; 00074 } 00075 00076 // Complete configuration of the database 00077 pDB->setDefaultTable((char*)defaultTable); 00078 pDB->setOperationalTable((char*)operationalTable); 00079 pDB->reset(); 00080 00081 // Check that database is configured 00082 if ( pDB->isObjectConfigured() != CONFIGURED ) 00083 { setTestResult(TEST_FAILURE, "Incorrect configuration status after configuration was completed"); 00084 return; 00085 } 00086 00087 // Check that operational table was correctly initialized 00088 if ( pDB->getParameterUnsignedInt(PD_T1) != defaultTable[0] ) 00089 { setTestResult(TEST_FAILURE, "Incorrect initialization of operational table"); 00090 return; 00091 } 00092 if ( pDB->getParameterUnsignedInt(PD_T2) != defaultTable[1] ) 00093 { setTestResult(TEST_FAILURE, "Incorrect initialization of operational table"); 00094 return; 00095 } 00096 if ( pDB->getParameterUnsignedInt(PD_T3) != defaultTable[2] ) 00097 { setTestResult(TEST_FAILURE, "Incorrect initialization of operational table"); 00098 return; 00099 } 00100 00101 // Check the read/write services for all parameter types 00102 double d = 0.2; 00103 pDB->setParameter(PD_T1,d); 00104 if (fabs(pDB->getParameterDouble(PD_T1)-d)>DBL_EPSILON) 00105 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for double parameter"); 00106 return; 00107 } 00108 if (fabs((*pDB->getParameterPointerDouble(PD_T1))-d)>DBL_EPSILON) 00109 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to double parameter"); 00110 return; 00111 } 00112 00113 float f = (float)0.4; 00114 pDB->setParameter(PD_T2,f); 00115 if (fabs(pDB->getParameterFloat(PD_T2)-f)>FLT_EPSILON) 00116 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for float parameter"); 00117 return; 00118 } 00119 if (fabs((*pDB->getParameterPointerFloat(PD_T2))-f)>FLT_EPSILON) 00120 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to float parameter"); 00121 return; 00122 } 00123 00124 unsigned int ui = 10; 00125 pDB->setParameter(PD_T2,ui); 00126 if (pDB->getParameterUnsignedInt(PD_T2)!=ui) 00127 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for unsigned int parameter"); 00128 return; 00129 } 00130 if ((*pDB->getParameterPointerUnsignedInt(PD_T2))!=ui) 00131 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to unsigned int parameter"); 00132 return; 00133 } 00134 00135 int i = 20; 00136 pDB->setParameter(PD_T2,i); 00137 if (pDB->getParameterInt(PD_T2)!=i) 00138 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for int parameter"); 00139 return; 00140 } 00141 if ((*pDB->getParameterPointerInt(PD_T2))!=i) 00142 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to int parameter"); 00143 return; 00144 } 00145 00146 unsigned short us = 40; 00147 pDB->setParameter(PD_T2,us); 00148 if (pDB->getParameterUnsignedShort(PD_T2)!=us) 00149 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for unsigned short parameter"); 00150 return; 00151 } 00152 if ((*pDB->getParameterPointerUnsignedShort(PD_T2))!=us) 00153 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to unsigned short parameter"); 00154 return; 00155 } 00156 00157 short s = 30; 00158 pDB->setParameter(PD_T2,s); 00159 if (pDB->getParameterShort(PD_T2)!=s) 00160 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for short parameter"); 00161 return; 00162 } 00163 if ((*pDB->getParameterPointerShort(PD_T2))!=s) 00164 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to short parameter"); 00165 return; 00166 } 00167 00168 unsigned char uc = 4; 00169 pDB->setParameter(PD_T2,uc); 00170 if (pDB->getParameterUnsignedChar(PD_T2)!=uc) 00171 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for unsigned char parameter"); 00172 return; 00173 } 00174 if ((*pDB->getParameterPointerUnsignedChar(PD_T2))!=uc) 00175 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to unsigned char parameter"); 00176 return; 00177 } 00178 00179 char c = 2; 00180 pDB->setParameter(PD_T2,c); 00181 if (pDB->getParameterUnsignedChar(PD_T2)!=c) 00182 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for char parameter"); 00183 return; 00184 } 00185 if ((*pDB->getParameterPointerChar(PD_T2))!=c) 00186 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to char parameter"); 00187 return; 00188 } 00189 00190 bool b = true; 00191 pDB->setParameter(PD_T2,b); 00192 if (pDB->getParameterBool(PD_T2)!=b) 00193 { setTestResult(TEST_FAILURE, "Incorrect write/read cycle for boolean parameter"); 00194 return; 00195 } 00196 if ((*pDB->getParameterPointerBool(PD_T2))!=b) 00197 { setTestResult(TEST_FAILURE, "Incorrect getter method for pointer to boolean parameter"); 00198 return; 00199 } 00200 00201 00202 setTestResult(TEST_SUCCESS,"Test Successful"); 00203 return; 00204 }
Copyright 2003 P&P Software GmbH - All Rights Reserved