source: src/unittests/ActionSequenceTest.cpp@ f59d81

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 f59d81 was f59d81, checked in by Frederik Heber <heber@…>, 15 years ago

MEMLEAK: created ActionSequence was not deleted at the end of some tests.

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[147339]1/*
2 * ActionSequenzTest.cpp
3 *
4 * Created on: Dec 17, 2009
5 * Author: crueger
6 */
7
8#include <cppunit/CompilerOutputter.h>
9#include <cppunit/extensions/TestFactoryRegistry.h>
10#include <cppunit/ui/text/TestRunner.h>
11
12#include "unittests/ActionSequenceTest.hpp"
13#include "Actions/Action.hpp"
14#include "Actions/ActionSequence.hpp"
15
[9b6b2f]16#ifdef HAVE_TESTRUNNER
17#include "UnitTestMain.hpp"
18#endif /*HAVE_TESTRUNNER*/
19
20/********************************************** Test classes **************************************/
21
[147339]22// Registers the fixture into the 'registry'
23CPPUNIT_TEST_SUITE_REGISTRATION( ActionSequenceTest );
24
25void setUp();
26void tearDown();
27
28void canUndoTest();
29
30/* some neccessary stubs for tests */
31class canUndoActionStub : public Action
32{
33public:
[cc04b7]34 canUndoActionStub(): Action("canUndoActionStub",false){}
[147339]35 virtual ~canUndoActionStub(){}
36
37 virtual void call(){}
38 virtual void undo(){}
39 virtual bool canUndo(){
40 return true;
41 }
42};
43
44class cannotUndoActionStub : public Action
45{
46public:
[cc04b7]47 cannotUndoActionStub() : Action("cannotUndoActionStub",false){}
[147339]48 virtual ~cannotUndoActionStub(){}
49
50 virtual void call(){}
51 virtual void undo(){}
52 virtual bool canUndo(){
53 return false;
54 }
55};
56
[0229f9]57class wasCalledActionStub : public Action
58{
59public:
60 wasCalledActionStub() :
[cc04b7]61 Action("wasCalledActionStub",false),
[0229f9]62 called(false)
63 {}
64 virtual ~wasCalledActionStub(){}
[147339]65
[0229f9]66 virtual void call(){
67 called = true;
68 }
69 virtual void undo(){
70 called = false;
71 }
72 virtual bool canUndo(){
73 return true;
74 }
75 bool wasCalled(){
76 return called;
77 }
78private:
79 bool called;
80};
[147339]81
[0229f9]82void ActionSequenceTest::setUp(){
[147339]83 // create some necessary stubs used in this test
[0229f9]84 positive1 = new canUndoActionStub();
85 positive2 = new canUndoActionStub();
86 negative1 = new cannotUndoActionStub();
87 negative2 = new cannotUndoActionStub();
88
89 shouldCall1 = new wasCalledActionStub();
90 shouldCall2 = new wasCalledActionStub();
91 shouldNotCall1 = new wasCalledActionStub();
92 shouldNotCall2 = new wasCalledActionStub();
93
94}
95
96void ActionSequenceTest::tearDown(){
97 delete positive1;
98 delete positive2;
99 delete negative1;
100 delete negative2;
[147339]101
[0229f9]102 delete shouldCall1;
103 delete shouldCall2;
104 delete shouldNotCall1;
105 delete shouldNotCall2;
106
107}
108
109void ActionSequenceTest::canUndoTest(){
[147339]110 // first section:
111 {
112 // test some combinations
113 {
114 ActionSequence *sequence = new ActionSequence();
115 sequence->addAction(positive1);
116 sequence->addAction(positive2);
117 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
118 delete sequence;
119 }
120 {
121 ActionSequence *sequence = new ActionSequence();
122 sequence->addAction(positive1);
123 sequence->addAction(negative2);
124 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
125 delete sequence;
126 }
127 {
128 ActionSequence *sequence = new ActionSequence();
129 sequence->addAction(negative1);
130 sequence->addAction(positive2);
131 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
132 delete sequence;
133 }
134 {
135 ActionSequence *sequence = new ActionSequence();
136 sequence->addAction(negative1);
137 sequence->addAction(negative2);
138 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
139 delete sequence;
140 }
141 }
142
143 // second section:
144 {
145 // empty sequence can be undone
146 ActionSequence *sequence = new ActionSequence();
147 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
148 // if only a positive action is contained it can be undone
149 sequence->addAction(positive1);
150 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
151 // the single negative action should block the process
152 sequence->addAction(negative1);
153 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
154 // after removing the negative action all is well again
155 sequence->removeLastAction();
156 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
157 delete sequence;
158 }
[0229f9]159}
[147339]160
[0229f9]161void ActionSequenceTest::doesCallTest(){
162 ActionSequence *sequence = new ActionSequence();
163 sequence->addAction(shouldCall1);
164 sequence->addAction(shouldCall2);
165 sequence->addAction(shouldNotCall1);
166 sequence->addAction(shouldNotCall2);
167 sequence->removeLastAction();
168 sequence->removeLastAction();
169
170 sequence->callAll();
171
172 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
173 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
174 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
175 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
176
[f59d81]177 delete sequence;
[0229f9]178}
179
180void ActionSequenceTest::doesUndoTest(){
181 ActionSequence *sequence = new ActionSequence();
182 sequence->addAction(shouldNotCall1);
183 sequence->addAction(shouldNotCall2);
184 sequence->addAction(shouldCall1);
185 sequence->addAction(shouldCall2);
186
187 sequence->callAll();
188
189 sequence->removeLastAction();
190 sequence->removeLastAction();
191
192 sequence->undoAll();
193
194 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
195 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
196 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
197 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
[147339]198
[f59d81]199 delete sequence;
[147339]200}
201
202
Note: See TracBrowser for help on using the repository browser.