Ignore:
Timestamp:
Apr 24, 2010, 3:27:00 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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
Message:

Added methods for specialized Notifications from the Observer Framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ObserverTest.cpp

    r8a34392 rccacba  
    116116  }
    117117  SimpleObservable *subObservable;
     118};
     119
     120class NotificationObservable : public Observable {
     121public:
     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
     146class NotificationObserver : public Observer {
     147public:
     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;
    118163};
    119164
     
    127172  superObservable = new SuperObservable();
    128173  blockObservable = new BlockObservable();
     174  notificationObservable = new NotificationObservable();
    129175
    130176  observer1 = new UpdateCountObserver();
     
    132178  observer3 = new UpdateCountObserver();
    133179  observer4 = new UpdateCountObserver();
     180
     181  notificationObserver1 = new NotificationObserver(notificationObservable->notification1);
     182  notificationObserver2 = new NotificationObserver(notificationObservable->notification2);
     183
    134184}
    135185
     
    139189  delete callObservable;
    140190  delete superObservable;
     191  delete notificationObservable;
    141192
    142193  delete observer1;
     
    144195  delete observer3;
    145196  delete observer4;
     197  delete notificationObserver1;
     198  delete notificationObserver2;
    146199}
    147200
     
    198251  CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
    199252  CPPUNIT_ASSERT_EQUAL( 2, observer2->updates );
     253}
     254
     255void 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
    200271}
    201272
Note: See TracChangeset for help on using the changeset viewer.