source: src/unittests/ActionSequenceTest.cpp@ 147339

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 147339 was 147339, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added unittest for ActionSequence.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * ActionSequenzTest.cpp
3 *
4 * Created on: Dec 17, 2009
5 * Author: crueger
6 */
7
8#include <cppunit/CompilerOutputter.h>
9#include <cppunit/extensions/TestFactoryRegistry.h>
10#include <cppunit/ui/text/TestRunner.h>
11
12#include "unittests/ActionSequenceTest.hpp"
13#include "Actions/Action.hpp"
14#include "Actions/ActionSequence.hpp"
15
16// Registers the fixture into the 'registry'
17CPPUNIT_TEST_SUITE_REGISTRATION( ActionSequenceTest );
18
19void setUp();
20void tearDown();
21
22void canUndoTest();
23
24/* some neccessary stubs for tests */
25class canUndoActionStub : public Action
26{
27public:
28 canUndoActionStub(){}
29 virtual ~canUndoActionStub(){}
30
31 virtual void call(){}
32 virtual void undo(){}
33 virtual bool canUndo(){
34 return true;
35 }
36};
37
38class cannotUndoActionStub : public Action
39{
40public:
41 cannotUndoActionStub(){}
42 virtual ~cannotUndoActionStub(){}
43
44 virtual void call(){}
45 virtual void undo(){}
46 virtual bool canUndo(){
47 return false;
48 }
49};
50
51void ActionSequenceTest::setUp(){}
52void ActionSequenceTest::tearDown(){}
53
54void ActionSequenceTest::canUndoTest(){
55
56 // create some necessary stubs used in this test
57 Action *positive1 = new canUndoActionStub();
58 Action *positive2 = new canUndoActionStub();
59 Action *negative1 = new cannotUndoActionStub();
60 Action *negative2 = new cannotUndoActionStub();
61
62 // first section:
63 {
64 // test some combinations
65 {
66 ActionSequence *sequence = new ActionSequence();
67 sequence->addAction(positive1);
68 sequence->addAction(positive2);
69 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
70 delete sequence;
71 }
72 {
73 ActionSequence *sequence = new ActionSequence();
74 sequence->addAction(positive1);
75 sequence->addAction(negative2);
76 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
77 delete sequence;
78 }
79 {
80 ActionSequence *sequence = new ActionSequence();
81 sequence->addAction(negative1);
82 sequence->addAction(positive2);
83 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
84 delete sequence;
85 }
86 {
87 ActionSequence *sequence = new ActionSequence();
88 sequence->addAction(negative1);
89 sequence->addAction(negative2);
90 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
91 delete sequence;
92 }
93 }
94
95 // second section:
96 {
97 // empty sequence can be undone
98 ActionSequence *sequence = new ActionSequence();
99 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
100 // if only a positive action is contained it can be undone
101 sequence->addAction(positive1);
102 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
103 // the single negative action should block the process
104 sequence->addAction(negative1);
105 CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
106 // after removing the negative action all is well again
107 sequence->removeLastAction();
108 CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
109 delete sequence;
110 }
111
112 delete positive1;
113 delete positive2;
114 delete negative1;
115 delete negative2;
116
117}
118
119
120/********************************************** Main routine **************************************/
121
122int main(int argc, char **argv)
123{
124 // Get the top level suite from the registry
125 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
126
127 // Adds the test to the list of test to run
128 CppUnit::TextUi::TestRunner runner;
129 runner.addTest( suite );
130
131 // Change the default outputter to a compiler error format outputter
132 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
133 std::cerr ) );
134 // Run the tests.
135 bool wasSucessful = runner.run();
136
137 // Return error code 1 if the one of test failed.
138 return wasSucessful ? 0 : 1;
139};
Note: See TracBrowser for help on using the repository browser.