source: src/unittests/ActionSequenceTest.cpp@ 521bbf

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

Fixed all remaining Action's and derived classes that lacked createDialog().

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