00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <getopt.h>
00019 #include "Generic.h"
00020 #include <stdio.h>
00021 #include "MemoryMapArray.h"
00022 #include "MemoryMapArrayTest.h"
00023
00024 #include <assert.h>
00025 #include <stdlib.h>
00026
00027 #define TEST_FILE_NAME "results/testMemoryMapArray.vector"
00028
00029 class MemoryMapArrayTest : public UnitTest
00030 {
00031 public:
00032 MemoryMapArrayTest(const char *title) : UnitTest(title) {;}
00033 void testBool();
00034 void test2Bit();
00035 void test4Bit();
00036 void test32Bit();
00037
00038 void test() {
00039 testBool();
00040 test2Bit();
00041 test4Bit();
00042 test32Bit();
00043 }
00044 };
00045
00046 void MemoryMapArrayTest::testBool(void)
00047 {
00048 mmapArrayBool_t testVector;
00049
00050
00051 if(unlink(TEST_FILE_NAME) == 0)
00052 {
00053
00054 }
00055
00056
00057 check(m_failures, ++m_testNum, "Create 1 bit vector file", 0,
00058 testVector.create(TEST_FILE_NAME, 11));
00059 testVector.set(0,0);
00060 testVector.set(1,1);
00061 testVector.set(2,0);
00062 testVector.set(3,1);
00063 testVector.set(4,1);
00064 testVector.set(5,0);
00065 testVector.set(6,1);
00066 testVector.set(7,0);
00067 testVector.set(8,0);
00068 testVector.set(9,0);
00069 testVector.set(10,1);
00070 check(m_failures, ++m_testNum, "Access 1 bit element 0", 0U, testVector[0]);
00071 check(m_failures, ++m_testNum, "Access 1 bit element 1", 1U, testVector[1]);
00072 check(m_failures, ++m_testNum, "Access 1 bit element 2", 0U, testVector[2]);
00073 check(m_failures, ++m_testNum, "Access 1 bit element 3", 1U, testVector[3]);
00074 check(m_failures, ++m_testNum, "Access 1 bit element 4", 1U, testVector[4]);
00075 check(m_failures, ++m_testNum, "Access 1 bit element 5", 0U, testVector[5]);
00076 check(m_failures, ++m_testNum, "Access 1 bit element 6", 1U, testVector[6]);
00077 check(m_failures, ++m_testNum, "Access 1 bit element 7", 0U, testVector[7]);
00078 check(m_failures, ++m_testNum, "Access 1 bit element 8", 0U, testVector[8]);
00079 check(m_failures, ++m_testNum, "Access 1 bit element 9", 0U, testVector[9]);
00080 check(m_failures, ++m_testNum, "Access 1 bit element 10", 1U, testVector[10]);
00081 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00082 check(m_failures, ++m_testNum, "Re-open vector file", false, testVector.open(TEST_FILE_NAME));
00083 check(m_failures, ++m_testNum, "Access 1 bit element 0", 0U, testVector[0]);
00084 check(m_failures, ++m_testNum, "Access 1 bit element 1", 1U, testVector[1]);
00085 check(m_failures, ++m_testNum, "Access 1 bit element 2", 0U, testVector[2]);
00086 check(m_failures, ++m_testNum, "Access 1 bit element 3", 1U, testVector[3]);
00087 check(m_failures, ++m_testNum, "Access 1 bit element 4", 1U, testVector[4]);
00088 check(m_failures, ++m_testNum, "Access 1 bit element 5", 0U, testVector[5]);
00089 check(m_failures, ++m_testNum, "Access 1 bit element 6", 1U, testVector[6]);
00090 check(m_failures, ++m_testNum, "Access 1 bit element 7", 0U, testVector[7]);
00091 check(m_failures, ++m_testNum, "Access 1 bit element 8", 0U, testVector[8]);
00092 check(m_failures, ++m_testNum, "Access 1 bit element 9", 0U, testVector[9]);
00093 check(m_failures, ++m_testNum, "Access 1 bit element 10", 1U, testVector[10]);
00094
00095 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00096 check(m_failures, ++m_testNum, "Unlink vector file", 0, unlink(TEST_FILE_NAME));
00097
00098
00099 }
00100
00101 void MemoryMapArrayTest::test2Bit(void)
00102 {
00103 mmapArray2Bit_t testVector;
00104
00105
00106 if(unlink(TEST_FILE_NAME) == 0)
00107 {
00108
00109 }
00110
00111 check(m_failures, ++m_testNum, "Create 2 bit vector file", 0,
00112 testVector.create(TEST_FILE_NAME, 11));
00113
00114 testVector.set(0,0);
00115 testVector.set(1,1);
00116 testVector.set(2,2);
00117 testVector.set(3,3);
00118 testVector.set(4,3);
00119 testVector.set(5,2);
00120 testVector.set(6,1);
00121 testVector.set(7,0);
00122 testVector.set(8,2);
00123 testVector.set(9,1);
00124 testVector.set(10,3);
00125 check(m_failures, ++m_testNum, "Access 2 bit element 0", 0U, testVector[0]);
00126 check(m_failures, ++m_testNum, "Access 2 bit element 1", 1U, testVector[1]);
00127 check(m_failures, ++m_testNum, "Access 2 bit element 2", 2U, testVector[2]);
00128 check(m_failures, ++m_testNum, "Access 2 bit element 3", 3U, testVector[3]);
00129 check(m_failures, ++m_testNum, "Access 2 bit element 4", 3U, testVector[4]);
00130 check(m_failures, ++m_testNum, "Access 2 bit element 5", 2U, testVector[5]);
00131 check(m_failures, ++m_testNum, "Access 2 bit element 6", 1U, testVector[6]);
00132 check(m_failures, ++m_testNum, "Access 2 bit element 7", 0U, testVector[7]);
00133 check(m_failures, ++m_testNum, "Access 2 bit element 8", 2U, testVector[8]);
00134 check(m_failures, ++m_testNum, "Access 2 bit element 9", 1U, testVector[9]);
00135 check(m_failures, ++m_testNum, "Access 2 bit element 10", 3U, testVector[10]);
00136 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00137 check(m_failures, ++m_testNum, "Re-open vector file", false, testVector.open(TEST_FILE_NAME));
00138 check(m_failures, ++m_testNum, "Access 2 bit element 0", 0U, testVector[0]);
00139 check(m_failures, ++m_testNum, "Access 2 bit element 1", 1U, testVector[1]);
00140 check(m_failures, ++m_testNum, "Access 2 bit element 2", 2U, testVector[2]);
00141 check(m_failures, ++m_testNum, "Access 2 bit element 3", 3U, testVector[3]);
00142 check(m_failures, ++m_testNum, "Access 2 bit element 4", 3U, testVector[4]);
00143 check(m_failures, ++m_testNum, "Access 2 bit element 5", 2U, testVector[5]);
00144 check(m_failures, ++m_testNum, "Access 2 bit element 6", 1U, testVector[6]);
00145 check(m_failures, ++m_testNum, "Access 2 bit element 7", 0U, testVector[7]);
00146 check(m_failures, ++m_testNum, "Access 2 bit element 8", 2U, testVector[8]);
00147 check(m_failures, ++m_testNum, "Access 2 bit element 9", 1U, testVector[9]);
00148 check(m_failures, ++m_testNum, "Access 2 bit element 10", 3U, testVector[10]);
00149
00150 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00151 check(m_failures, ++m_testNum, "Unlink vector file", 0, unlink(TEST_FILE_NAME));
00152
00153 }
00154
00155 void MemoryMapArrayTest::test4Bit(void)
00156 {
00157 mmapArray4Bit_t testVector;
00158
00159
00160 if(unlink(TEST_FILE_NAME) == 0)
00161 {
00162
00163 }
00164
00165 check(m_failures, ++m_testNum, "Create 4 bit vector file", 0,
00166 testVector.create(TEST_FILE_NAME, 11));
00167
00168 testVector.set(0,0);
00169 testVector.set(1,1);
00170 testVector.set(2,2);
00171 testVector.set(3,3);
00172 testVector.set(4,4);
00173 testVector.set(5,5);
00174 testVector.set(6,6);
00175 testVector.set(7,7);
00176 testVector.set(8,8);
00177 testVector.set(9,9);
00178 testVector.set(10,10);
00179
00180 check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
00181 check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
00182 check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
00183 check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
00184 check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
00185 check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
00186 check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
00187 check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
00188 check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
00189 check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
00190 check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
00191
00192 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00193 check(m_failures, ++m_testNum, "Re-open vector file", false, testVector.open(TEST_FILE_NAME));
00194 check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
00195 check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
00196 check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
00197 check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
00198 check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
00199 check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
00200 check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
00201 check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
00202 check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
00203 check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
00204 check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
00205
00206 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00207 check(m_failures, ++m_testNum, "Unlink vector file", 0, unlink(TEST_FILE_NAME));
00208 }
00209
00210 void MemoryMapArrayTest::test32Bit(void)
00211 {
00212
00213 mmapArrayUint32_t testVector;
00214
00215
00216 if(unlink(TEST_FILE_NAME) == 0)
00217 {
00218
00219 }
00220
00221 check(m_failures, ++m_testNum, "Create 32 bit vector file", 0,
00222 testVector.create(TEST_FILE_NAME, 11));
00223
00224 testVector.set(0,0);
00225 testVector.set(1,1);
00226 testVector.set(2,2);
00227 testVector.set(3,3);
00228 testVector.set(4,4);
00229 testVector.set(5,5);
00230 testVector.set(6,6);
00231 testVector.set(7,7);
00232 testVector.set(8,8);
00233 testVector.set(9,9);
00234 testVector.set(10,10);
00235 check(m_failures, ++m_testNum, "Access 32 bit element 0", 0U, testVector[0]);
00236 check(m_failures, ++m_testNum, "Access 32 bit element 1", 1U, testVector[1]);
00237 check(m_failures, ++m_testNum, "Access 32 bit element 2", 2U, testVector[2]);
00238 check(m_failures, ++m_testNum, "Access 32 bit element 3", 3U, testVector[3]);
00239 check(m_failures, ++m_testNum, "Access 32 bit element 4", 4U, testVector[4]);
00240 check(m_failures, ++m_testNum, "Access 32 bit element 5", 5U, testVector[5]);
00241 check(m_failures, ++m_testNum, "Access 32 bit element 6", 6U, testVector[6]);
00242 check(m_failures, ++m_testNum, "Access 32 bit element 7", 7U, testVector[7]);
00243 check(m_failures, ++m_testNum, "Access 32 bit element 8", 8U, testVector[8]);
00244 check(m_failures, ++m_testNum, "Access 32 bit element 9", 9U, testVector[9]);
00245 check(m_failures, ++m_testNum, "Access 32 bit element 10", 10U, testVector[10]);
00246
00247
00248 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00249 check(m_failures, ++m_testNum, "Re-open vector file", false, testVector.open(TEST_FILE_NAME));
00250 check(m_failures, ++m_testNum, "Access 32 bit element 0", 0U, testVector[0]);
00251 check(m_failures, ++m_testNum, "Access 32 bit element 1", 1U, testVector[1]);
00252 check(m_failures, ++m_testNum, "Access 32 bit element 2", 2U, testVector[2]);
00253 check(m_failures, ++m_testNum, "Access 32 bit element 3", 3U, testVector[3]);
00254 check(m_failures, ++m_testNum, "Access 32 bit element 4", 4U, testVector[4]);
00255 check(m_failures, ++m_testNum, "Access 32 bit element 5", 5U, testVector[5]);
00256 check(m_failures, ++m_testNum, "Access 32 bit element 6", 6U, testVector[6]);
00257 check(m_failures, ++m_testNum, "Access 32 bit element 7", 7U, testVector[7]);
00258 check(m_failures, ++m_testNum, "Access 32 bit element 8", 8U, testVector[8]);
00259 check(m_failures, ++m_testNum, "Access 32 bit element 9", 9U, testVector[9]);
00260 check(m_failures, ++m_testNum, "Access 32 bit element 10", 10U, testVector[10]);
00261
00262 check(m_failures, ++m_testNum, "Close vector file", false, testVector.close());
00263 check(m_failures, ++m_testNum, "Unlink vector file", 0, unlink(TEST_FILE_NAME));
00264 }
00265
00266 int main(int argc, char **argv)
00267 {
00268 MemoryMapArrayTest test("MemoryMapArrayTest");
00269 #if 0
00270 bool showAllCasesFlag = false;
00271 int opt;
00272
00273 while(( opt = getopt(argc, (char **) argv, "v")) != -1) {
00274 switch(opt) {
00275 case 'v':
00276 showAllCasesFlag = true;
00277 break;
00278 default:
00279 std::cerr << "usage: testSW [-v]" << std::endl;
00280 exit(1);
00281 }
00282 }
00283
00284 #endif
00285
00286 test.test();
00287
00288 std::cout << test;
00289
00290 exit(test.getFailureCount());
00291 }