00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027
00028 #include "../include/TestPointer.h"
00029
00030 namespace ParCompMarkTest
00031 {
00032
00033 void TestPointer::setUp()
00034 {
00035
00036 }
00037
00038
00039
00040 void TestPointer::tearDown()
00041 {
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 void TestPointer::test_constructor()
00051 {
00052
00053
00054
00055
00056
00057
00058
00059 Pointer < int,
00060 DummyLock > p;
00061
00062 CPPUNIT_ASSERT_MESSAGE("Null pointer initialization error", p.mMeta->ptr == 0);
00063 CPPUNIT_ASSERT_MESSAGE("Null pointer initialization error", p.mMeta->dead == true);
00064 CPPUNIT_ASSERT_MESSAGE("Null pointer initialization error", p.mMeta->usage == 1);
00065 CPPUNIT_ASSERT_MESSAGE("Null pointer initialization error", p.mMeta->ownMemory == false);
00066 }
00067
00068
00069
00070 void TestPointer::test_constructor_cT_p_cbool()
00071 {
00072
00073
00074
00075
00076
00077
00078
00079
00080 int *_p = new int (1);
00081 Pointer < int,
00082 DummyLock > p(_p);
00083
00084 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p.mMeta->ptr == _p);
00085 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p.mMeta->dead == false);
00086 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p.mMeta->usage == 1);
00087 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p.mMeta->ownMemory == true);
00088
00089
00090 Pointer < int,
00091 DummyLock > p2(_p, false);
00092
00093 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p2.mMeta->ptr == _p);
00094 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p2.mMeta->dead == false);
00095 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p2.mMeta->usage == 1);
00096 CPPUNIT_ASSERT_MESSAGE("C style pointer initialization error", p2.mMeta->ownMemory == false);
00097 }
00098
00099
00100
00101 void TestPointer::test_constructor_Pointer___T__Lock__()
00102 {
00103
00104
00105
00106
00107
00108
00109
00110 int *_p = new int (1);
00111 Pointer < int,
00112 DummyLock > p1(_p);
00113 Pointer < int,
00114 DummyLock > p2(p1);
00115
00116 CPPUNIT_ASSERT_MESSAGE("Copy constructor initialization error", p1.mMeta == p2.mMeta);
00117 CPPUNIT_ASSERT_MESSAGE("Copy constructor initialization error", p1.mMeta->usage == 2);
00118 }
00119
00120
00121
00122 void TestPointer::test_constructor_cPointer___T__Lock__()
00123 {
00124
00125
00126
00127
00128
00129
00130
00131 int *_p = new int (1);
00132 const Pointer < int,
00133 DummyLock > p1(_p);
00134 Pointer < int,
00135 DummyLock > p2(p1);
00136
00137 CPPUNIT_ASSERT_MESSAGE("Copy constructor initialization error", p1.mMeta == p2.mMeta);
00138 CPPUNIT_ASSERT_MESSAGE("Copy constructor initialization error", p1.mMeta->usage == 2);
00139 }
00140
00141
00142
00143 void TestPointer::test_destructor()
00144 {
00145 int *_p = new int (1);
00146 Pointer < int,
00147 DummyLock > p1(_p);
00148
00149 do
00150 {
00151 Pointer < int,
00152 DummyLock > p2(p1);
00153 } while(false);
00154 CPPUNIT_ASSERT_MESSAGE("Copy constructor initialization error", p1.mMeta->usage == 1);
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 void TestPointer::test_operator_assignment_cT_p()
00164 {
00165
00166
00167
00168
00169
00170
00171
00172 int *_p1 = new int (1);
00173 Pointer < int,
00174 DummyLock > p(_p1);
00175 Pointer < int,
00176 DummyLock > p2(p);
00177
00178
00179 void *_meta = p.mMeta;
00180
00181 CPPUNIT_ASSERT_NO_THROW(p = _p1);
00182 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta->ptr == _p1);
00183 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta->usage == 2);
00184 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta == _meta);
00185
00186
00187 int *_p2 = new int (2);
00188
00189 CPPUNIT_ASSERT_NO_THROW(p = _p2);
00190 CPPUNIT_ASSERT_MESSAGE("C style pointer assign error", p.mMeta->ptr == _p2);
00191 CPPUNIT_ASSERT_MESSAGE("C style pointer assign error", p.mMeta->usage == 1);
00192 }
00193
00194
00195
00196 void TestPointer::test_operator_assignment_Pointer___T__Lock__()
00197 {
00198
00199
00200
00201
00202
00203
00204
00205 typedef Pointer < int,
00206 DummyLock > MyPointer;
00207
00208 int *_p = new int (1);
00209 MyPointer p1(_p);
00210
00211
00212 void *_meta = p1.mMeta;
00213
00214 CPPUNIT_ASSERT_NO_THROW(p1 = p1);
00215 CPPUNIT_ASSERT_MESSAGE("Self assign error", p1.mMeta->usage == 1);
00216 CPPUNIT_ASSERT_MESSAGE("Self assign error", p1.mMeta == _meta);
00217
00218
00219 MyPointer p2;
00220
00221 CPPUNIT_ASSERT_NO_THROW(p2 = p1);
00222 CPPUNIT_ASSERT_MESSAGE("Assign error", p1.mMeta == p2.mMeta);
00223 CPPUNIT_ASSERT_MESSAGE("Assign error", p1.mMeta->usage == 2);
00224
00225
00226 CPPUNIT_ASSERT_NO_THROW(p2 = MyPointer());
00227 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->ptr == 0);
00228 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->dead == true);
00229 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->usage == 1);
00230 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->ownMemory == false);
00231
00232
00233 CPPUNIT_ASSERT_NO_THROW(p2 = MyPointer(new int (1234)));
00234
00235 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->ptr != 0);
00236 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", *(p2.mMeta->ptr) == 1234);
00237 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->dead == false);
00238 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->usage == 1);
00239 CPPUNIT_ASSERT_MESSAGE("Just-in created assign error", p2.mMeta->ownMemory == true);
00240 }
00241
00242
00243
00244 void TestPointer::test_operator_assignment_cPointer___T__Lock__()
00245 {
00246
00247
00248
00249
00250
00251
00252
00253
00254 }
00255
00256
00257
00258 void TestPointer::test_operator_memberSelection()
00259 {
00260
00261
00262
00263
00264
00265
00266
00267 int *_p = new int (1);
00268 Pointer < int,
00269 DummyLock > p(_p);
00270
00271 CPPUNIT_ASSERT_MESSAGE("Member selection(->) error", p.operator->() == _p);
00272 }
00273
00274
00275
00294
00295
00314
00315
00334
00335
00336 void TestPointer::test_operator_equality_cT_p()
00337 {
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 }
00350
00351
00352
00353 void TestPointer::test_operator_equality_Pointer___T__Lock__()
00354 {
00355
00356
00357
00358
00359
00360
00361
00362 int *_p1 = new int (1);
00363 int *_p2 = new int (2);
00364 Pointer < int,
00365 DummyLock > p1(_p1);
00366 Pointer < int,
00367 DummyLock > p2(p1);
00368 Pointer < int,
00369 DummyLock > p3(_p2);
00370
00371 CPPUNIT_ASSERT(p1 == p2);
00372 CPPUNIT_ASSERT(!(p1 == p3));
00373 }
00374
00375
00376
00377 void TestPointer::test_operator_inequality_cT_p()
00378 {
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 }
00391
00392
00393
00394 void TestPointer::test_operator_inequality_Pointer___T__Lock__()
00395 {
00396
00397
00398
00399
00400
00401
00402
00403 int *_p1 = new int (1);
00404 int *_p2 = new int (2);
00405 Pointer < int,
00406 DummyLock > p1(_p1);
00407 Pointer < int,
00408 DummyLock > p2(p1);
00409 Pointer < int,
00410 DummyLock > p3(_p2);
00411
00412 CPPUNIT_ASSERT(!(p1 != p2));
00413 CPPUNIT_ASSERT(p1 != p3);
00414 }
00415
00416
00417
00418
00419
00420
00421
00422 void TestPointer::test_isNull()
00423 {
00424
00425
00426
00427
00428
00429
00430
00431 Pointer < int,
00432 DummyLock > p1;
00433
00434 int *_p = new int (1);
00435 Pointer < int,
00436 DummyLock > p2(_p);
00437
00438 CPPUNIT_ASSERT(p1.isNull());
00439 CPPUNIT_ASSERT(!p2.isNull());
00440 }
00441
00442
00443
00444 void TestPointer::test_isNotNull()
00445 {
00446
00447
00448
00449
00450
00451
00452
00453 Pointer < int,
00454 DummyLock > p1;
00455
00456 int *_p = new int (1);
00457 Pointer < int,
00458 DummyLock > p2(_p);
00459
00460 CPPUNIT_ASSERT(!p1.isNotNull());
00461 CPPUNIT_ASSERT(p2.isNotNull());
00462 }
00463
00464
00465
00466 void TestPointer::test_assignWithLock_Pointer___T__Lock__()
00467 {
00468
00469
00470
00471
00472
00473
00474
00475 typedef Pointer < int,
00476 Mutex > MyPointer;
00477
00478 int *_p = new int (1);
00479 MyPointer p1(_p);
00480
00481
00482 void *_meta = p1.mMeta;
00483
00484 CPPUNIT_ASSERT_NO_THROW(p1.assignWithLock(p1));
00485 CPPUNIT_ASSERT_MESSAGE("Self assign error", p1.mMeta->usage == 1);
00486 CPPUNIT_ASSERT_MESSAGE("Self assign error", p1.mMeta == _meta);
00487
00488 CPPUNIT_ASSERT_MESSAGE("Self assign error", p1.mMeta->lock.getLocked());
00489 p1.unlock();
00490
00491
00492 MyPointer p2;
00493
00494 CPPUNIT_ASSERT_NO_THROW(p2.assignWithLock(p1));
00495 CPPUNIT_ASSERT_MESSAGE("Assign error", p1.mMeta == p2.mMeta);
00496 CPPUNIT_ASSERT_MESSAGE("Assign error", p1.mMeta->usage == 2);
00497
00498 CPPUNIT_ASSERT_MESSAGE("Self assign error", p2.mMeta->lock.getLocked());
00499 p2.unlock();
00500 }
00501
00502
00503
00504 void TestPointer::test_reference_cT_p()
00505 {
00506
00507
00508
00509
00510
00511
00512
00513 int *_p1 = new int (1);
00514 Pointer < int,
00515 DummyLock > p(_p1);
00516 Pointer < int,
00517 DummyLock > p2(p);
00518
00519
00520 void *_meta = p.mMeta;
00521
00522 CPPUNIT_ASSERT_NO_THROW(p = _p1);
00523 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta->ptr == _p1);
00524 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta->usage == 2);
00525 CPPUNIT_ASSERT_MESSAGE("C style pointer self assign error", p.mMeta == _meta);
00526
00527
00528 int *_p2 = new int (2);
00529
00530 CPPUNIT_ASSERT_NO_THROW(p = _p2);
00531 CPPUNIT_ASSERT_MESSAGE("C style pointer assign error", p.mMeta->ptr == _p2);
00532 CPPUNIT_ASSERT_MESSAGE("C style pointer assign error", p.mMeta->usage == 1);
00533 }
00534
00535
00536
00537 void TestPointer::test_getPtr()
00538 {
00539
00540
00541
00542
00543
00544
00545
00546 int *_p = new int (1);
00547 Pointer < int,
00548 DummyLock > p(_p);
00549
00550 CPPUNIT_ASSERT_MESSAGE("C style pointer error", p.getPtr() == _p);
00551 }
00552
00553
00554
00555 void TestPointer::test_kill_cbool()
00556 {
00557
00558
00559
00560
00561
00562
00563
00564
00565 int *_p = new int (1);
00566 Pointer < int,
00567 DummyLock > p1(_p);
00568 Pointer < int,
00569 DummyLock > p2(p1);
00570
00571 CPPUNIT_ASSERT_NO_THROW(p2.kill());
00572 CPPUNIT_ASSERT_MESSAGE("Nice kill error", p1.isNotNull());
00573
00574
00575 Pointer < int,
00576 DummyLock > p3(p1);
00577
00578 CPPUNIT_ASSERT_NO_THROW(p3.kill(true));
00579 CPPUNIT_ASSERT_MESSAGE("Force kill error", p1.isNull());
00580 }
00581
00582
00583
00584 void TestPointer::test_setNull_cbool()
00585 {
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 int *_p = new int (1);
00598
00599
00600 Pointer < int,
00601 DummyLock > p(_p);
00602
00603 p.setNull();
00604
00605
00606 delete _p;
00607
00608
00609 }
00610
00611
00612
00613 void TestPointer::test_lock()
00614 {
00615
00616
00617
00618
00619
00620
00621
00622
00623 }
00624
00625
00626
00627 void TestPointer::test_trylock()
00628 {
00629
00630
00631
00632
00633
00634
00635
00636
00637 }
00638
00639
00640
00641 void TestPointer::test_unlock()
00642 {
00643
00644
00645
00646
00647
00648
00649
00650
00651 }
00652
00653
00654
00655 void TestPointer::test_getLocked()
00656 {
00657
00658
00659
00660
00661
00662
00663
00664 CPPUNIT_FAIL("Implement this test!");
00665 }
00666
00667
00668
00669 void TestPointer::test__deletePointer_cbool_cbool()
00670 {
00671
00672
00673
00674
00675
00676
00677
00678
00679 }
00680
00681
00682
00683 void TestPointer::test__assignCPointer_cT_p_cbool()
00684 {
00685
00686
00687
00688
00689
00690
00691
00692
00693 }
00694
00695
00696
00697 void TestPointer::test__assignPointer_Pointer___T__Lock___cbool()
00698 {
00699
00700
00701
00702
00703
00704
00705
00706
00707 }
00708
00709
00710
00711 void TestPointer::test__switchPointer_Pointer___T__Lock___cbool()
00712 {
00713
00714
00715
00716
00717
00718
00719
00720 CPPUNIT_FAIL("Implement this test!");
00721 }
00722
00723
00724
00725 void TestPointer::test__equalsCPointer_cT_p()
00726 {
00727
00728
00729
00730
00731
00732
00733
00734
00735 }
00736
00737
00738
00739 void TestPointer::test__equalsPointer_Pointer___T__Lock__()
00740 {
00741
00742
00743
00744
00745
00746
00747
00748
00749 }
00750
00751
00752
00753
00755 CPPUNIT_TEST_SUITE_REGISTRATION(TestPointer);
00756 }