Changeset 4fb5a3
- Timestamp:
- Mar 19, 2010, 4:44:08 PM (15 years ago)
- 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:
- adc42b
- Parents:
- 052b8d0
- git-author:
- Tillmann Crueger <crueger@…> (03/19/10 16:13:28)
- git-committer:
- Tillmann Crueger <crueger@…> (03/19/10 16:44:08)
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
r052b8d0 r4fb5a3 10 10 11 11 #include <iostream> 12 #include <cassert> 12 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; … … 127 128 // observers, but still we are called by one of our sub-Observables 128 129 // we cannot be sure observation will still work at this point 129 cerr << "Circle detected in observation-graph." << endl;130 cerr << "Observation-graph always needs to be a DAG to work correctly!" << endl;131 cerr << "Please check your observation code and fix this!" << endl;130 ASSERT(0,"Circle detected in observation-graph.\n" 131 "Observation-graph always needs to be a DAG to work correctly!\n" 132 "Please check your observation code and fix this!\n"); 132 133 return; 133 134 } … … 148 149 */ 149 150 void Observable::signOn(Observer *target,int priority) { 150 assert(priority>=-20 && priority<=+20 && "Priority out of range [-20:+20]");151 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 151 152 bool res = false; 152 153 callees_t *callees = 0; … … 172 173 */ 173 174 void Observable::signOff(Observer *target) { 174 assert(callTable.count(this) &&"SignOff called for an Observable without Observers.");175 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 175 176 callees_t *callees = callTable[this]; 176 177 callees_t::iterator iter; … … 188 189 delete callees; 189 190 } 191 } 192 193 bool Observable::isBlocked(){ 194 return depth.count(this) > 0; 190 195 } 191 196 -
src/Patterns/Observer.hpp
r052b8d0 r4fb5a3 95 95 virtual void signOff(Observer *target); 96 96 97 /** 98 * Ask an Observer if it is currently in a blocked state, i.e. if 99 * Changes are in Progress, that are not yet published. 100 */ 101 virtual bool isBlocked(); 102 97 103 protected: 98 104 virtual void update(Observable *publisher); … … 119 125 static std::set<Observable*> busyObservables; 120 126 127 //! @cond 121 128 // Structure for RAII-Style notification 122 129 protected: … … 133 140 Observable *protege; 134 141 }; 142 //! @endcond 135 143 }; 136 144 -
src/unittests/ObserverTest.cpp
r052b8d0 r4fb5a3 13 13 14 14 #include "Patterns/Observer.hpp" 15 #include "Helpers/Assert.hpp" 15 16 16 17 #include <iostream> … … 65 66 }; 66 67 68 class BlockObservable : public Observable { 69 public: 70 void changeMethod1(){ 71 OBSERVE; 72 // test if we report correctly as blocked 73 CPPUNIT_ASSERT(isBlocked()); 74 } 75 76 void changeMethod2(){ 77 OBSERVE; 78 internalMethod1(); 79 internalMethod2(); 80 } 81 82 void internalMethod1(){ 83 // we did not block, but our caller did... 84 // see if this is found 85 CPPUNIT_ASSERT(isBlocked()); 86 } 87 88 void internalMethod2(){ 89 OBSERVE; 90 // Both this method and the caller do block 91 // Does the reporting still work as expected? 92 CPPUNIT_ASSERT(isBlocked()); 93 } 94 95 void noChangeMethod(){ 96 // No Block introduced here 97 // reported correctely? 98 CPPUNIT_ASSERT(!isBlocked()); 99 } 100 }; 101 67 102 class SuperObservable : public Observable { 68 103 public: … … 86 121 87 122 void ObserverTest::setUp() { 123 ASSERT_DO(Assert::Throw); 88 124 simpleObservable1 = new SimpleObservable(); 89 125 simpleObservable2 = new SimpleObservable(); 90 126 callObservable = new CallObservable(); 91 127 superObservable = new SuperObservable(); 128 blockObservable = new BlockObservable(); 92 129 93 130 observer1 = new UpdateCountObserver(); … … 163 200 } 164 201 202 void ObserverTest::doesReportTest(){ 203 // Actual checks are in the Stub-methods for this 204 blockObservable->changeMethod1(); 205 blockObservable->changeMethod2(); 206 blockObservable->noChangeMethod(); 207 } 165 208 166 209 void ObserverTest::CircleDetectionTest() { … … 174 217 // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE 175 218 simpleObservable1->signOn(simpleObservable1); 176 simpleObservable1->changeMethod();219 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 177 220 178 221 // more complex test … … 180 223 simpleObservable1->signOn(simpleObservable2); 181 224 simpleObservable2->signOn(simpleObservable1); 182 simpleObservable1->changeMethod();225 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 183 226 simpleObservable1->signOff(simpleObservable2); 184 227 simpleObservable2->signOff(simpleObservable1); -
src/unittests/ObserverTest.hpp
r052b8d0 r4fb5a3 16 16 class CallObservable; 17 17 class SuperObservable; 18 class BlockObservable; 18 19 19 20 … … 24 25 CPPUNIT_TEST ( doesBlockUpdateTest ); 25 26 CPPUNIT_TEST ( doesSubObservableTest ); 27 CPPUNIT_TEST ( doesReportTest ); 26 28 CPPUNIT_TEST ( CircleDetectionTest ); 27 29 CPPUNIT_TEST_SUITE_END(); … … 34 36 void doesBlockUpdateTest(); 35 37 void doesSubObservableTest(); 38 void doesReportTest(); 36 39 void CircleDetectionTest(); 37 40 … … 45 48 SimpleObservable *simpleObservable2; 46 49 CallObservable *callObservable; 50 BlockObservable *blockObservable; 47 51 SuperObservable *superObservable; 48 52 };
Note:
See TracChangeset
for help on using the changeset viewer.