Ignore:
Timestamp:
Dec 13, 2011, 12:02:21 PM (14 years ago)
Author:
Frederik Heber <heber@…>
Children:
3324cf
Parents:
d85532
git-author:
Frederik Heber <heber@…> (12/02/11 13:13:44)
git-committer:
Frederik Heber <heber@…> (12/13/11 12:02:21)
Message:

Relay can now also relay notifications.

  • NOTE: We do not yet notify the Observables, whose update() we combine, when the Relay is destroyed. They have to signOff before by themselves (or by some other means, e.g. be destroyed before.).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer/unittests/ObserverUnitTest.cpp

    rd85532 rb760ac5  
    7171  RelayObservable = new RelayTest;
    7272  RelayObserver = new RelayCountObserver(RelayObservable);
     73
     74  RelayNotifier = new RelayNotification;
     75  RelayNotified = new RelayNotificationObserver(RelayObservable);
    7376}
    7477
     
    8487  delete RelayObservable;
    8588  delete RelayObserver;
     89  delete RelayNotifier;
     90  delete RelayNotified;
    8691
    8792  delete observer1;
     
    276281}
    277282
     283void ObserverTest::relayNotificationTest()
     284{
     285  observerLog().enableLogging();
     286
     287  // sign on some observables to the relay
     288  notificationObservable->signOn(RelayNotifier, NotificationObservable::Operation1Notify);
     289  notificationObservable->signOn(RelayNotifier, NotificationObservable::Operation2Notify);
     290  notificationObservable->signOn(notificationObserver1, NotificationObservable::Operation1Notify);
     291
     292  RelayNotifier->signOn(RelayNotified, NotificationObservable::Operation1Notify);
     293
     294  // operation1
     295  notificationObservable->operation1();
     296  CPPUNIT_ASSERT(RelayNotified->wasNotified);
     297  CPPUNIT_ASSERT(notificationObserver1->wasNotified);
     298
     299  RelayNotified->wasNotified=false;
     300
     301  // operation2
     302  notificationObservable->operation2();
     303  CPPUNIT_ASSERT(!RelayNotified->wasNotified);
     304  CPPUNIT_ASSERT(notificationObserver1->wasNotified);
     305
     306  // signOff relay from 1 and operation1
     307  notificationObserver1->wasNotified=false;
     308  notificationObservable->signOff(RelayNotifier, NotificationObservable::Operation1Notify);
     309
     310  notificationObservable->operation1();
     311  CPPUNIT_ASSERT(!RelayNotified->wasNotified);
     312  CPPUNIT_ASSERT(notificationObserver1->wasNotified);
     313
     314  // test kill subject
     315  delete RelayNotified;
     316  RelayNotified = NULL; // delete in tearDown is allowed for NULL
     317  notificationObservable->operation1();
     318  delete notificationObservable;
     319  notificationObservable = NULL; // delete in tearDown is allowed for NULL
     320
     321  observerLog().disableLogging();
     322}
     323
    278324void ObserverTest::CircleDetectionTest() {
    279325  std::cout << std::endl << "Warning: the next test involved methods that can produce infinite loops." << std::endl;
Note: See TracChangeset for help on using the changeset viewer.