Changeset ccacba for src/unittests/ObserverTest.cpp
- Timestamp:
- Apr 24, 2010, 3:27:00 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:
- 033a05
- Parents:
- 8a34392
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/ObserverTest.cpp
r8a34392 rccacba 116 116 } 117 117 SimpleObservable *subObservable; 118 }; 119 120 class NotificationObservable : public Observable { 121 public: 122 NotificationObservable() : 123 notification1(new Notification(this)), 124 notification2(new Notification(this)) 125 {} 126 127 ~NotificationObservable(){ 128 delete notification1; 129 delete notification2; 130 } 131 132 void operation1(){ 133 OBSERVE; 134 NOTIFY(notification1); 135 } 136 137 void operation2(){ 138 OBSERVE; 139 NOTIFY(notification2); 140 } 141 142 Notification_ptr notification1; 143 Notification_ptr notification2; 144 }; 145 146 class NotificationObserver : public Observer { 147 public: 148 NotificationObserver(Notification_ptr notification) : 149 requestedNotification(notification), 150 wasNotified(false) 151 {} 152 153 void update(Observable*){} 154 void subjectKilled(Observable*){} 155 void recieveNotification(Observable *publisher, Notification_ptr notification){ 156 ASSERT(requestedNotification==notification,"Notification recieved that was not requested"); 157 wasNotified = true; 158 } 159 160 Notification_ptr requestedNotification; 161 162 bool wasNotified; 118 163 }; 119 164 … … 127 172 superObservable = new SuperObservable(); 128 173 blockObservable = new BlockObservable(); 174 notificationObservable = new NotificationObservable(); 129 175 130 176 observer1 = new UpdateCountObserver(); … … 132 178 observer3 = new UpdateCountObserver(); 133 179 observer4 = new UpdateCountObserver(); 180 181 notificationObserver1 = new NotificationObserver(notificationObservable->notification1); 182 notificationObserver2 = new NotificationObserver(notificationObservable->notification2); 183 134 184 } 135 185 … … 139 189 delete callObservable; 140 190 delete superObservable; 191 delete notificationObservable; 141 192 142 193 delete observer1; … … 144 195 delete observer3; 145 196 delete observer4; 197 delete notificationObserver1; 198 delete notificationObserver2; 146 199 } 147 200 … … 198 251 CPPUNIT_ASSERT_EQUAL( 2, observer1->updates ); 199 252 CPPUNIT_ASSERT_EQUAL( 2, observer2->updates ); 253 } 254 255 void ObserverTest::doesNotifyTest(){ 256 notificationObservable->signOn(notificationObserver1, 257 notificationObservable->notification1); 258 notificationObservable->signOn(notificationObserver2, 259 notificationObservable->notification2); 260 261 notificationObservable->operation1(); 262 CPPUNIT_ASSERT(notificationObserver1->wasNotified); 263 CPPUNIT_ASSERT(!notificationObserver2->wasNotified); 264 265 notificationObserver1->wasNotified=false; 266 267 notificationObservable->operation2(); 268 CPPUNIT_ASSERT(!notificationObserver1->wasNotified); 269 CPPUNIT_ASSERT(notificationObserver2->wasNotified); 270 200 271 } 201 272
Note:
See TracChangeset
for help on using the changeset viewer.