source: src/Actions/unittests/ActionSequenceUnitTest.cpp@ 560cbf

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 560cbf was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.0 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.
[94d5ac6]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/>.
[bcf653]21 */
22
[147339]23/*
[f7c0c4]24 * ActionSequenceUnitTest.cpp
[147339]25 *
26 * Created on: Dec 17, 2009
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[147339]35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
[f7c0c4]39#include "ActionSequenceUnitTest.hpp"
[147339]40#include "Actions/Action.hpp"
41#include "Actions/ActionSequence.hpp"
[2efa90]42#include "Actions/MakroAction.hpp"
43#include "Actions/ActionHistory.hpp"
44#include "Actions/ActionRegistry.hpp"
[147339]45
[fdcd1b]46#include "stubs/DummyUI.hpp"
[112f90]47
[ce7fdc]48using namespace MoleCuilder;
49
[9b6b2f]50#ifdef HAVE_TESTRUNNER
51#include "UnitTestMain.hpp"
52#endif /*HAVE_TESTRUNNER*/
53
54/********************************************** Test classes **************************************/
55
[147339]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:
[3139b2]63 canUndoActionStub(const ActionTrait &_trait):
[e4afb4]64 Action(_trait,false){}
[147339]65 virtual ~canUndoActionStub(){}
66
[047878]67 virtual Dialog* fillDialog(Dialog *dialog){
68 ASSERT(dialog,"No Dialog given when filling action dialog");
69 return dialog;
[80951de]70 }
71
[5b0b98]72 virtual Action::state_ptr performCall(){
[67e2b3]73 return Action::success;
74 }
[5b0b98]75 virtual Action::state_ptr performUndo(Action::state_ptr){
[67e2b3]76 return Action::success;
77 }
[5b0b98]78 virtual Action::state_ptr performRedo(Action::state_ptr){
[67e2b3]79 return Action::success;
80 }
[147339]81 virtual bool canUndo(){
82 return true;
83 }
[67e2b3]84 virtual bool shouldUndo(){
85 return true;
86 }
[147339]87};
88
89class cannotUndoActionStub : public Action
90{
91public:
[3139b2]92 cannotUndoActionStub(const ActionTrait &_trait) :
[e4afb4]93 Action(_trait,false){}
[147339]94 virtual ~cannotUndoActionStub(){}
95
[047878]96 virtual Dialog* fillDialog(Dialog *dialog){
97 ASSERT(dialog,"No Dialog given when filling action dialog");
98 return dialog;
[80951de]99 }
100
[5b0b98]101 virtual Action::state_ptr performCall(){
[67e2b3]102 return Action::success;
103 }
[5b0b98]104 virtual Action::state_ptr performUndo(Action::state_ptr){
[67e2b3]105 return Action::success;
106 }
[5b0b98]107 virtual Action::state_ptr performRedo(Action::state_ptr){
[67e2b3]108 return Action::success;
109 }
[147339]110 virtual bool canUndo(){
111 return false;
112 }
[67e2b3]113 virtual bool shouldUndo(){
114 return true;
115 }
[147339]116};
117
[0229f9]118class wasCalledActionStub : public Action
119{
120public:
[3139b2]121 wasCalledActionStub(const ActionTrait &_trait) :
[e4afb4]122 Action(_trait,false),
[0229f9]123 called(false)
124 {}
125 virtual ~wasCalledActionStub(){}
[147339]126
[047878]127 virtual Dialog* fillDialog(Dialog *dialog){
128 return dialog;
[80951de]129 }
[5b0b98]130 virtual Action::state_ptr performCall(){
[0229f9]131 called = true;
[67e2b3]132 return Action::success;
[0229f9]133 }
[5b0b98]134 virtual Action::state_ptr performUndo(Action::state_ptr){
[0229f9]135 called = false;
[67e2b3]136 return Action::success;
137 }
[5b0b98]138 virtual Action::state_ptr performRedo(Action::state_ptr){
[67e2b3]139 called = true;
140 return Action::success;
[0229f9]141 }
142 virtual bool canUndo(){
143 return true;
144 }
[67e2b3]145 virtual bool shouldUndo(){
146 return true;
147 }
[0229f9]148 bool wasCalled(){
149 return called;
150 }
151private:
152 bool called;
153};
[147339]154
[0229f9]155void ActionSequenceTest::setUp(){
[694d84]156 hasDescriptor = false;
[2efa90]157 ActionHistory::init();
[112f90]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");
[147339]164 // create some necessary stubs used in this test
[3139b2]165 ActionTrait canUndoTrait("canUndoActionStub");
166 ActionTrait cannotUndoTrait("cannotUndoActionStub");
[e4afb4]167 positive1 = new canUndoActionStub(canUndoTrait);
168 positive2 = new canUndoActionStub(canUndoTrait);
169 negative1 = new cannotUndoActionStub(cannotUndoTrait);
170 negative2 = new cannotUndoActionStub(cannotUndoTrait);
171
[3139b2]172 ActionTrait wasCalledTrait("wasCalledActionStub");
[e4afb4]173 shouldCall1 = new wasCalledActionStub(wasCalledTrait);
174 shouldCall2 = new wasCalledActionStub(wasCalledTrait);
175 shouldNotCall1 = new wasCalledActionStub(wasCalledTrait);
176 shouldNotCall2 = new wasCalledActionStub(wasCalledTrait);
[0229f9]177
178}
179
180void ActionSequenceTest::tearDown(){
181 delete positive1;
182 delete positive2;
183 delete negative1;
184 delete negative2;
[147339]185
[0229f9]186 delete shouldCall1;
187 delete shouldCall2;
188 delete shouldNotCall1;
189 delete shouldNotCall2;
190
[2efa90]191 ActionHistory::purgeInstance();
192 ActionRegistry::purgeInstance();
[694d84]193 {
194 UIFactory::purgeInstance();
195 hasDescriptor = false;
196 }
[0229f9]197}
198
199void ActionSequenceTest::canUndoTest(){
[147339]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 }
[0229f9]249}
[147339]250
[0229f9]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
[f59d81]267 delete sequence;
[0229f9]268}
269
270void ActionSequenceTest::doesUndoTest(){
271 ActionSequence *sequence = new ActionSequence();
[3139b2]272 ActionTrait wasCalledTrait("wasCalledActionStub");
[e4afb4]273 wasCalledActionStub *wasCalled1 = new wasCalledActionStub(wasCalledTrait);
274 wasCalledActionStub *wasCalled2 = new wasCalledActionStub(wasCalledTrait);
[2efa90]275 sequence->addAction(wasCalled1);
276 sequence->addAction(wasCalled2);
[0229f9]277
[3139b2]278 ActionTrait MakroTrait("Test MakroAction");
[e4afb4]279 MakroAction act(MakroTrait,sequence,false);
[0229f9]280
[2efa90]281 act.call();
[0229f9]282
[2efa90]283 CPPUNIT_ASSERT_EQUAL(true,wasCalled1->wasCalled());
[ec149d]284 CPPUNIT_ASSERT_EQUAL(true,wasCalled2->wasCalled());
[0229f9]285
[2efa90]286 ActionHistory::getInstance().undoLast();
287
288 CPPUNIT_ASSERT_EQUAL(false,wasCalled1->wasCalled());
[ec149d]289 CPPUNIT_ASSERT_EQUAL(false,wasCalled2->wasCalled());
[147339]290
291}
292
293
Note: See TracBrowser for help on using the repository browser.