source: src/unittests/ActionSequenceTest.cpp@ 88b400

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 88b400 was ec149d, checked in by Frederik Heber <heber@…>, 14 years ago

BUGFIX: ActionSequenceTest::doesUndoTest() had typo, used wasCalled1 twice instead of wasCalled2.

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