source: src/unittests/manipulateAtomsTest.cpp@ 4c1230

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 4c1230 was 694d84, checked in by Frederik Heber <heber@…>, 14 years ago

MEMFIX: static factories map of UIFactory was not clear()'ed in destructor.

  • hence, boost::shared_ptr still had a user and have not been deleted.
  • TESTFIX: ActionSequenceTest and manipulateAtomsTest segfault.
    • the problem was the static hasDescriptor boolean. It made the dummy factory
getting registered only once, despite its being removed during UIFactory
purgeInstance() in tearDown().
  • hasDescriptor is now a member variable and set to false in tearDown().
  • Property mode set to 100644
File size: 3.8 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/*
9 * manipulateAtomsTest.cpp
10 *
11 * Created on: Feb 18, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "manipulateAtomsTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25#include <iostream>
26#include <boost/bind.hpp>
27
28#include "Descriptors/AtomDescriptor.hpp"
29#include "Descriptors/AtomIdDescriptor.hpp"
30#include "Actions/ManipulateAtomsProcess.hpp"
31#include "Actions/ActionRegistry.hpp"
32#include "Actions/ActionHistory.hpp"
33
34#include "World.hpp"
35#include "atom.hpp"
36
37#include "DummyUI.hpp"
38
39#ifdef HAVE_TESTRUNNER
40#include "UnitTestMain.hpp"
41#endif /*HAVE_TESTRUNNER*/
42
43// Registers the fixture into the 'registry'
44CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
45
46// some stubs
47class AtomStub : public atom {
48public:
49 AtomStub(int _id) :
50 atom(),
51 manipulated(false),
52 id(_id)
53 {}
54
55 virtual atomId_t getId(){
56 return id;
57 }
58
59 virtual void doSomething(){
60 manipulated = true;
61 }
62
63 bool manipulated;
64private:
65 atomId_t id;
66};
67
68class countObserver : public Observer{
69public:
70 countObserver() :
71 Observer("countObserver"),
72 count(0)
73 {}
74 virtual ~countObserver(){}
75
76 void update(Observable *){
77 count++;
78 }
79
80 void subjectKilled(Observable *)
81 {}
82
83 int count;
84};
85
86// set up and tear down
87void manipulateAtomsTest::setUp(){
88 hasDescriptor = false;
89 ActionHistory::init();
90 World::getInstance();
91 // TODO: find a way to really reset the factory to a clean state in tear-down
92 if(!hasDescriptor){
93 UIFactory::registerFactory(new DummyUIFactory::description());
94 hasDescriptor = true;
95 }
96 UIFactory::makeUserInterface("Dummy");
97 for(int i=0;i<ATOM_COUNT;++i){
98 atoms[i]= new AtomStub(i);
99 World::getInstance().registerAtom(atoms[i]);
100 }
101}
102void manipulateAtomsTest::tearDown(){
103 World::purgeInstance();
104 ActionRegistry::purgeInstance();
105 ActionHistory::purgeInstance();
106 {
107 UIFactory::purgeInstance();
108 hasDescriptor = false;
109 }
110}
111
112static void operation(atom* _atom){
113 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
114 CPPUNIT_ASSERT(atom);
115 atom->doSomething();
116}
117
118
119void manipulateAtomsTest::testManipulateSimple(){
120 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
121 proc->call();
122 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
123 std::vector<atom*>::iterator iter;
124 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
125 AtomStub *atom;
126 atom = dynamic_cast<AtomStub*>(*iter);
127 CPPUNIT_ASSERT(atom);
128 CPPUNIT_ASSERT(atom->manipulated);
129 }
130}
131
132void manipulateAtomsTest::testManipulateExcluded(){
133
134 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
135 proc->call();
136 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
137 std::vector<atom*>::iterator iter;
138 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
139 AtomStub *atom;
140 atom = dynamic_cast<AtomStub*>(*iter);
141 CPPUNIT_ASSERT(atom);
142 if(atom->getId()!=(int)ATOM_COUNT/2)
143 CPPUNIT_ASSERT(atom->manipulated);
144 else
145 CPPUNIT_ASSERT(!atom->manipulated);
146 }
147}
148
149void manipulateAtomsTest::testObserver(){
150 countObserver *obs = new countObserver();
151 World::getInstance().signOn(obs);
152 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
153 proc->call();
154
155 CPPUNIT_ASSERT_EQUAL(1,obs->count);
156 World::getInstance().signOff(obs);
157 delete obs;
158}
Note: See TracBrowser for help on using the repository browser.