source: src/Actions/unittests/ActionSequenceUnitTest.cpp@ 852ea3

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 Candidate_v1.7.0 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 852ea3 was 5ca6b5, checked in by Michael Ankele <ankele@…>, 13 years ago

drop deprecated references to ValueStorage

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