| 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 | * ManipulablePrototypeFactoryUnitTest.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 | #include <cppunit/CompilerOutputter.h>
|
|---|
| 18 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
|---|
| 19 | #include <cppunit/ui/text/TestRunner.h>
|
|---|
| 20 | #include "CodePatterns/Assert.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "ManipulablePrototypeFactoryUnitTest.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include "stubs/CommonStub.hpp"
|
|---|
| 25 | #include "stubs/ManipulableCloneStub.hpp"
|
|---|
| 26 | #include "stubs/ManipulablePrototypeFactoryStub.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include <typeinfo>
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_TESTRUNNER
|
|---|
| 31 | #include "UnitTestMain.hpp"
|
|---|
| 32 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 33 |
|
|---|
| 34 | /********************************************** Test classes **************************************/
|
|---|
| 35 |
|
|---|
| 36 | // Registers the fixture into the 'registry'
|
|---|
| 37 | CPPUNIT_TEST_SUITE_REGISTRATION( ManipulablePrototypeFactoryTest );
|
|---|
| 38 |
|
|---|
| 39 | void ManipulablePrototypeFactoryTest::setUp()
|
|---|
| 40 | {
|
|---|
| 41 | rndA =
|
|---|
| 42 | ManipulablePrototypeFactoryStub::getInstance().
|
|---|
| 43 | ManipulablePrototypeTable[ManipulablePrototypeFactoryStub::Aclass]->clone();
|
|---|
| 44 | CPPUNIT_ASSERT_EQUAL( 0, rndA->getcount() );
|
|---|
| 45 | rndB =
|
|---|
| 46 | ManipulablePrototypeFactoryStub::getInstance().
|
|---|
| 47 | ManipulablePrototypeTable[ManipulablePrototypeFactoryStub::Bclass]->clone();
|
|---|
| 48 | CPPUNIT_ASSERT_EQUAL( 0, rndB->getcount() );
|
|---|
| 49 |
|
|---|
| 50 | rndA_1 = NULL;
|
|---|
| 51 | rndA_2 = NULL;
|
|---|
| 52 | rndA_3 = NULL;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void ManipulablePrototypeFactoryTest::tearDown()
|
|---|
| 56 | {
|
|---|
| 57 | delete rndA;
|
|---|
| 58 | delete rndA_1;
|
|---|
| 59 | delete rndA_2;
|
|---|
| 60 | delete rndA_3;
|
|---|
| 61 | delete rndB;
|
|---|
| 62 | ManipulablePrototypeFactoryStub::purgeInstance();
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void ManipulablePrototypeFactoryTest::DistributionTest()
|
|---|
| 66 | {
|
|---|
| 67 | // check the injectiveness of enum and string map
|
|---|
| 68 | for (ManipulablePrototypeFactoryStub::NameMap::const_iterator
|
|---|
| 69 | iter = ManipulablePrototypeFactoryStub::getInstance().names.begin();
|
|---|
| 70 | iter != ManipulablePrototypeFactoryStub::getInstance().names.end();
|
|---|
| 71 | ++iter) {
|
|---|
| 72 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 73 | iter->second,
|
|---|
| 74 | ManipulablePrototypeFactoryStub::getInstance().getName(
|
|---|
| 75 | ManipulablePrototypeFactoryStub::getInstance().getEnum(
|
|---|
| 76 | iter->second
|
|---|
| 77 | )
|
|---|
| 78 | )
|
|---|
| 79 | );
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | // check distributions in the table
|
|---|
| 83 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 84 | std::string(typeid(ManipulablePrototype<teststubs::Aclass>).name()),
|
|---|
| 85 | std::string(typeid(*rndA).name())
|
|---|
| 86 | );
|
|---|
| 87 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 88 | std::string(typeid(ManipulablePrototype<teststubs::Bclass>).name()),
|
|---|
| 89 | std::string(typeid(*rndB).name())
|
|---|
| 90 | );
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void ManipulablePrototypeFactoryTest::getProductEnumTest()
|
|---|
| 94 | {
|
|---|
| 95 | rndA_1 =
|
|---|
| 96 | ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 97 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void ManipulablePrototypeFactoryTest::getProductNameTest()
|
|---|
| 101 | {
|
|---|
| 102 | rndA_1 =
|
|---|
| 103 | ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 104 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | void ManipulablePrototypeFactoryTest::getProductTypeTest()
|
|---|
| 108 | {
|
|---|
| 109 | rndA_1 =
|
|---|
| 110 | ManipulablePrototypeFactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
|
|---|
| 111 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void ManipulablePrototypeFactoryTest::Individualitytest()
|
|---|
| 115 | {
|
|---|
| 116 | // increasing this does not change the prototype
|
|---|
| 117 | rndA->count();
|
|---|
| 118 |
|
|---|
| 119 | rndA_1 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 120 | CPPUNIT_ASSERT_EQUAL( 0, rndA_1->getcount() );
|
|---|
| 121 | CPPUNIT_ASSERT( rndA->getcount() != rndA_1->getcount() );
|
|---|
| 122 | rndA_1->count();
|
|---|
| 123 | CPPUNIT_ASSERT( rndA->getcount() == rndA_1->getcount() );
|
|---|
| 124 |
|
|---|
| 125 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 126 | CPPUNIT_ASSERT_EQUAL( 0, rndA_2->getcount() );
|
|---|
| 127 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
|
|---|
| 128 | rndA_2->count();
|
|---|
| 129 | CPPUNIT_ASSERT( rndA->getcount() == rndA_2->getcount() );
|
|---|
| 130 | CPPUNIT_ASSERT( rndA_1->getcount() == rndA_2->getcount() );
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void ManipulablePrototypeFactoryTest::getPrototypetest()
|
|---|
| 134 | {
|
|---|
| 135 | // this method is protected and only friends may access it.
|
|---|
| 136 | IManipulablePrototype &rndA_1c = ManipulablePrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass"));
|
|---|
| 137 | CPPUNIT_ASSERT_EQUAL( 0, rndA_1c.getcount() );
|
|---|
| 138 |
|
|---|
| 139 | // clone the type and check whether new default values holds
|
|---|
| 140 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 141 | CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() );
|
|---|
| 142 | rndA_2->count();
|
|---|
| 143 | CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() );
|
|---|
| 144 |
|
|---|
| 145 | // the following is possible (with PrototypeFactory not!)
|
|---|
| 146 | rndA_1c.count();
|
|---|
| 147 | CPPUNIT_ASSERT_EQUAL( 1, rndA_1c.getcount() );
|
|---|
| 148 |
|
|---|
| 149 | // rndA has been cloned before we have manipulated the prototype
|
|---|
| 150 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
|
|---|
| 151 |
|
|---|
| 152 | // prototype is at 1, has been manipulated!
|
|---|
| 153 | rndA_3 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 154 | CPPUNIT_ASSERT_EQUAL( 1, rndA_3->getcount() );
|
|---|
| 155 |
|
|---|
| 156 | // rndA is older, before manipulation, hence still at 0
|
|---|
| 157 | CPPUNIT_ASSERT( rndA->getcount() != rndA_3->getcount() );
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void ManipulablePrototypeFactoryTest::manipulatePrototypetest()
|
|---|
| 161 | {
|
|---|
| 162 | teststubs::classParameters params;
|
|---|
| 163 | params.counter = 100;
|
|---|
| 164 | ManipulablePrototypeFactoryStub::getInstance().manipulatePrototype(std::string("Aclass"), params);
|
|---|
| 165 |
|
|---|
| 166 | rndA_1 = ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 167 | CPPUNIT_ASSERT( 100 == rndA_1->getcount() );
|
|---|
| 168 |
|
|---|
| 169 | rndA_1->count();
|
|---|
| 170 | CPPUNIT_ASSERT( 101 == rndA_1->getcount() );
|
|---|
| 171 |
|
|---|
| 172 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 173 | CPPUNIT_ASSERT( 100 == rndA_2->getcount() );
|
|---|
| 174 | CPPUNIT_ASSERT( rndA_1->getcount() != rndA_2->getcount() );
|
|---|
| 175 | }
|
|---|