source: ThirdParty/CodePatterns/src/Patterns/unittests/FactoryUnitTest.cpp

Candidate_v1.6.1
Last change on this file was 41e8e2, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '084729c5923f0123e695fbe2548b393288c1f13d' as 'ThirdParty/CodePatterns'

  • Property mode set to 100644
File size: 2.5 KB
Line 
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'
36CPPUNIT_TEST_SUITE_REGISTRATION( FactoryTest );
37
38void 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
49void FactoryTest::tearDown()
50{
51 delete rndA;
52 delete rndB;
53 delete rndA_1;
54 FactoryStub::purgeInstance();
55}
56
57void 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
86void FactoryTest::getProductEnumTest()
87{
88 rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
89 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
90}
91
92void FactoryTest::getProductNameTest()
93{
94 rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass"));
95 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
96}
97
98void FactoryTest::getProductTypeTest()
99{
100 rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
101 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
102}
Note: See TracBrowser for help on using the repository browser.