source: src/unittests/ActionSequenceTest.cpp@ 81a9bc

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * ActionSequenzTest.cpp
3 *
4 * Created on: Dec 17, 2009
5 * Author: crueger
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <cppunit/CompilerOutputter.h>
14#include <cppunit/extensions/TestFactoryRegistry.h>
15#include <cppunit/ui/text/TestRunner.h>
16
17#include "unittests/ActionSequenceTest.hpp"
18#include "Actions/Action.hpp"
19#include "Actions/ActionSequence.hpp"
20#include "Actions/MakroAction.hpp"
21#include "Actions/ActionHistory.hpp"
22#include "Actions/ActionRegistry.hpp"
23
24#include "DummyUI.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( ActionSequenceTest );
34
35/* some neccessary stubs for tests */
36class canUndoActionStub : public Action
37{
38public:
39 canUndoActionStub(): Action("canUndoActionStub",false){}
40 virtual ~canUndoActionStub(){}
41
42 virtual Dialog* fillDialog(Dialog *dialog){
43 ASSERT(dialog,"No Dialog given when filling action dialog");
44 return dialog;
45 }
46
47 virtual Action::state_ptr performCall(){
48 return Action::success;
49 }
50 virtual Action::state_ptr performUndo(Action::state_ptr){
51 return Action::success;
52 }
53 virtual Action::state_ptr performRedo(Action::state_ptr){
54 return Action::success;
55 }
56 virtual bool canUndo(){
57 return true;
58 }
59 virtual bool shouldUndo(){
60 return true;
61 }
62};
63
64class cannotUndoActionStub : public Action
65{
66public:
67 cannotUndoActionStub() : Action("cannotUndoActionStub",false){}
68 virtual ~cannotUndoActionStub(){}
69
70 virtual Dialog* fillDialog(Dialog *dialog){
71 ASSERT(dialog,"No Dialog given when filling action dialog");
72 return dialog;
73 }
74
75 virtual Action::state_ptr performCall(){
76 return Action::success;
77 }
78 virtual Action::state_ptr performUndo(Action::state_ptr){
79 return Action::success;
80 }
81 virtual Action::state_ptr performRedo(Action::state_ptr){
82 return Action::success;
83 }
84 virtual bool canUndo(){
85 return false;
86 }
87 virtual bool shouldUndo(){
88 return true;
89 }
90};
91
92class wasCalledActionStub : public Action
93{
94public:
95 wasCalledActionStub() :
96 Action("wasCalledActionStub",false),
97 called(false)
98 {}
99 virtual ~wasCalledActionStub(){}
100
101 virtual Dialog* fillDialog(Dialog *dialog){
102 return dialog;
103 }
104 virtual Action::state_ptr performCall(){
105 called = true;
106 return Action::success;
107 }
108 virtual Action::state_ptr performUndo(Action::state_ptr){
109 called = false;
110 return Action::success;
111 }
112 virtual Action::state_ptr performRedo(Action::state_ptr){
113 called = true;
114 return Action::success;
115 }
116 virtual bool canUndo(){
117 return true;
118 }
119 virtual bool shouldUndo(){
120 return true;
121 }
122 bool wasCalled(){
123 return called;
124 }
125private:
126 bool called;
127};
128
129void ActionSequenceTest::setUp(){
130 static bool hasDescriptor = false;
131 ActionHistory::init();
132 // TODO: find a way to really reset the factory to a clean state in tear-down
133 if(!hasDescriptor){
134 UIFactory::registerFactory(new DummyUIFactory::description());
135 hasDescriptor = true;
136 }
137 UIFactory::makeUserInterface("Dummy");
138 // create some necessary stubs used in this test
139 positive1 = new canUndoActionStub();
140 positive2 = new canUndoActionStub();
141 negative1 = new cannotUndoActionStub();
142 negative2 = new cannotUndoActionStub();
143
144 shouldCall1 = new wasCalledActionStub();
145 shouldCall2 = new wasCalledActionStub();
146 shouldNotCall1 = new wasCalledActionStub();
147 shouldNotCall2 = new wasCalledActionStub();
148
149}
150
151void ActionSequenceTest::tearDown(){
152 delete positive1;
153 delete positive2;
154 delete negative1;
155 delete negative2;
156
157 delete shouldCall1;
158 delete shouldCall2;
159 delete shouldNotCall1;
160 delete shouldNotCall2;
161
162 ActionHistory::purgeInstance();
163 ActionRegistry::purgeInstance();
164 UIFactory::purgeInstance();
165}
166
167void ActionSequenceTest::canUndoTest(){
168 // first section:
169 {
170 // test some combinations
171 {
172 ActionSequence *sequence = new ActionSequence();
173 sequence->addAction(positive1);
174 sequence->addAction(positive2);
175 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
176 delete sequence;
177 }
178 {
179 ActionSequence *sequence = new ActionSequence();
180 sequence->addAction(positive1);
181 sequence->addAction(negative2);
182 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
183 delete sequence;
184 }
185 {
186 ActionSequence *sequence = new ActionSequence();
187 sequence->addAction(negative1);
188 sequence->addAction(positive2);
189 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
190 delete sequence;
191 }
192 {
193 ActionSequence *sequence = new ActionSequence();
194 sequence->addAction(negative1);
195 sequence->addAction(negative2);
196 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
197 delete sequence;
198 }
199 }
200
201 // second section:
202 {
203 // empty sequence can be undone
204 ActionSequence *sequence = new ActionSequence();
205 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
206 // if only a positive action is contained it can be undone
207 sequence->addAction(positive1);
208 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
209 // the single negative action should block the process
210 sequence->addAction(negative1);
211 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
212 // after removing the negative action all is well again
213 sequence->removeLastAction();
214 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
215 delete sequence;
216 }
217}
218
219void ActionSequenceTest::doesCallTest(){
220 ActionSequence *sequence = new ActionSequence();
221 sequence->addAction(shouldCall1);
222 sequence->addAction(shouldCall2);
223 sequence->addAction(shouldNotCall1);
224 sequence->addAction(shouldNotCall2);
225 sequence->removeLastAction();
226 sequence->removeLastAction();
227
228 sequence->callAll();
229
230 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
231 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
232 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
233 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
234
235 delete sequence;
236}
237
238void ActionSequenceTest::doesUndoTest(){
239 ActionSequence *sequence = new ActionSequence();
240 wasCalledActionStub *wasCalled1 = new wasCalledActionStub();
241 wasCalledActionStub *wasCalled2 = new wasCalledActionStub();
242 sequence->addAction(wasCalled1);
243 sequence->addAction(wasCalled2);
244
245 MakroAction act("Test MakroAction",sequence,false);
246
247 act.call();
248
249 CPPUNIT_ASSERT_EQUAL(true,wasCalled1->wasCalled());
250 CPPUNIT_ASSERT_EQUAL(true,wasCalled2->wasCalled());
251
252 ActionHistory::getInstance().undoLast();
253
254 CPPUNIT_ASSERT_EQUAL(false,wasCalled1->wasCalled());
255 CPPUNIT_ASSERT_EQUAL(false,wasCalled2->wasCalled());
256
257}
258
259
Note: See TracBrowser for help on using the repository browser.