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 | * FactoryUnitTest.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 "FactoryUnitTest.hpp"
|
---|
23 |
|
---|
24 | #include "stubs/CommonStub.hpp"
|
---|
25 | #include "stubs/FactoryStub.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( FactoryTest );
|
---|
37 |
|
---|
38 | void FactoryTest::setUp()
|
---|
39 | {
|
---|
40 | rndA =
|
---|
41 | FactoryStub::getInstance().
|
---|
42 | PrototypeTable[FactoryStub::Aclass]->create();
|
---|
43 | rndB =
|
---|
44 | FactoryStub::getInstance().
|
---|
45 | PrototypeTable[FactoryStub::Bclass]->create();
|
---|
46 | rndA_1 = NULL;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void FactoryTest::tearDown()
|
---|
50 | {
|
---|
51 | delete rndA;
|
---|
52 | delete rndB;
|
---|
53 | delete rndA_1;
|
---|
54 | FactoryStub::purgeInstance();
|
---|
55 | }
|
---|
56 |
|
---|
57 | void FactoryTest::DistributionTest()
|
---|
58 | {
|
---|
59 | // check the injectiveness of enum and string map
|
---|
60 | for (FactoryStub::NameMap::const_iterator
|
---|
61 | iter = FactoryStub::getInstance().names.begin();
|
---|
62 | iter != FactoryStub::getInstance().names.end();
|
---|
63 | ++iter) {
|
---|
64 | CPPUNIT_ASSERT_EQUAL(
|
---|
65 | iter->second,
|
---|
66 | FactoryStub::getInstance().getName(
|
---|
67 | FactoryStub::getInstance().getEnum(
|
---|
68 | iter->second
|
---|
69 | )
|
---|
70 | )
|
---|
71 | );
|
---|
72 | }
|
---|
73 |
|
---|
74 | // check distributions in the table
|
---|
75 | CPPUNIT_ASSERT_EQUAL(
|
---|
76 | std::string(typeid(teststubs::Aclass).name()),
|
---|
77 | rndA->name()
|
---|
78 | );
|
---|
79 | CPPUNIT_ASSERT_EQUAL(
|
---|
80 | std::string(typeid(teststubs::Bclass).name()),
|
---|
81 | rndB->name()
|
---|
82 | );
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | void FactoryTest::getProductEnumTest()
|
---|
87 | {
|
---|
88 | rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
|
---|
89 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
90 | }
|
---|
91 |
|
---|
92 | void FactoryTest::getProductNameTest()
|
---|
93 | {
|
---|
94 | rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass"));
|
---|
95 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
96 | }
|
---|
97 |
|
---|
98 | void FactoryTest::getProductTypeTest()
|
---|
99 | {
|
---|
100 | rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
|
---|
101 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
---|
102 | }
|
---|