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 | * PrototypeFactoryUnitTest.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 "PrototypeFactoryUnitTest.hpp"
|
---|
23 |
|
---|
24 | #include "stubs/CommonStub.hpp"
|
---|
25 | #include "stubs/PrototypeFactoryStub.hpp"
|
---|
26 |
|
---|
27 | #include <typeinfo>
|
---|
28 |
|
---|
29 | #ifdef HAVE_TESTRUNNER
|
---|
30 | #include "UnitTestMain.hpp"
|
---|
31 | #endif /*HAVE_TESTRUNNER*/
|
---|
32 |
|
---|
33 | /********************************************** Test classes **************************************/
|
---|
34 |
|
---|
35 | // Registers the fixture into the 'registry'
|
---|
36 | CPPUNIT_TEST_SUITE_REGISTRATION( PrototypeFactoryTest );
|
---|
37 |
|
---|
38 | void PrototypeFactoryTest::setUp()
|
---|
39 | {
|
---|
40 | rndA =
|
---|
41 | PrototypeFactoryStub::getInstance().
|
---|
42 | PrototypeTable[PrototypeFactoryStub::Aclass]->clone();
|
---|
43 | CPPUNIT_ASSERT_EQUAL( 0, rndA->getcount() );
|
---|
44 | rndB =
|
---|
45 | PrototypeFactoryStub::getInstance().
|
---|
46 | PrototypeTable[PrototypeFactoryStub::Bclass]->clone();
|
---|
47 | CPPUNIT_ASSERT_EQUAL( 0, rndB->getcount() );
|
---|
48 |
|
---|
49 | rndA_1 = NULL;
|
---|
50 | rndA_2 = NULL;
|
---|
51 | rndA_3 = NULL;
|
---|
52 | }
|
---|
53 |
|
---|
54 | void PrototypeFactoryTest::tearDown()
|
---|
55 | {
|
---|
56 | delete rndA;
|
---|
57 | delete rndA_1;
|
---|
58 | delete rndA_2;
|
---|
59 | delete rndA_3;
|
---|
60 | delete rndB;
|
---|
61 | PrototypeFactoryStub::purgeInstance();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void PrototypeFactoryTest::DistributionTest()
|
---|
65 | {
|
---|
66 | // check the injectiveness of enum and string map
|
---|
67 | for (PrototypeFactoryStub::NameMap::const_iterator
|
---|
68 | iter = PrototypeFactoryStub::getInstance().names.begin();
|
---|
69 | iter != PrototypeFactoryStub::getInstance().names.end();
|
---|
70 | ++iter) {
|
---|
71 | CPPUNIT_ASSERT_EQUAL(
|
---|
72 | iter->second,
|
---|
73 | PrototypeFactoryStub::getInstance().getName(
|
---|
74 | PrototypeFactoryStub::getInstance().getEnum(
|
---|
75 | iter->second
|
---|
76 | )
|
---|
77 | )
|
---|
78 | );
|
---|
79 | }
|
---|
80 |
|
---|
81 | // check distributions in the table
|
---|
82 | CPPUNIT_ASSERT_EQUAL(
|
---|
83 | std::string(typeid(Prototype<teststubs::Aclass>).name()),
|
---|
84 | std::string(typeid(*rndA).name())
|
---|
85 | );
|
---|
86 | CPPUNIT_ASSERT_EQUAL(
|
---|
87 | std::string(typeid(Prototype<teststubs::Bclass>).name()),
|
---|
88 | std::string(typeid(*rndB).name())
|
---|
89 | );
|
---|
90 | }
|
---|
91 |
|
---|
92 | void PrototypeFactoryTest::getProductEnumTest()
|
---|
93 | {
|
---|
94 | rndA_1 =
|
---|
95 | PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
|
---|
96 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
97 | }
|
---|
98 |
|
---|
99 | void PrototypeFactoryTest::getProductNameTest()
|
---|
100 | {
|
---|
101 | rndA_1 =
|
---|
102 | PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
---|
103 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
104 | }
|
---|
105 |
|
---|
106 | void PrototypeFactoryTest::getProductTypeTest()
|
---|
107 | {
|
---|
108 | rndA_1 =
|
---|
109 | PrototypeFactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
|
---|
110 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
111 | }
|
---|
112 |
|
---|
113 | void PrototypeFactoryTest::Individualitytest()
|
---|
114 | {
|
---|
115 | // increasing this does not change the prototype
|
---|
116 | rndA->count();
|
---|
117 |
|
---|
118 | rndA_1 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
|
---|
119 | CPPUNIT_ASSERT_EQUAL( 0, rndA_1->getcount() );
|
---|
120 | CPPUNIT_ASSERT( rndA->getcount() != rndA_1->getcount() );
|
---|
121 | rndA_1->count();
|
---|
122 | CPPUNIT_ASSERT( rndA->getcount() == rndA_1->getcount() );
|
---|
123 |
|
---|
124 | rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
|
---|
125 | CPPUNIT_ASSERT_EQUAL( 0, rndA_2->getcount() );
|
---|
126 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
|
---|
127 | rndA_2->count();
|
---|
128 | CPPUNIT_ASSERT( rndA->getcount() == rndA_2->getcount() );
|
---|
129 | CPPUNIT_ASSERT( rndA_1->getcount() == rndA_2->getcount() );
|
---|
130 | }
|
---|
131 |
|
---|
132 | void PrototypeFactoryTest::getPrototypetest()
|
---|
133 | {
|
---|
134 | // this method is protected and only friends may access it.
|
---|
135 | const IPrototype& rndA_1c = PrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass"));
|
---|
136 |
|
---|
137 | // clone the type and check whether new default values holds
|
---|
138 | rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
|
---|
139 | CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() );
|
---|
140 | rndA_2->count();
|
---|
141 | CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() );
|
---|
142 |
|
---|
143 | // the following is not possible
|
---|
144 | //rndA_1c.count();
|
---|
145 |
|
---|
146 | rndA_3 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
|
---|
147 | CPPUNIT_ASSERT_EQUAL( 0, rndA_3->getcount() );
|
---|
148 | CPPUNIT_ASSERT( rndA->getcount() == rndA_3->getcount() );
|
---|
149 | }
|
---|