source: ThirdParty/CodePatterns/src/Patterns/unittests/ManipulableCloneUnitTest.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: 3.2 KB
RevLine 
[084729c]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 * ManipulableCloneUnitTest.cpp
9 *
10 * Created on: Jan 06, 2011
11 * Author: heber
12 */
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "ManipulableCloneUnitTest.hpp"
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include "CodePatterns/Assert.hpp"
25
26#include "CodePatterns/ManipulableClone.hpp"
27#include "stubs/ManipulableCloneStub.hpp"
28#include "stubs/CommonParametersStub.hpp"
29
30#include <typeinfo>
31
32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36/********************************************** Test classes **************************************/
37
38// Registers the fixture into the 'registry'
39CPPUNIT_TEST_SUITE_REGISTRATION( ManipulableCloneTest );
40
41
42void ManipulableCloneTest::setUp()
43{
44 ip1 = &p1;
45 CPPUNIT_ASSERT( ip1 == &p1 );
46 ip2 = &p2;
47 CPPUNIT_ASSERT( ip2 == &p2 );
48
49 ip1_1 = NULL;
50 ip1_2 = NULL;
51 ip2_1 = NULL;
52 ip2_2 = NULL;
53}
54
55void ManipulableCloneTest::tearDown()
56{
57 // NULL pointer may be deleted.
58 delete ip1_1;
59 delete ip1_2;
60 delete ip2_1;
61 delete ip2_2;
62}
63
64void ManipulableCloneTest::CreationTest()
65{
66 // test that new instances have been created.
67 ip1_1 = p1.clone();
68 ip1_2 = p1.clone();
69 CPPUNIT_ASSERT( ip1 != ip1_1 );
70 CPPUNIT_ASSERT( ip1 != ip1_2 );
71
72 ip2_1 = p2.clone();
73 ip2_2 = p2.clone();
74 CPPUNIT_ASSERT( ip2 != ip2_1 );
75 CPPUNIT_ASSERT( ip2 != ip2_2 );
76}
77
78void ManipulableCloneTest::IndividualityTest()
79{
80 CPPUNIT_ASSERT( typeid(p1).name() != typeid(p2).name() );
81 p1.count();
82 p2.count();
83 p2.count();
84
85 // make refs to interface
86 ip1 = &p1;
87 CPPUNIT_ASSERT( ip1 == &p1 );
88 ip2 = &p2;
89 CPPUNIT_ASSERT( ip2 == &p2 );
90
91 // clone (i.e. counter = p?.counter ), ...
92 ip1_1 = p1.clone();
93 ip1_2 = p1.clone();
94 ip2_1 = p2.clone();
95 ip2_2 = p2.clone();
96
97 // check that each is individual
98 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_1->getcount() );
99 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_2->getcount() );
100 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_1->getcount() );
101 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_2->getcount() );
102
103 // increase individual counters and check against others
104 ip1_1->count();
105 CPPUNIT_ASSERT( ip1->getcount() != ip1_1->getcount() );
106 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
107 CPPUNIT_ASSERT( ip1->getcount() == ip1_2->getcount() );
108
109 ip1_2->count();
110 CPPUNIT_ASSERT( ip1_1->getcount() == ip1_2->getcount() );
111 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
112
113 ip1_2->count();
114 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
115 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
116}
117
118void ManipulableCloneTest::ManipulationTest()
119{
120 ip1_1 = p1.clone();
121 CPPUNIT_ASSERT_EQUAL( 0, ip1_1->getcount() );
122 teststubs::classParameters params;
123 params.counter= 100;
124 ip1_2 = p1.manipulatedclone(params);
125 CPPUNIT_ASSERT_EQUAL( 100, ip1_2->getcount() );
126
127 ip2_1 = p2.clone();
128 CPPUNIT_ASSERT_EQUAL( 0, ip2_1->getcount() );
129
130 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
131}
Note: See TracBrowser for help on using the repository browser.