| [746ff1] | 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 | * CreatorUnitTest.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 "CreatorUnitTest.hpp" | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 21 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 22 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 23 |  | 
|---|
| [9b8fa4] | 24 | #include "CodePatterns/Assert.hpp" | 
|---|
| [746ff1] | 25 |  | 
|---|
|  | 26 | #include <typeinfo> | 
|---|
|  | 27 |  | 
|---|
|  | 28 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 29 | #include "UnitTestMain.hpp" | 
|---|
|  | 30 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 31 |  | 
|---|
|  | 32 | /********************************************** Test classes **************************************/ | 
|---|
|  | 33 |  | 
|---|
|  | 34 | // Registers the fixture into the 'registry' | 
|---|
|  | 35 | CPPUNIT_TEST_SUITE_REGISTRATION( CreatorTest ); | 
|---|
|  | 36 |  | 
|---|
|  | 37 |  | 
|---|
|  | 38 | void CreatorTest::setUp() | 
|---|
|  | 39 | { | 
|---|
| [9f39db] | 40 | testingA1 = NULL; | 
|---|
|  | 41 | testingA2 = NULL; | 
|---|
|  | 42 | testingB1 = NULL; | 
|---|
|  | 43 | testingB2 = NULL; | 
|---|
| [746ff1] | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 | void CreatorTest::tearDown() | 
|---|
|  | 47 | { | 
|---|
| [9f39db] | 48 | delete testingA1; | 
|---|
|  | 49 | delete testingA2; | 
|---|
|  | 50 | delete testingB1; | 
|---|
|  | 51 | delete testingB2; | 
|---|
| [746ff1] | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | void CreatorTest::CreationTest() | 
|---|
|  | 55 | { | 
|---|
| [9f39db] | 56 | testingA1 = teststubA.create(); | 
|---|
|  | 57 | testingA2 = teststubA.create(); | 
|---|
|  | 58 | testingB1 = teststubB.create(); | 
|---|
| [746ff1] | 59 |  | 
|---|
|  | 60 | // instance is different | 
|---|
|  | 61 | CPPUNIT_ASSERT( &teststubA != testingA1 ); | 
|---|
|  | 62 | CPPUNIT_ASSERT( &teststubA != testingA2 ); | 
|---|
|  | 63 | CPPUNIT_ASSERT( testingA1 != testingA2 ); | 
|---|
| [9f39db] | 64 | CPPUNIT_ASSERT( &teststubB != testingB1 ); | 
|---|
| [746ff1] | 65 |  | 
|---|
|  | 66 | // type is the same ... | 
|---|
|  | 67 | CPPUNIT_ASSERT_EQUAL( typeid(teststubA).name(), typeid(*testingA1).name() ); | 
|---|
|  | 68 | CPPUNIT_ASSERT_EQUAL( typeid(*testingA1).name(), typeid(*testingA2).name() ); | 
|---|
| [9f39db] | 69 | CPPUNIT_ASSERT_EQUAL( typeid(teststubB).name(), typeid(*testingB1).name() ); | 
|---|
| [746ff1] | 70 |  | 
|---|
|  | 71 | // ... for the same particular type only! | 
|---|
|  | 72 | // (RTTI knows about the true complex type!) | 
|---|
| [9f39db] | 73 | CPPUNIT_ASSERT( typeid(*testingB1).name() != typeid(*testingA1).name() ); | 
|---|
|  | 74 | CPPUNIT_ASSERT( typeid(*testingB1).name() != typeid(*testingA2).name() ); | 
|---|
| [746ff1] | 75 |  | 
|---|
|  | 76 | // but not for different encapsulated types | 
|---|
| [9f39db] | 77 | CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB1).name() ); | 
|---|
| [746ff1] | 78 | CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA1).name() ); | 
|---|
|  | 79 | CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA2).name() ); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | } | 
|---|
|  | 82 |  | 
|---|
|  | 83 | void CreatorTest::IndividualityTest() | 
|---|
|  | 84 | { | 
|---|
|  | 85 | teststubA.count(); | 
|---|
|  | 86 | teststubB.count(); | 
|---|
|  | 87 | teststubB.count(); | 
|---|
|  | 88 |  | 
|---|
| [9f39db] | 89 | testingA1 = teststubA.create(); | 
|---|
|  | 90 | testingA2 = teststubA.create(); | 
|---|
|  | 91 | testingB1 = teststubB.create(); | 
|---|
|  | 92 | testingB2 = teststubB.create(); | 
|---|
| [746ff1] | 93 |  | 
|---|
|  | 94 | // content is the same (prototype has been copied) | 
|---|
|  | 95 | CPPUNIT_ASSERT( teststubA.getcount() != testingA1->getcount()); | 
|---|
|  | 96 | CPPUNIT_ASSERT( teststubA.getcount() != testingA2->getcount()); | 
|---|
|  | 97 | CPPUNIT_ASSERT( teststubB.getcount() != testingB1->getcount()); | 
|---|
|  | 98 | CPPUNIT_ASSERT( teststubB.getcount() != testingB2->getcount()); | 
|---|
|  | 99 |  | 
|---|
|  | 100 | // but each copy is independent | 
|---|
|  | 101 | testingA1->count(); | 
|---|
|  | 102 | CPPUNIT_ASSERT( testingA1->getcount() != testingA2->getcount()); | 
|---|
|  | 103 | testingB1->count(); | 
|---|
|  | 104 | testingB2->count(); | 
|---|
|  | 105 | testingB2->count(); | 
|---|
|  | 106 | CPPUNIT_ASSERT( testingB1->getcount() != testingB2->getcount()); | 
|---|
|  | 107 | } | 
|---|