source: src/unittests/ActionSequenceTest.cpp@ d56640

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 d56640 was 5b0b98, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Switched type of pointer used for ActionStates

  • Property mode set to 100644
File size: 5.8 KB
Line 
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
16#ifdef HAVE_TESTRUNNER
17#include "UnitTestMain.hpp"
18#endif /*HAVE_TESTRUNNER*/
19
20/********************************************** Test classes **************************************/
21
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:
34 canUndoActionStub(): Action("canUndoActionStub",false){}
35 virtual ~canUndoActionStub(){}
36
37 virtual Action::state_ptr performCall(){
38 return Action::success;
39 }
40 virtual Action::state_ptr performUndo(Action::state_ptr){
41 return Action::success;
42 }
43 virtual Action::state_ptr performRedo(Action::state_ptr){
44 return Action::success;
45 }
46 virtual bool canUndo(){
47 return true;
48 }
49 virtual bool shouldUndo(){
50 return true;
51 }
52};
53
54class cannotUndoActionStub : public Action
55{
56public:
57 cannotUndoActionStub() : Action("cannotUndoActionStub",false){}
58 virtual ~cannotUndoActionStub(){}
59
60 virtual Action::state_ptr performCall(){
61 return Action::success;
62 }
63 virtual Action::state_ptr performUndo(Action::state_ptr){
64 return Action::success;
65 }
66 virtual Action::state_ptr performRedo(Action::state_ptr){
67 return Action::success;
68 }
69 virtual bool canUndo(){
70 return false;
71 }
72 virtual bool shouldUndo(){
73 return true;
74 }
75};
76
77class wasCalledActionStub : public Action
78{
79public:
80 wasCalledActionStub() :
81 Action("wasCalledActionStub",false),
82 called(false)
83 {}
84 virtual ~wasCalledActionStub(){}
85
86 virtual Action::state_ptr performCall(){
87 called = true;
88 return Action::success;
89 }
90 virtual Action::state_ptr performUndo(Action::state_ptr){
91 called = false;
92 return Action::success;
93 }
94 virtual Action::state_ptr performRedo(Action::state_ptr){
95 called = true;
96 return Action::success;
97 }
98 virtual bool canUndo(){
99 return true;
100 }
101 virtual bool shouldUndo(){
102 return true;
103 }
104 bool wasCalled(){
105 return called;
106 }
107private:
108 bool called;
109};
110
111void ActionSequenceTest::setUp(){
112 // create some necessary stubs used in this test
113 positive1 = new canUndoActionStub();
114 positive2 = new canUndoActionStub();
115 negative1 = new cannotUndoActionStub();
116 negative2 = new cannotUndoActionStub();
117
118 shouldCall1 = new wasCalledActionStub();
119 shouldCall2 = new wasCalledActionStub();
120 shouldNotCall1 = new wasCalledActionStub();
121 shouldNotCall2 = new wasCalledActionStub();
122
123}
124
125void ActionSequenceTest::tearDown(){
126 delete positive1;
127 delete positive2;
128 delete negative1;
129 delete negative2;
130
131 delete shouldCall1;
132 delete shouldCall2;
133 delete shouldNotCall1;
134 delete shouldNotCall2;
135
136}
137
138void ActionSequenceTest::canUndoTest(){
139 // first section:
140 {
141 // test some combinations
142 {
143 ActionSequence *sequence = new ActionSequence();
144 sequence->addAction(positive1);
145 sequence->addAction(positive2);
146 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
147 delete sequence;
148 }
149 {
150 ActionSequence *sequence = new ActionSequence();
151 sequence->addAction(positive1);
152 sequence->addAction(negative2);
153 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
154 delete sequence;
155 }
156 {
157 ActionSequence *sequence = new ActionSequence();
158 sequence->addAction(negative1);
159 sequence->addAction(positive2);
160 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
161 delete sequence;
162 }
163 {
164 ActionSequence *sequence = new ActionSequence();
165 sequence->addAction(negative1);
166 sequence->addAction(negative2);
167 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
168 delete sequence;
169 }
170 }
171
172 // second section:
173 {
174 // empty sequence can be undone
175 ActionSequence *sequence = new ActionSequence();
176 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
177 // if only a positive action is contained it can be undone
178 sequence->addAction(positive1);
179 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
180 // the single negative action should block the process
181 sequence->addAction(negative1);
182 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
183 // after removing the negative action all is well again
184 sequence->removeLastAction();
185 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
186 delete sequence;
187 }
188}
189
190void ActionSequenceTest::doesCallTest(){
191 ActionSequence *sequence = new ActionSequence();
192 sequence->addAction(shouldCall1);
193 sequence->addAction(shouldCall2);
194 sequence->addAction(shouldNotCall1);
195 sequence->addAction(shouldNotCall2);
196 sequence->removeLastAction();
197 sequence->removeLastAction();
198
199 sequence->callAll();
200
201 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
202 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
203 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
204 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
205
206 delete sequence;
207}
208
209void ActionSequenceTest::doesUndoTest(){
210 ActionSequence *sequence = new ActionSequence();
211 sequence->addAction(shouldNotCall1);
212 sequence->addAction(shouldNotCall2);
213 sequence->addAction(shouldCall1);
214 sequence->addAction(shouldCall2);
215
216 ActionSequence::stateSet states = sequence->callAll();
217
218 sequence->removeLastAction();
219 sequence->removeLastAction();
220
221 sequence->undoAll(states);
222
223 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
224 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
225 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
226 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
227
228 delete sequence;
229}
230
231
Note: See TracBrowser for help on using the repository browser.