source: src/Actions/unittests/ActionSequenceUnitTest.cpp@ d67e6c

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 d67e6c was 0c8056, checked in by Frederik Heber <heber@…>, 12 years ago

Actions now get ptr to ActionRegistry in cstor.

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