source: src/Actions/unittests/ActionSequenceUnitTest.cpp@ 87d6bd

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 87d6bd was 22b786, checked in by Frederik Heber <heber@…>, 12 years ago

Made SubgraphDissection a MakroAction and added UpdateMoleculesAction.

  • MakroAction does not delete the ActionSequence eventually and it now obtains just a ref, not pointer.
  • TESTFIX: Changed ActionSequenceUnitTest::doesUndoTest() accordingly.
  • SubgraphDissection is right now still very ugly with lots of copy&paste from the preprocessor header files to get every function in place.
  • it could be made into a MakroAction because all three internal Actions do not require any options. How to achieve this with options is unsolved.
  • Property mode set to 100644
File size: 8.0 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * ActionSequenceUnitTest.cpp
25 *
26 * Created on: Dec 17, 2009
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include "ActionSequenceUnitTest.hpp"
40#include "Actions/Action.hpp"
41#include "Actions/ActionSequence.hpp"
42#include "Actions/MakroAction.hpp"
43#include "Actions/ActionHistory.hpp"
44#include "Actions/ActionRegistry.hpp"
45
46#include "stubs/DummyUI.hpp"
47
48using namespace MoleCuilder;
49
50#ifdef HAVE_TESTRUNNER
51#include "UnitTestMain.hpp"
52#endif /*HAVE_TESTRUNNER*/
53
54/********************************************** Test classes **************************************/
55
56// Registers the fixture into the 'registry'
57CPPUNIT_TEST_SUITE_REGISTRATION( ActionSequenceTest );
58
59/* some neccessary stubs for tests */
60class canUndoActionStub : public Action
61{
62public:
63 canUndoActionStub(const ActionTrait &_trait):
64 Action(_trait,false){}
65 virtual ~canUndoActionStub(){}
66
67 virtual Dialog* fillDialog(Dialog *dialog){
68 ASSERT(dialog,"No Dialog given when filling action dialog");
69 return dialog;
70 }
71
72 virtual Action::state_ptr performCall(){
73 return Action::success;
74 }
75 virtual Action::state_ptr performUndo(Action::state_ptr){
76 return Action::success;
77 }
78 virtual Action::state_ptr performRedo(Action::state_ptr){
79 return Action::success;
80 }
81 virtual bool canUndo(){
82 return true;
83 }
84 virtual bool shouldUndo(){
85 return true;
86 }
87};
88
89class cannotUndoActionStub : public Action
90{
91public:
92 cannotUndoActionStub(const ActionTrait &_trait) :
93 Action(_trait,false){}
94 virtual ~cannotUndoActionStub(){}
95
96 virtual Dialog* fillDialog(Dialog *dialog){
97 ASSERT(dialog,"No Dialog given when filling action dialog");
98 return dialog;
99 }
100
101 virtual Action::state_ptr performCall(){
102 return Action::success;
103 }
104 virtual Action::state_ptr performUndo(Action::state_ptr){
105 return Action::success;
106 }
107 virtual Action::state_ptr performRedo(Action::state_ptr){
108 return Action::success;
109 }
110 virtual bool canUndo(){
111 return false;
112 }
113 virtual bool shouldUndo(){
114 return true;
115 }
116};
117
118class wasCalledActionStub : public Action
119{
120public:
121 wasCalledActionStub(const ActionTrait &_trait) :
122 Action(_trait,false),
123 called(false)
124 {}
125 virtual ~wasCalledActionStub(){}
126
127 virtual Dialog* fillDialog(Dialog *dialog){
128 return dialog;
129 }
130 virtual Action::state_ptr performCall(){
131 called = true;
132 return Action::success;
133 }
134 virtual Action::state_ptr performUndo(Action::state_ptr){
135 called = false;
136 return Action::success;
137 }
138 virtual Action::state_ptr performRedo(Action::state_ptr){
139 called = true;
140 return Action::success;
141 }
142 virtual bool canUndo(){
143 return true;
144 }
145 virtual bool shouldUndo(){
146 return true;
147 }
148 bool wasCalled(){
149 return called;
150 }
151private:
152 bool called;
153};
154
155void ActionSequenceTest::setUp(){
156 hasDescriptor = false;
157 ActionHistory::init();
158 // TODO: find a way to really reset the factory to a clean state in tear-down
159 if(!hasDescriptor){
160 UIFactory::registerFactory(new DummyUIFactory::description());
161 hasDescriptor = true;
162 }
163 UIFactory::makeUserInterface("Dummy");
164 // create some necessary stubs used in this test
165 ActionTrait canUndoTrait("canUndoActionStub");
166 ActionTrait cannotUndoTrait("cannotUndoActionStub");
167 positive1 = new canUndoActionStub(canUndoTrait);
168 positive2 = new canUndoActionStub(canUndoTrait);
169 negative1 = new cannotUndoActionStub(cannotUndoTrait);
170 negative2 = new cannotUndoActionStub(cannotUndoTrait);
171
172 ActionTrait wasCalledTrait("wasCalledActionStub");
173 shouldCall1 = new wasCalledActionStub(wasCalledTrait);
174 shouldCall2 = new wasCalledActionStub(wasCalledTrait);
175 shouldNotCall1 = new wasCalledActionStub(wasCalledTrait);
176 shouldNotCall2 = new wasCalledActionStub(wasCalledTrait);
177
178}
179
180void ActionSequenceTest::tearDown(){
181 delete positive1;
182 delete positive2;
183 delete negative1;
184 delete negative2;
185
186 delete shouldCall1;
187 delete shouldCall2;
188 delete shouldNotCall1;
189 delete shouldNotCall2;
190
191 ActionHistory::purgeInstance();
192 ActionRegistry::purgeInstance();
193 {
194 UIFactory::purgeInstance();
195 hasDescriptor = false;
196 }
197}
198
199void ActionSequenceTest::canUndoTest(){
200 // first section:
201 {
202 // test some combinations
203 {
204 ActionSequence *sequence = new ActionSequence();
205 sequence->addAction(positive1);
206 sequence->addAction(positive2);
207 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
208 delete sequence;
209 }
210 {
211 ActionSequence *sequence = new ActionSequence();
212 sequence->addAction(positive1);
213 sequence->addAction(negative2);
214 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
215 delete sequence;
216 }
217 {
218 ActionSequence *sequence = new ActionSequence();
219 sequence->addAction(negative1);
220 sequence->addAction(positive2);
221 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
222 delete sequence;
223 }
224 {
225 ActionSequence *sequence = new ActionSequence();
226 sequence->addAction(negative1);
227 sequence->addAction(negative2);
228 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
229 delete sequence;
230 }
231 }
232
233 // second section:
234 {
235 // empty sequence can be undone
236 ActionSequence *sequence = new ActionSequence();
237 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
238 // if only a positive action is contained it can be undone
239 sequence->addAction(positive1);
240 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
241 // the single negative action should block the process
242 sequence->addAction(negative1);
243 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
244 // after removing the negative action all is well again
245 sequence->removeLastAction();
246 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
247 delete sequence;
248 }
249}
250
251void ActionSequenceTest::doesCallTest(){
252 ActionSequence *sequence = new ActionSequence();
253 sequence->addAction(shouldCall1);
254 sequence->addAction(shouldCall2);
255 sequence->addAction(shouldNotCall1);
256 sequence->addAction(shouldNotCall2);
257 sequence->removeLastAction();
258 sequence->removeLastAction();
259
260 sequence->callAll();
261
262 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
263 CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
264 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
265 CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
266
267 delete sequence;
268}
269
270void ActionSequenceTest::doesUndoTest(){
271 ActionSequence *sequence = new ActionSequence();
272 ActionTrait wasCalledTrait("wasCalledActionStub");
273 wasCalledActionStub *wasCalled1 = new wasCalledActionStub(wasCalledTrait);
274 wasCalledActionStub *wasCalled2 = new wasCalledActionStub(wasCalledTrait);
275 sequence->addAction(wasCalled1);
276 sequence->addAction(wasCalled2);
277
278 ActionTrait MakroTrait("Test MakroAction");
279 MakroAction act(MakroTrait,*sequence,false);
280
281 act.call();
282
283 CPPUNIT_ASSERT_EQUAL(true,wasCalled1->wasCalled());
284 CPPUNIT_ASSERT_EQUAL(true,wasCalled2->wasCalled());
285
286 ActionHistory::getInstance().undoLast();
287
288 CPPUNIT_ASSERT_EQUAL(false,wasCalled1->wasCalled());
289 CPPUNIT_ASSERT_EQUAL(false,wasCalled2->wasCalled());
290
291 delete sequence;
292}
293
294
Note: See TracBrowser for help on using the repository browser.