Changeset b64313
- Timestamp:
- Mar 19, 2010, 4:13:28 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:
- 760ef4
- Parents:
- e0b6fd
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
re0b6fd rb64313 10 10 11 11 #include <iostream> 12 #include <cassert> 12 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; … … 133 134 // observers, but still we are called by one of our sub-Observables 134 135 // we cannot be sure observation will still work at this point 135 cerr << "Circle detected in observation-graph." << endl;136 cerr << "Observation-graph always needs to be a DAG to work correctly!" << endl;137 cerr << "Please check your observation code and fix this!" << endl;136 ASSERT(0,"Circle detected in observation-graph.\n" 137 "Observation-graph always needs to be a DAG to work correctly!\n" 138 "Please check your observation code and fix this!\n"); 138 139 return; 139 140 } … … 154 155 */ 155 156 void Observable::signOn(Observer *target,int priority) { 156 assert(priority>=-20 && priority<=+20 && "Priority out of range [-20:+20]");157 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 157 158 bool res = false; 158 159 callees_t *callees = 0; … … 178 179 */ 179 180 void Observable::signOff(Observer *target) { 180 assert(callTable.count(this) &&"SignOff called for an Observable without Observers.");181 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 181 182 callees_t *callees = callTable[this]; 182 183 callees_t::iterator iter; … … 196 197 } 197 198 199 bool Observable::isBlocked(){ 200 return depth.count(this) > 0; 201 } 202 198 203 /** Handles sub-observables that just got killed 199 204 * when an sub-observerable dies we usually don't need to do anything -
src/Patterns/Observer.hpp
re0b6fd rb64313 98 98 virtual void signOff(Observer *target); 99 99 100 /** 101 * Ask an Observer if it is currently in a blocked state, i.e. if 102 * Changes are in Progress, that are not yet published. 103 */ 104 virtual bool isBlocked(); 105 100 106 protected: 101 107 virtual void update(Observable *publisher); … … 122 128 static std::set<Observable*> busyObservables; 123 129 130 //! @cond 124 131 // Structure for RAII-Style notification 125 132 protected: … … 137 144 Observable *protege; 138 145 }; 146 //! @endcond 139 147 }; 140 148 -
src/unittests/ObserverTest.cpp
re0b6fd rb64313 15 15 #include "Patterns/Observer.hpp" 16 16 #include "Patterns/ObservedIterator.hpp" 17 #include "Helpers/Assert.hpp" 17 18 18 19 #include <iostream> … … 64 65 i++; 65 66 changeMethod1(); 67 } 68 }; 69 70 class BlockObservable : public Observable { 71 public: 72 void changeMethod1(){ 73 OBSERVE; 74 // test if we report correctly as blocked 75 CPPUNIT_ASSERT(isBlocked()); 76 } 77 78 void changeMethod2(){ 79 OBSERVE; 80 internalMethod1(); 81 internalMethod2(); 82 } 83 84 void internalMethod1(){ 85 // we did not block, but our caller did... 86 // see if this is found 87 CPPUNIT_ASSERT(isBlocked()); 88 } 89 90 void internalMethod2(){ 91 OBSERVE; 92 // Both this method and the caller do block 93 // Does the reporting still work as expected? 94 CPPUNIT_ASSERT(isBlocked()); 95 } 96 97 void noChangeMethod(){ 98 // No Block introduced here 99 // reported correctely? 100 CPPUNIT_ASSERT(!isBlocked()); 66 101 } 67 102 }; … … 120 155 121 156 void ObserverTest::setUp() { 157 ASSERT_DO(Assert::Throw); 122 158 simpleObservable1 = new SimpleObservable(); 123 159 simpleObservable2 = new SimpleObservable(); 124 160 callObservable = new CallObservable(); 125 161 superObservable = new SuperObservable(); 162 blockObservable = new BlockObservable(); 126 163 127 164 observer1 = new UpdateCountObserver(); … … 199 236 CPPUNIT_ASSERT_EQUAL( 2, observer1->updates ); 200 237 CPPUNIT_ASSERT_EQUAL( 2, observer2->updates ); 238 } 239 240 void ObserverTest::doesReportTest(){ 241 // Actual checks are in the Stub-methods for this 242 blockObservable->changeMethod1(); 243 blockObservable->changeMethod2(); 244 blockObservable->noChangeMethod(); 201 245 } 202 246 … … 227 271 // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE 228 272 simpleObservable1->signOn(simpleObservable1); 229 simpleObservable1->changeMethod();273 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 230 274 231 275 // more complex test … … 233 277 simpleObservable1->signOn(simpleObservable2); 234 278 simpleObservable2->signOn(simpleObservable1); 235 simpleObservable1->changeMethod();279 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 236 280 simpleObservable1->signOff(simpleObservable2); 237 281 simpleObservable2->signOff(simpleObservable1); -
src/unittests/ObserverTest.hpp
re0b6fd rb64313 17 17 class SuperObservable; 18 18 class ObservableCollection; 19 class BlockObservable; 19 20 20 21 … … 25 26 CPPUNIT_TEST ( doesBlockUpdateTest ); 26 27 CPPUNIT_TEST ( doesSubObservableTest ); 28 CPPUNIT_TEST ( doesReportTest ); 27 29 CPPUNIT_TEST ( iteratorTest ); 28 30 CPPUNIT_TEST ( CircleDetectionTest ); … … 36 38 void doesBlockUpdateTest(); 37 39 void doesSubObservableTest(); 40 void doesReportTest(); 38 41 void iteratorTest(); 39 42 void CircleDetectionTest(); … … 48 51 SimpleObservable *simpleObservable2; 49 52 CallObservable *callObservable; 53 BlockObservable *blockObservable; 50 54 SuperObservable *superObservable; 51 55
Note:
See TracChangeset
for help on using the changeset viewer.