Ignore:
Timestamp:
Aug 5, 2015, 7:12:24 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
c307ba
Parents:
94232b
git-author:
Frederik Heber <heber@…> (08/03/15 09:25:02)
git-committer:
Frederik Heber <heber@…> (08/05/15 07:12:24)
Message:

Cleaned up ActionQueue's interface: Actions are always cloned.

  • Action's dstor needs to be public as we have a clone() function.
  • ActionRegistrys' (and AQ's) getActionByName now returns const ref. We must not return a ptr as it may not get deleted elsewhere. We are handing out prototypes.
  • queueAction(action*,...) is private to prevent leakage, queueAction(string, ...) is the public interface.
  • some other small functions are now private, too.
  • MakroActions now need to clone() the prototype on prepare() and delete them on unprepare().
  • ActionSequence deletes contained actions.
  • FIX: ActionSequenceUnitTest cannot check on not-called property of removed actions anymore as these are gone now (they are deleted on removal and they are cloned on insertion).
  • DOCU: Updated documentation on Actions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/unittests/ActionSequenceUnitTest.cpp

    r94232b r10aee4  
    239239    {
    240240      ActionSequence *sequence = new ActionSequence();
    241       sequence->addAction(positive1);
    242       sequence->addAction(positive2);
     241      sequence->addAction(positive1->clone());
     242      sequence->addAction(positive2->clone());
    243243      CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    244244      delete sequence;
     
    246246    {
    247247      ActionSequence *sequence = new ActionSequence();
    248       sequence->addAction(positive1);
    249       sequence->addAction(negative2);
     248      sequence->addAction(positive1->clone());
     249      sequence->addAction(negative2->clone());
    250250      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    251251      delete sequence;
     
    253253    {
    254254      ActionSequence *sequence = new ActionSequence();
    255       sequence->addAction(negative1);
    256       sequence->addAction(positive2);
     255      sequence->addAction(negative1->clone());
     256      sequence->addAction(positive2->clone());
    257257      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    258258      delete sequence;
     
    260260    {
    261261      ActionSequence *sequence = new ActionSequence();
    262       sequence->addAction(negative1);
    263       sequence->addAction(negative2);
     262      sequence->addAction(negative1->clone());
     263      sequence->addAction(negative2->clone());
    264264      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    265265      delete sequence;
     
    273273    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    274274    // if only a positive action is contained it can be undone
    275     sequence->addAction(positive1);
     275    sequence->addAction(positive1->clone());
    276276    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    277277    // the single negative action should block the process
    278     sequence->addAction(negative1);
     278    sequence->addAction(negative1->clone());
    279279    CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    280280    // after removing the negative action all is well again
    281     sequence->removeLastAction();
     281    delete sequence->removeLastAction();
    282282    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    283283    delete sequence;
     
    287287void ActionSequenceTest::doesCallTest(){
    288288  ActionSequence *sequence = new ActionSequence();
    289   sequence->addAction(shouldCall1);
    290   sequence->addAction(shouldCall2);
    291   sequence->addAction(shouldNotCall1);
    292   sequence->addAction(shouldNotCall2);
    293   sequence->removeLastAction();
    294   sequence->removeLastAction();
     289  sequence->addAction(shouldCall1->clone());
     290  sequence->addAction(shouldCall2->clone());
     291  sequence->addAction(shouldNotCall1->clone());
     292  sequence->addAction(shouldNotCall2->clone());
     293  delete sequence->removeLastAction();
     294  delete sequence->removeLastAction();
    295295
    296296  sequence->callAll();
    297297
    298   CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
    299   CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
    300   CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
    301   CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
     298  ActionSequence::actionSet::const_iterator iter = sequence->actions.begin();
     299  CPPUNIT_ASSERT_EQUAL(true,dynamic_cast<wasCalledActionStub *>(*iter++)->wasCalled());
     300  CPPUNIT_ASSERT_EQUAL(true,dynamic_cast<wasCalledActionStub *>(*iter++)->wasCalled());
     301  CPPUNIT_ASSERT( iter == sequence->actions.end() );
    302302
    303303  delete sequence;
Note: See TracChangeset for help on using the changeset viewer.