Changeset b760ac5 for src/Patterns/Observer/unittests
- Timestamp:
- Dec 13, 2011, 12:02:21 PM (14 years ago)
- 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)
- Location:
- src/Patterns/Observer/unittests
- Files:
-
- 4 edited
-
ObserverUnitTest.cpp (modified) (3 diffs)
-
ObserverUnitTest.hpp (modified) (4 diffs)
-
stubs/ObserverStub.cpp (modified) (2 diffs)
-
stubs/ObserverStub.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer/unittests/ObserverUnitTest.cpp
rd85532 rb760ac5 71 71 RelayObservable = new RelayTest; 72 72 RelayObserver = new RelayCountObserver(RelayObservable); 73 74 RelayNotifier = new RelayNotification; 75 RelayNotified = new RelayNotificationObserver(RelayObservable); 73 76 } 74 77 … … 84 87 delete RelayObservable; 85 88 delete RelayObserver; 89 delete RelayNotifier; 90 delete RelayNotified; 86 91 87 92 delete observer1; … … 276 281 } 277 282 283 void 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 278 324 void ObserverTest::CircleDetectionTest() { 279 325 std::cout << std::endl << "Warning: the next test involved methods that can produce infinite loops." << std::endl; -
src/Patterns/Observer/unittests/ObserverUnitTest.hpp
rd85532 rb760ac5 28 28 class NotificationObservable; 29 29 class RelayCountObserver; 30 class RelayNotification; 31 class RelayNotificationObserver; 30 32 31 33 class ObserverTest : public CppUnit::TestFixture … … 40 42 CPPUNIT_TEST ( iteratorTest ); 41 43 CPPUNIT_TEST ( relayTest ); 44 CPPUNIT_TEST ( relayNotificationTest ); 42 45 CPPUNIT_TEST ( CircleDetectionTest ); 43 46 CPPUNIT_TEST_SUITE_END(); … … 55 58 void iteratorTest(); 56 59 void relayTest(); 60 void relayNotificationTest(); 57 61 void CircleDetectionTest(); 58 62 … … 76 80 RelayTest *RelayObservable; 77 81 RelayCountObserver *RelayObserver; 82 RelayNotification *RelayNotifier; 83 RelayNotificationObserver *RelayNotified; 78 84 }; 79 85 -
src/Patterns/Observer/unittests/stubs/ObserverStub.cpp
rd85532 rb760ac5 239 239 {} 240 240 241 /************ RelayNotification ***************/ 242 243 RelayNotification::RelayNotification() : 244 Relay(std::string("RelayTest")) 245 { 246 Channels *OurChannel = new Channels(); 247 NotificationChannels.insert( std::make_pair(this, OurChannel) ); 248 OurChannel->addChannel(NotificationObservable::Operation1Notify); 249 OurChannel->addChannel(NotificationObservable::Operation2Notify); 250 } 251 252 RelayNotification::~RelayNotification() 253 {} 254 241 255 /************ RelayCountObserver ***************/ 242 256 … … 259 273 } 260 274 275 /********* RelayNotificationObserver ***********/ 276 277 RelayNotificationObserver::RelayNotificationObserver(const Observable * const _relay) : 278 Observer("RelayNotificationObserver"), 279 wasNotified(false), 280 relay(_relay) 281 {} 282 283 RelayNotificationObserver::~RelayNotificationObserver() 284 {} 285 286 void RelayNotificationObserver::update(Observable*){} 287 void RelayNotificationObserver::subjectKilled(Observable*){} 288 void RelayNotificationObserver::recieveNotification(Observable *publisher, Notification_ptr notification){ 289 // check that we are not called by the relay itself 290 CPPUNIT_ASSERT(publisher != relay); 291 wasNotified = true; 292 } 293 -
src/Patterns/Observer/unittests/stubs/ObserverStub.hpp
rd85532 rb760ac5 148 148 }; 149 149 150 class RelayNotification : public Relay 151 { 152 public: 153 RelayNotification(); 154 ~RelayNotification(); 155 private: 156 }; 157 158 class RelayNotificationObserver : public Observer { 159 public: 160 RelayNotificationObserver(const Observable * const _relay); 161 virtual ~RelayNotificationObserver(); 162 163 void update(Observable*); 164 void subjectKilled(Observable*); 165 void recieveNotification(Observable *publisher, Notification_ptr notification); 166 167 bool wasNotified; 168 private: 169 const Observable * const relay; 170 }; 171 150 172 #endif /* OBSERVERSTUB_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.
