[084729c] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 | /*
|
---|
| 8 | * CloneUnitTest.cpp
|
---|
| 9 | *
|
---|
| 10 | * Created on: Jan 03, 2011
|
---|
| 11 | * Author: heber
|
---|
| 12 | */
|
---|
| 13 | // include config.h
|
---|
| 14 | #ifdef HAVE_CONFIG_H
|
---|
| 15 | #include <config.h>
|
---|
| 16 | #endif
|
---|
| 17 |
|
---|
| 18 | #include "CloneUnitTest.hpp"
|
---|
| 19 |
|
---|
| 20 | #include <cppunit/CompilerOutputter.h>
|
---|
| 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 22 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 23 |
|
---|
| 24 | #include "CodePatterns/Assert.hpp"
|
---|
| 25 |
|
---|
| 26 | #include "CodePatterns/Clone.hpp"
|
---|
| 27 | #include "stubs/CloneStub.hpp"
|
---|
| 28 |
|
---|
| 29 | #include <typeinfo>
|
---|
| 30 |
|
---|
| 31 | #ifdef HAVE_TESTRUNNER
|
---|
| 32 | #include "UnitTestMain.hpp"
|
---|
| 33 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 34 |
|
---|
| 35 | /********************************************** Test classes **************************************/
|
---|
| 36 |
|
---|
| 37 | // Registers the fixture into the 'registry'
|
---|
| 38 | CPPUNIT_TEST_SUITE_REGISTRATION( CloneTest );
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | void CloneTest::setUp()
|
---|
| 42 | {
|
---|
| 43 | ip1 = &p1;
|
---|
| 44 | CPPUNIT_ASSERT( ip1 == &p1 );
|
---|
| 45 | ip2 = &p2;
|
---|
| 46 | CPPUNIT_ASSERT( ip2 == &p2 );
|
---|
| 47 |
|
---|
| 48 | ip1_1 = NULL;
|
---|
| 49 | ip1_2 = NULL;
|
---|
| 50 | ip2_1 = NULL;
|
---|
| 51 | ip2_2 = NULL;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void CloneTest::tearDown()
|
---|
| 55 | {
|
---|
| 56 | // NULL pointer may be deleted.
|
---|
| 57 | delete ip1_1;
|
---|
| 58 | delete ip1_2;
|
---|
| 59 | delete ip2_1;
|
---|
| 60 | delete ip2_2;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void CloneTest::CreationTest()
|
---|
| 64 | {
|
---|
| 65 | // test that new instances have been created.
|
---|
| 66 | ip1_1 = p1.clone();
|
---|
| 67 | ip1_2 = p1.clone();
|
---|
| 68 | CPPUNIT_ASSERT( ip1 != ip1_1 );
|
---|
| 69 | CPPUNIT_ASSERT( ip1 != ip1_2 );
|
---|
| 70 |
|
---|
| 71 | ip2_1 = p2.clone();
|
---|
| 72 | ip2_2 = p2.clone();
|
---|
| 73 | CPPUNIT_ASSERT( ip2 != ip2_1 );
|
---|
| 74 | CPPUNIT_ASSERT( ip2 != ip2_2 );
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void CloneTest::IndividualityTest()
|
---|
| 78 | {
|
---|
| 79 | CPPUNIT_ASSERT( typeid(p1).name() != typeid(p2).name() );
|
---|
| 80 | p1.count();
|
---|
| 81 | p2.count();
|
---|
| 82 | p2.count();
|
---|
| 83 |
|
---|
| 84 | // make refs to interface
|
---|
| 85 | ip1 = &p1;
|
---|
| 86 | CPPUNIT_ASSERT( ip1 == &p1 );
|
---|
| 87 | ip2 = &p2;
|
---|
| 88 | CPPUNIT_ASSERT( ip2 == &p2 );
|
---|
| 89 |
|
---|
| 90 | // clone (i.e. counter = p?.counter ), ...
|
---|
| 91 | ip1_1 = p1.clone();
|
---|
| 92 | ip1_2 = p1.clone();
|
---|
| 93 | ip2_1 = p2.clone();
|
---|
| 94 | ip2_2 = p2.clone();
|
---|
| 95 |
|
---|
| 96 | // check that each is individual
|
---|
| 97 | CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_1->getcount() );
|
---|
| 98 | CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_2->getcount() );
|
---|
| 99 | CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_1->getcount() );
|
---|
| 100 | CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_2->getcount() );
|
---|
| 101 |
|
---|
| 102 | // increase individual counters and check against others
|
---|
| 103 | ip1_1->count();
|
---|
| 104 | CPPUNIT_ASSERT( ip1->getcount() != ip1_1->getcount() );
|
---|
| 105 | CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
|
---|
| 106 | CPPUNIT_ASSERT( ip1->getcount() == ip1_2->getcount() );
|
---|
| 107 |
|
---|
| 108 | ip1_2->count();
|
---|
| 109 | CPPUNIT_ASSERT( ip1_1->getcount() == ip1_2->getcount() );
|
---|
| 110 | CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
|
---|
| 111 |
|
---|
| 112 | ip1_2->count();
|
---|
| 113 | CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
|
---|
| 114 | CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
|
---|
| 115 | }
|
---|