source: src/Patterns/unittests/CreatorUnitTest.cpp@ 567640

Last change on this file since 567640 was 724564, checked in by Frederik Heber <heber@…>, 15 years ago

Factory know has an additional type table and stubs have been refactored.

  • CommonStub.?pp contains basic classes with a int counter inside.
  • Library version is now 2:1:0, API is 1.0.3.
  • Property mode set to 100644
File size: 4.7 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 * 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
24#include "Assert.hpp"
25
26#include "Creator.hpp"
27#include "stubs/CommonStub.hpp"
28#include "stubs/CreatorStub.hpp"
29
30#include <boost/nondet_random.hpp>
31#include <boost/random.hpp>
32#include <boost/random/additive_combine.hpp>
33#include <boost/random/discard_block.hpp>
34#include <boost/random/inversive_congruential.hpp>
35#include <boost/random/lagged_fibonacci.hpp>
36#include <boost/random/linear_congruential.hpp>
37#include <boost/random/linear_feedback_shift.hpp>
38#include <boost/random/mersenne_twister.hpp>
39#include <boost/random/random_number_generator.hpp>
40#include <boost/random/ranlux.hpp>
41#include <boost/random/shuffle_output.hpp>
42#include <boost/random/subtract_with_carry.hpp>
43#include <boost/random/xor_combine.hpp>
44#include <boost/random/bernoulli_distribution.hpp>
45#include <boost/random/binomial_distribution.hpp>
46#include <boost/random/cauchy_distribution.hpp>
47#include <boost/random/exponential_distribution.hpp>
48#include <boost/random/gamma_distribution.hpp>
49#include <boost/random/geometric_distribution.hpp>
50#include <boost/random/linear_congruential.hpp>
51#include <boost/random/lognormal_distribution.hpp>
52#include <boost/random/normal_distribution.hpp>
53#include <boost/random/poisson_distribution.hpp>
54#include <boost/random/triangle_distribution.hpp>
55#include <boost/random/uniform_01.hpp>
56#include <boost/random/uniform_int.hpp>
57#include <boost/random/uniform_on_sphere.hpp>
58#include <boost/random/uniform_real.hpp>
59#include <boost/random/uniform_smallint.hpp>
60
61#include <typeinfo>
62
63#ifdef HAVE_TESTRUNNER
64#include "UnitTestMain.hpp"
65#endif /*HAVE_TESTRUNNER*/
66
67/********************************************** Test classes **************************************/
68
69// Registers the fixture into the 'registry'
70CPPUNIT_TEST_SUITE_REGISTRATION( CreatorTest );
71
72
73void CreatorTest::setUp()
74{
75}
76
77void CreatorTest::tearDown()
78{
79}
80
81void CreatorTest::CreationTest()
82{
83 class CreatorStub<teststubs::Aclass> teststubA;
84 class CreatorStub<teststubs::Bclass> teststubB;
85
86 ICreatorStub* testingA1 = teststubA.create();
87 ICreatorStub* testingA2 = teststubA.create();
88 ICreatorStub* testingB = teststubB.create();
89
90 // instance is different
91 CPPUNIT_ASSERT( &teststubA != testingA1 );
92 CPPUNIT_ASSERT( &teststubA != testingA2 );
93 CPPUNIT_ASSERT( testingA1 != testingA2 );
94 CPPUNIT_ASSERT( &teststubB != testingB );
95
96 // type is the same ...
97 CPPUNIT_ASSERT_EQUAL( typeid(teststubA).name(), typeid(*testingA1).name() );
98 CPPUNIT_ASSERT_EQUAL( typeid(*testingA1).name(), typeid(*testingA2).name() );
99 CPPUNIT_ASSERT_EQUAL( typeid(teststubB).name(), typeid(*testingB).name() );
100
101 // ... for the same particular type only!
102 // (RTTI knows about the true complex type!)
103 CPPUNIT_ASSERT( typeid(*testingB).name() != typeid(*testingA1).name() );
104 CPPUNIT_ASSERT( typeid(*testingB).name() != typeid(*testingA2).name() );
105
106 // but not for different encapsulated types
107 CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB).name() );
108 CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA1).name() );
109 CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA2).name() );
110
111 delete testingA1;
112 delete testingA2;
113 delete testingB;
114}
115
116void CreatorTest::IndividualityTest()
117{
118 class CreatorStub<teststubs::Aclass> teststubA;
119 class CreatorStub<teststubs::Bclass> teststubB;
120 teststubA.count();
121 teststubB.count();
122 teststubB.count();
123
124 ICreatorStub* testingA1 = teststubA.create();
125 ICreatorStub* testingA2 = teststubA.create();
126 ICreatorStub* testingB1 = teststubB.create();
127 ICreatorStub* testingB2 = teststubB.create();
128
129 // content is the same (prototype has been copied)
130 CPPUNIT_ASSERT( teststubA.getcount() != testingA1->getcount());
131 CPPUNIT_ASSERT( teststubA.getcount() != testingA2->getcount());
132 CPPUNIT_ASSERT( teststubB.getcount() != testingB1->getcount());
133 CPPUNIT_ASSERT( teststubB.getcount() != testingB2->getcount());
134
135 // but each copy is independent
136 testingA1->count();
137 CPPUNIT_ASSERT( testingA1->getcount() != testingA2->getcount());
138 testingB1->count();
139 testingB2->count();
140 testingB2->count();
141 CPPUNIT_ASSERT( testingB1->getcount() != testingB2->getcount());
142
143 delete testingA1;
144 delete testingA2;
145 delete testingB1;
146 delete testingB2;
147}
Note: See TracBrowser for help on using the repository browser.