source: ThirdParty/CodePatterns/src/Patterns/unittests/CloneUnitTest.cpp@ 41e8e2

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 41e8e2 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.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 * CloneUnitTest.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 "CloneUnitTest.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/Clone.hpp"
27#include "stubs/CloneStub.hpp"
28
29#include <typeinfo>
30
31#ifdef HAVE_TESTRUNNER
32#include "UnitTestMain.hpp"
33#endif /*HAVE_TESTRUNNER*/
34
35/********************************************** Test classes **************************************/
36
37// Registers the fixture into the 'registry'
38CPPUNIT_TEST_SUITE_REGISTRATION( CloneTest );
39
40
41void CloneTest::setUp()
42{
43 ip1 = &p1;
44 CPPUNIT_ASSERT( ip1 == &p1 );
45 ip2 = &p2;
46 CPPUNIT_ASSERT( ip2 == &p2 );
47
48 ip1_1 = NULL;
49 ip1_2 = NULL;
50 ip2_1 = NULL;
51 ip2_2 = NULL;
52}
53
54void CloneTest::tearDown()
55{
56 // NULL pointer may be deleted.
57 delete ip1_1;
58 delete ip1_2;
59 delete ip2_1;
60 delete ip2_2;
61}
62
63void CloneTest::CreationTest()
64{
65 // test that new instances have been created.
66 ip1_1 = p1.clone();
67 ip1_2 = p1.clone();
68 CPPUNIT_ASSERT( ip1 != ip1_1 );
69 CPPUNIT_ASSERT( ip1 != ip1_2 );
70
71 ip2_1 = p2.clone();
72 ip2_2 = p2.clone();
73 CPPUNIT_ASSERT( ip2 != ip2_1 );
74 CPPUNIT_ASSERT( ip2 != ip2_2 );
75}
76
77void CloneTest::IndividualityTest()
78{
79 CPPUNIT_ASSERT( typeid(p1).name() != typeid(p2).name() );
80 p1.count();
81 p2.count();
82 p2.count();
83
84 // make refs to interface
85 ip1 = &p1;
86 CPPUNIT_ASSERT( ip1 == &p1 );
87 ip2 = &p2;
88 CPPUNIT_ASSERT( ip2 == &p2 );
89
90 // clone (i.e. counter = p?.counter ), ...
91 ip1_1 = p1.clone();
92 ip1_2 = p1.clone();
93 ip2_1 = p2.clone();
94 ip2_2 = p2.clone();
95
96 // check that each is individual
97 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_1->getcount() );
98 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_2->getcount() );
99 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_1->getcount() );
100 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_2->getcount() );
101
102 // increase individual counters and check against others
103 ip1_1->count();
104 CPPUNIT_ASSERT( ip1->getcount() != ip1_1->getcount() );
105 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
106 CPPUNIT_ASSERT( ip1->getcount() == ip1_2->getcount() );
107
108 ip1_2->count();
109 CPPUNIT_ASSERT( ip1_1->getcount() == ip1_2->getcount() );
110 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
111
112 ip1_2->count();
113 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
114 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
115}
Note: See TracBrowser for help on using the repository browser.