source: src/Actions/unittests/ActionSequenceUnitTest.cpp@ 5ca6b5

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 5ca6b5 was 5ca6b5, checked in by Michael Ankele <ankele@…>, 12 years ago

drop deprecated references to ValueStorage

  • Property mode set to 100644
File size: 7.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ActionSequenceUnitTest.cpp
10 *
11 * Created on: Dec 17, 2009
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include "ActionSequenceUnitTest.hpp"
25#include "Actions/Action.hpp"
26#include "Actions/ActionSequence.hpp"
27#include "Actions/MakroAction.hpp"
28#include "Actions/ActionHistory.hpp"
29#include "Actions/ActionRegistry.hpp"
30
31#include "stubs/DummyUI.hpp"
32
33using namespace MoleCuilder;
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39/********************************************** Test classes **************************************/
40
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:
48 canUndoActionStub(const ActionTrait &_trait):
49 Action(_trait,false){}
50 virtual ~canUndoActionStub(){}
51
52 virtual Dialog* fillDialog(Dialog *dialog){
53 ASSERT(dialog,"No Dialog given when filling action dialog");
54 return dialog;
55 }
56
57 virtual Action::state_ptr performCall(){
58 return Action::success;
59 }
60 virtual Action::state_ptr performUndo(Action::state_ptr){
61 return Action::success;
62 }
63 virtual Action::state_ptr performRedo(Action::state_ptr){
64 return Action::success;
65 }
66 virtual bool canUndo(){
67 return true;
68 }
69 virtual bool shouldUndo(){
70 return true;
71 }
72};
73
74class cannotUndoActionStub : public Action
75{
76public:
77 cannotUndoActionStub(const ActionTrait &_trait) :
78 Action(_trait,false){}
79 virtual ~cannotUndoActionStub(){}
80
81 virtual Dialog* fillDialog(Dialog *dialog){
82 ASSERT(dialog,"No Dialog given when filling action dialog");
83 return dialog;
84 }
85
86 virtual Action::state_ptr performCall(){
87 return Action::success;
88 }
89 virtual Action::state_ptr performUndo(Action::state_ptr){
90 return Action::success;
91 }
92 virtual Action::state_ptr performRedo(Action::state_ptr){
93 return Action::success;
94 }
95 virtual bool canUndo(){
96 return false;
97 }
98 virtual bool shouldUndo(){
99 return true;
100 }
101};
102
103class wasCalledActionStub : public Action
104{
105public:
106 wasCalledActionStub(const ActionTrait &_trait) :
107 Action(_trait,false),
108 called(false)
109 {}
110 virtual ~wasCalledActionStub(){}
111
112 virtual Dialog* fillDialog(Dialog *dialog){
113 return dialog;
114 }
115 virtual Action::state_ptr performCall(){
116 called = true;
117 return Action::success;
118 }
119 virtual Action::state_ptr performUndo(Action::state_ptr){
120 called = false;
121 return Action::success;
122 }
123 virtual Action::state_ptr performRedo(Action::state_ptr){
124 called = true;
125 return Action::success;
126 }
127 virtual bool canUndo(){
128 return true;
129 }
130 virtual bool shouldUndo(){
131 return true;
132 }
133 bool wasCalled(){
134 return called;
135 }
136private:
137 bool called;
138};
139
140void ActionSequenceTest::setUp(){
141 hasDescriptor = false;
142 ActionHistory::init();
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");
149 // create some necessary stubs used in this test
150 ActionTrait canUndoTrait("canUndoActionStub");
151 ActionTrait cannotUndoTrait("cannotUndoActionStub");
152 positive1 = new canUndoActionStub(canUndoTrait);
153 positive2 = new canUndoActionStub(canUndoTrait);
154 negative1 = new cannotUndoActionStub(cannotUndoTrait);
155 negative2 = new cannotUndoActionStub(cannotUndoTrait);
156
157 ActionTrait wasCalledTrait("wasCalledActionStub");
158 shouldCall1 = new wasCalledActionStub(wasCalledTrait);
159 shouldCall2 = new wasCalledActionStub(wasCalledTrait);
160 shouldNotCall1 = new wasCalledActionStub(wasCalledTrait);
161 shouldNotCall2 = new wasCalledActionStub(wasCalledTrait);
162
163}
164
165void ActionSequenceTest::tearDown(){
166 delete positive1;
167 delete positive2;
168 delete negative1;
169 delete negative2;
170
171 delete shouldCall1;
172 delete shouldCall2;
173 delete shouldNotCall1;
174 delete shouldNotCall2;
175
176 ActionHistory::purgeInstance();
177 ActionRegistry::purgeInstance();
178 {
179 UIFactory::purgeInstance();
180 hasDescriptor = false;
181 }
182}
183
184void ActionSequenceTest::canUndoTest(){
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 }
234}
235
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
252 delete sequence;
253}
254
255void ActionSequenceTest::doesUndoTest(){
256 ActionSequence *sequence = new ActionSequence();
257 ActionTrait wasCalledTrait("wasCalledActionStub");
258 wasCalledActionStub *wasCalled1 = new wasCalledActionStub(wasCalledTrait);
259 wasCalledActionStub *wasCalled2 = new wasCalledActionStub(wasCalledTrait);
260 sequence->addAction(wasCalled1);
261 sequence->addAction(wasCalled2);
262
263 ActionTrait MakroTrait("Test MakroAction");
264 MakroAction act(MakroTrait,sequence,false);
265
266 act.call();
267
268 CPPUNIT_ASSERT_EQUAL(true,wasCalled1->wasCalled());
269 CPPUNIT_ASSERT_EQUAL(true,wasCalled2->wasCalled());
270
271 ActionHistory::getInstance().undoLast();
272
273 CPPUNIT_ASSERT_EQUAL(false,wasCalled1->wasCalled());
274 CPPUNIT_ASSERT_EQUAL(false,wasCalled2->wasCalled());
275
276}
277
278
Note: See TracBrowser for help on using the repository browser.