[63c1f6] | 1 | /*
|
---|
| 2 | * ObserverTest.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Jan 19, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[63c1f6] | 13 | #include "ObserverTest.hpp"
|
---|
| 14 |
|
---|
| 15 | #include <cppunit/CompilerOutputter.h>
|
---|
| 16 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 17 | #include <cppunit/ui/text/TestRunner.h>
|
---|
[bd58fb] | 18 | #include <set>
|
---|
[63c1f6] | 19 |
|
---|
| 20 | #include "Patterns/Observer.hpp"
|
---|
[bd58fb] | 21 | #include "Patterns/ObservedIterator.hpp"
|
---|
[4fb5a3] | 22 | #include "Helpers/Assert.hpp"
|
---|
[63c1f6] | 23 |
|
---|
| 24 | #include <iostream>
|
---|
| 25 |
|
---|
| 26 | using namespace std;
|
---|
| 27 |
|
---|
[9b6b2f] | 28 | #ifdef HAVE_TESTRUNNER
|
---|
| 29 | #include "UnitTestMain.hpp"
|
---|
| 30 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 31 |
|
---|
[63c1f6] | 32 | // Registers the fixture into the 'registry'
|
---|
| 33 | CPPUNIT_TEST_SUITE_REGISTRATION( ObserverTest );
|
---|
| 34 |
|
---|
| 35 | /******************* Test stubs ************************/
|
---|
| 36 |
|
---|
| 37 | class UpdateCountObserver : public Observer {
|
---|
| 38 | public:
|
---|
| 39 | UpdateCountObserver() :
|
---|
[cd5047] | 40 | Observer("UpdateCountObserver"),
|
---|
[63c1f6] | 41 | updates(0)
|
---|
| 42 | {};
|
---|
| 43 | void update(Observable *publisher){
|
---|
| 44 | updates++;
|
---|
| 45 | }
|
---|
| 46 | void subjectKilled(Observable *publisher) {
|
---|
| 47 | }
|
---|
| 48 | int updates;
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | class SimpleObservable : public Observable {
|
---|
| 52 | public:
|
---|
[cd5047] | 53 | SimpleObservable() :
|
---|
| 54 | Observable("SimpleObservable")
|
---|
| 55 | {}
|
---|
| 56 |
|
---|
[63c1f6] | 57 | void changeMethod() {
|
---|
[317df8] | 58 | OBSERVE;
|
---|
[5e5283] | 59 | int i = 0;
|
---|
[63c1f6] | 60 | i++;
|
---|
| 61 | }
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | class CallObservable : public Observable {
|
---|
| 65 | public:
|
---|
[cd5047] | 66 | CallObservable() :
|
---|
| 67 | Observable("CallObservable")
|
---|
| 68 | {}
|
---|
| 69 |
|
---|
[63c1f6] | 70 | void changeMethod1() {
|
---|
[317df8] | 71 | OBSERVE;
|
---|
[5e5283] | 72 | int i = 0;
|
---|
[63c1f6] | 73 | i++;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void changeMethod2() {
|
---|
[317df8] | 77 | OBSERVE;
|
---|
[5e5283] | 78 | int i = 0;
|
---|
[63c1f6] | 79 | i++;
|
---|
| 80 | changeMethod1();
|
---|
| 81 | }
|
---|
| 82 | };
|
---|
| 83 |
|
---|
[4fb5a3] | 84 | class BlockObservable : public Observable {
|
---|
| 85 | public:
|
---|
[cd5047] | 86 | BlockObservable() :
|
---|
| 87 | Observable("BlockObservable")
|
---|
| 88 | {}
|
---|
| 89 |
|
---|
[4fb5a3] | 90 | void changeMethod1(){
|
---|
| 91 | OBSERVE;
|
---|
| 92 | // test if we report correctly as blocked
|
---|
| 93 | CPPUNIT_ASSERT(isBlocked());
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void changeMethod2(){
|
---|
| 97 | OBSERVE;
|
---|
| 98 | internalMethod1();
|
---|
| 99 | internalMethod2();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void internalMethod1(){
|
---|
| 103 | // we did not block, but our caller did...
|
---|
| 104 | // see if this is found
|
---|
| 105 | CPPUNIT_ASSERT(isBlocked());
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | void internalMethod2(){
|
---|
| 109 | OBSERVE;
|
---|
| 110 | // Both this method and the caller do block
|
---|
| 111 | // Does the reporting still work as expected?
|
---|
| 112 | CPPUNIT_ASSERT(isBlocked());
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void noChangeMethod(){
|
---|
| 116 | // No Block introduced here
|
---|
| 117 | // reported correctely?
|
---|
| 118 | CPPUNIT_ASSERT(!isBlocked());
|
---|
| 119 | }
|
---|
| 120 | };
|
---|
| 121 |
|
---|
[63c1f6] | 122 | class SuperObservable : public Observable {
|
---|
| 123 | public:
|
---|
[cd5047] | 124 | SuperObservable():
|
---|
| 125 | Observable("SuperObservable")
|
---|
| 126 | {
|
---|
[63c1f6] | 127 | subObservable = new SimpleObservable();
|
---|
| 128 | subObservable->signOn(this);
|
---|
| 129 | }
|
---|
| 130 | ~SuperObservable(){
|
---|
| 131 | delete subObservable;
|
---|
| 132 | }
|
---|
| 133 | void changeMethod() {
|
---|
[317df8] | 134 | OBSERVE;
|
---|
[5e5283] | 135 | int i = 0;
|
---|
[63c1f6] | 136 | i++;
|
---|
| 137 | subObservable->changeMethod();
|
---|
| 138 | }
|
---|
| 139 | SimpleObservable *subObservable;
|
---|
| 140 | };
|
---|
| 141 |
|
---|
[ccacba] | 142 | class NotificationObservable : public Observable {
|
---|
| 143 | public:
|
---|
| 144 | NotificationObservable() :
|
---|
[cd5047] | 145 | Observable("NotificationObservable"),
|
---|
| 146 | notification1(new Notification(this)),
|
---|
| 147 | notification2(new Notification(this))
|
---|
[ccacba] | 148 | {}
|
---|
| 149 |
|
---|
| 150 | ~NotificationObservable(){
|
---|
| 151 | delete notification1;
|
---|
| 152 | delete notification2;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void operation1(){
|
---|
| 156 | OBSERVE;
|
---|
| 157 | NOTIFY(notification1);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void operation2(){
|
---|
| 161 | OBSERVE;
|
---|
| 162 | NOTIFY(notification2);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | Notification_ptr notification1;
|
---|
| 166 | Notification_ptr notification2;
|
---|
| 167 | };
|
---|
| 168 |
|
---|
| 169 | class NotificationObserver : public Observer {
|
---|
| 170 | public:
|
---|
| 171 | NotificationObserver(Notification_ptr notification) :
|
---|
[cd5047] | 172 | Observer("NotificationObserver"),
|
---|
[ccacba] | 173 | requestedNotification(notification),
|
---|
| 174 | wasNotified(false)
|
---|
| 175 | {}
|
---|
| 176 |
|
---|
| 177 | void update(Observable*){}
|
---|
| 178 | void subjectKilled(Observable*){}
|
---|
| 179 | void recieveNotification(Observable *publisher, Notification_ptr notification){
|
---|
[033a05] | 180 | ASSERT(requestedNotification==notification,"Notification received that was not requested");
|
---|
[ccacba] | 181 | wasNotified = true;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | Notification_ptr requestedNotification;
|
---|
| 185 |
|
---|
| 186 | bool wasNotified;
|
---|
| 187 | };
|
---|
| 188 |
|
---|
[8774c5] | 189 | class ObservableSet : public Observable {
|
---|
[bd58fb] | 190 | public:
|
---|
| 191 | typedef std::set<SimpleObservable*> set;
|
---|
| 192 | typedef ObservedIterator<set> iterator;
|
---|
[a7b761b] | 193 | typedef set::const_iterator const_iterator;
|
---|
[bd58fb] | 194 |
|
---|
[8774c5] | 195 | ObservableSet(int _num) :
|
---|
[cd5047] | 196 | Observable("ObservableCollection"),
|
---|
| 197 | num(_num)
|
---|
[a7b761b] | 198 | {
|
---|
[bd58fb] | 199 | for(int i=0; i<num; ++i){
|
---|
| 200 | SimpleObservable *content = new SimpleObservable();
|
---|
| 201 | content->signOn(this);
|
---|
| 202 | theSet.insert(content);
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[8774c5] | 206 | ~ObservableSet(){
|
---|
[bd58fb] | 207 | set::iterator iter;
|
---|
| 208 | for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
|
---|
| 209 | delete (*iter);
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | iterator begin(){
|
---|
| 214 | return iterator(theSet.begin(),this);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | iterator end(){
|
---|
| 218 | return iterator(theSet.end(),this);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[a7b761b] | 221 | const int num;
|
---|
| 222 |
|
---|
[bd58fb] | 223 | private:
|
---|
| 224 | set theSet;
|
---|
| 225 | };
|
---|
| 226 |
|
---|
[8774c5] | 227 | class ObservableMap : public Observable {
|
---|
| 228 | public:
|
---|
| 229 | typedef std::map<int,SimpleObservable*> set;
|
---|
| 230 | typedef ObservedIterator<set> iterator;
|
---|
| 231 | typedef set::const_iterator const_iterator;
|
---|
| 232 |
|
---|
| 233 | ObservableMap(int _num) :
|
---|
| 234 | Observable("ObservableCollection"),
|
---|
| 235 | num(_num)
|
---|
| 236 | {
|
---|
| 237 | for(int i=0; i<num; ++i){
|
---|
| 238 | SimpleObservable *content = new SimpleObservable();
|
---|
| 239 | content->signOn(this);
|
---|
| 240 | theSet.insert(make_pair(i,content));
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | ~ObservableMap(){
|
---|
| 245 | set::iterator iter;
|
---|
| 246 | for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
|
---|
| 247 | delete iter->second;
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | iterator begin(){
|
---|
| 252 | return iterator(theSet.begin(),this);
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | iterator end(){
|
---|
| 256 | return iterator(theSet.end(),this);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | const int num;
|
---|
| 260 |
|
---|
| 261 | private:
|
---|
| 262 | set theSet;
|
---|
| 263 | };
|
---|
| 264 |
|
---|
[a7b761b] | 265 |
|
---|
[63c1f6] | 266 | /******************* actuall tests ***************/
|
---|
| 267 |
|
---|
| 268 | void ObserverTest::setUp() {
|
---|
[4fb5a3] | 269 | ASSERT_DO(Assert::Throw);
|
---|
[d5f216] | 270 | simpleObservable1 = new SimpleObservable();
|
---|
| 271 | simpleObservable2 = new SimpleObservable();
|
---|
[63c1f6] | 272 | callObservable = new CallObservable();
|
---|
| 273 | superObservable = new SuperObservable();
|
---|
[4fb5a3] | 274 | blockObservable = new BlockObservable();
|
---|
[ccacba] | 275 | notificationObservable = new NotificationObservable();
|
---|
[8774c5] | 276 | obsset = new ObservableSet(5);
|
---|
| 277 | obsmap = new ObservableMap(5);
|
---|
[63c1f6] | 278 |
|
---|
| 279 | observer1 = new UpdateCountObserver();
|
---|
| 280 | observer2 = new UpdateCountObserver();
|
---|
| 281 | observer3 = new UpdateCountObserver();
|
---|
[d5f216] | 282 | observer4 = new UpdateCountObserver();
|
---|
[ccacba] | 283 |
|
---|
| 284 | notificationObserver1 = new NotificationObserver(notificationObservable->notification1);
|
---|
| 285 | notificationObserver2 = new NotificationObserver(notificationObservable->notification2);
|
---|
[63c1f6] | 286 | }
|
---|
| 287 |
|
---|
| 288 | void ObserverTest::tearDown() {
|
---|
[d5f216] | 289 | delete simpleObservable1;
|
---|
| 290 | delete simpleObservable2;
|
---|
[63c1f6] | 291 | delete callObservable;
|
---|
| 292 | delete superObservable;
|
---|
[033a05] | 293 | delete blockObservable;
|
---|
[ccacba] | 294 | delete notificationObservable;
|
---|
[8774c5] | 295 | delete obsset;
|
---|
| 296 | delete obsmap;
|
---|
[63c1f6] | 297 |
|
---|
| 298 | delete observer1;
|
---|
| 299 | delete observer2;
|
---|
| 300 | delete observer3;
|
---|
[d5f216] | 301 | delete observer4;
|
---|
[ccacba] | 302 | delete notificationObserver1;
|
---|
| 303 | delete notificationObserver2;
|
---|
[63c1f6] | 304 | }
|
---|
| 305 |
|
---|
| 306 | void ObserverTest::doesUpdateTest()
|
---|
| 307 | {
|
---|
[d5f216] | 308 | simpleObservable1->signOn(observer1);
|
---|
| 309 | simpleObservable1->signOn(observer2);
|
---|
| 310 | simpleObservable1->signOn(observer3);
|
---|
[9b6b2f] | 311 |
|
---|
[d5f216] | 312 | simpleObservable2->signOn(observer2);
|
---|
| 313 | simpleObservable2->signOn(observer4);
|
---|
[63c1f6] | 314 |
|
---|
[61ea5b] | 315 | CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
|
---|
| 316 | CPPUNIT_ASSERT_EQUAL( 0, observer2->updates );
|
---|
| 317 | CPPUNIT_ASSERT_EQUAL( 0, observer3->updates );
|
---|
| 318 | CPPUNIT_ASSERT_EQUAL( 0, observer4->updates );
|
---|
| 319 |
|
---|
| 320 |
|
---|
[d5f216] | 321 | simpleObservable1->changeMethod();
|
---|
[63c1f6] | 322 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
|
---|
| 323 | CPPUNIT_ASSERT_EQUAL( 1, observer2->updates );
|
---|
| 324 | CPPUNIT_ASSERT_EQUAL( 1, observer3->updates );
|
---|
[d5f216] | 325 | CPPUNIT_ASSERT_EQUAL( 0, observer4->updates );
|
---|
[63c1f6] | 326 |
|
---|
[d5f216] | 327 | simpleObservable1->signOff(observer3);
|
---|
[63c1f6] | 328 |
|
---|
[d5f216] | 329 | simpleObservable1->changeMethod();
|
---|
[63c1f6] | 330 | CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
|
---|
| 331 | CPPUNIT_ASSERT_EQUAL( 2, observer2->updates );
|
---|
| 332 | CPPUNIT_ASSERT_EQUAL( 1, observer3->updates );
|
---|
[d5f216] | 333 | CPPUNIT_ASSERT_EQUAL( 0, observer4->updates );
|
---|
| 334 |
|
---|
| 335 | simpleObservable2->changeMethod();
|
---|
| 336 | CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
|
---|
| 337 | CPPUNIT_ASSERT_EQUAL( 3, observer2->updates );
|
---|
| 338 | CPPUNIT_ASSERT_EQUAL( 1, observer3->updates );
|
---|
| 339 | CPPUNIT_ASSERT_EQUAL( 1, observer4->updates );
|
---|
[63c1f6] | 340 | }
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | void ObserverTest::doesBlockUpdateTest() {
|
---|
| 344 | callObservable->signOn(observer1);
|
---|
[61ea5b] | 345 | CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
|
---|
[63c1f6] | 346 |
|
---|
| 347 | callObservable->changeMethod1();
|
---|
| 348 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
|
---|
| 349 |
|
---|
| 350 | callObservable->changeMethod2();
|
---|
| 351 | CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | void ObserverTest::doesSubObservableTest() {
|
---|
| 355 | superObservable->signOn(observer1);
|
---|
| 356 | superObservable->subObservable->signOn(observer2);
|
---|
| 357 |
|
---|
| 358 | superObservable->subObservable->changeMethod();
|
---|
| 359 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
|
---|
| 360 | CPPUNIT_ASSERT_EQUAL( 1, observer2->updates );
|
---|
| 361 |
|
---|
| 362 | superObservable->changeMethod();
|
---|
| 363 | CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
|
---|
| 364 | CPPUNIT_ASSERT_EQUAL( 2, observer2->updates );
|
---|
| 365 | }
|
---|
| 366 |
|
---|
[61ea5b] | 367 | void ObserverTest::outsideLockTest(){
|
---|
| 368 | callObservable->signOn(observer1);
|
---|
| 369 | CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
|
---|
| 370 |
|
---|
| 371 | {
|
---|
| 372 | LOCK_OBSERVABLE(*callObservable);
|
---|
| 373 | CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
|
---|
| 374 | }
|
---|
| 375 | // lock is gone now, observer should have notified
|
---|
| 376 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[ccacba] | 379 | void ObserverTest::doesNotifyTest(){
|
---|
| 380 | notificationObservable->signOn(notificationObserver1,
|
---|
| 381 | notificationObservable->notification1);
|
---|
| 382 | notificationObservable->signOn(notificationObserver2,
|
---|
| 383 | notificationObservable->notification2);
|
---|
| 384 |
|
---|
| 385 | notificationObservable->operation1();
|
---|
| 386 | CPPUNIT_ASSERT(notificationObserver1->wasNotified);
|
---|
| 387 | CPPUNIT_ASSERT(!notificationObserver2->wasNotified);
|
---|
| 388 |
|
---|
| 389 | notificationObserver1->wasNotified=false;
|
---|
| 390 |
|
---|
| 391 | notificationObservable->operation2();
|
---|
| 392 | CPPUNIT_ASSERT(!notificationObserver1->wasNotified);
|
---|
| 393 | CPPUNIT_ASSERT(notificationObserver2->wasNotified);
|
---|
| 394 |
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[4fb5a3] | 397 | void ObserverTest::doesReportTest(){
|
---|
| 398 | // Actual checks are in the Stub-methods for this
|
---|
| 399 | blockObservable->changeMethod1();
|
---|
| 400 | blockObservable->changeMethod2();
|
---|
| 401 | blockObservable->noChangeMethod();
|
---|
| 402 | }
|
---|
[63c1f6] | 403 |
|
---|
[bd58fb] | 404 | void ObserverTest::iteratorTest(){
|
---|
[a7b761b] | 405 | int i = 0;
|
---|
| 406 | // test the general iterator methods
|
---|
[8774c5] | 407 | for(ObservableSet::iterator iter=obsset->begin(); iter!=obsset->end();++iter){
|
---|
| 408 | CPPUNIT_ASSERT(i< obsset->num);
|
---|
[a7b761b] | 409 | i++;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | i=0;
|
---|
[8774c5] | 413 | for(ObservableSet::const_iterator iter=obsset->begin(); iter!=obsset->end();++iter){
|
---|
| 414 | CPPUNIT_ASSERT(i<obsset->num);
|
---|
[a7b761b] | 415 | i++;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
[8774c5] | 418 | obsset->signOn(observer1);
|
---|
[bd58fb] | 419 | {
|
---|
[a7b761b] | 420 | // we construct this out of the loop, so the iterator dies at the end of
|
---|
| 421 | // the scope and not the end of the loop (allows more testing)
|
---|
[8774c5] | 422 | ObservableSet::iterator iter;
|
---|
| 423 | for(iter=obsset->begin(); iter!=obsset->end(); ++iter){
|
---|
[bd58fb] | 424 | (*iter)->changeMethod();
|
---|
| 425 | }
|
---|
| 426 | // At this point no change should have been propagated
|
---|
| 427 | CPPUNIT_ASSERT_EQUAL( 0, observer1->updates);
|
---|
| 428 | }
|
---|
| 429 | // After the Iterator has died the propagation should take place
|
---|
| 430 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
|
---|
[a7b761b] | 431 |
|
---|
| 432 | // when using a const_iterator no changes should be propagated
|
---|
[8774c5] | 433 | for(ObservableSet::const_iterator iter = obsset->begin(); iter!=obsset->end();++iter);
|
---|
[a7b761b] | 434 | CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
|
---|
[8774c5] | 435 |
|
---|
| 436 | // we need to test the operator-> as well
|
---|
| 437 | obsmap->signOn(observer2);
|
---|
| 438 | {
|
---|
| 439 | // we construct this out of the loop, so the iterator dies at the end of
|
---|
| 440 | // the scope and not the end of the loop (allows more testing)
|
---|
| 441 | ObservableMap::iterator iter;
|
---|
| 442 | for(iter=obsmap->begin(); iter!=obsmap->end(); ++iter){
|
---|
| 443 | iter->second->changeMethod();
|
---|
| 444 | }
|
---|
| 445 | // At this point no change should have been propagated
|
---|
| 446 | CPPUNIT_ASSERT_EQUAL( 0, observer2->updates);
|
---|
| 447 | }
|
---|
| 448 | // After the Iterator has died the propagation should take place
|
---|
| 449 | CPPUNIT_ASSERT_EQUAL( 1, observer2->updates);
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 | obsset->signOff(observer1);
|
---|
| 453 | obsmap->signOff(observer2);
|
---|
[bd58fb] | 454 | }
|
---|
| 455 |
|
---|
[63c1f6] | 456 | void ObserverTest::CircleDetectionTest() {
|
---|
| 457 | cout << endl << "Warning: the next test involved methods that can produce infinite loops." << endl;
|
---|
| 458 | cout << "Errors in this methods can not be checked using the CPPUNIT_ASSERT Macros." << endl;
|
---|
| 459 | cout << "Instead tests are run on these methods to see if termination is assured" << endl << endl;
|
---|
| 460 | cout << "If this test does not complete in a few seconds, kill the test-suite and fix the Error in the circle detection mechanism" << endl;
|
---|
| 461 |
|
---|
[d5f216] | 462 | cout << endl << endl << "The following errors displayed by the observer framework can be ignored" << endl;
|
---|
[63c1f6] | 463 |
|
---|
| 464 | // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE
|
---|
[d5f216] | 465 | simpleObservable1->signOn(simpleObservable1);
|
---|
[7a176b] | 466 | #ifndef NDEBUG
|
---|
[4fb5a3] | 467 | CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
|
---|
[7a176b] | 468 | #else
|
---|
| 469 | simpleObservable1->changeMethod();
|
---|
| 470 | #endif
|
---|
[d5f216] | 471 |
|
---|
| 472 | // more complex test
|
---|
| 473 | simpleObservable1->signOff(simpleObservable1);
|
---|
| 474 | simpleObservable1->signOn(simpleObservable2);
|
---|
| 475 | simpleObservable2->signOn(simpleObservable1);
|
---|
[7a176b] | 476 | #ifndef NDEBUG
|
---|
[4fb5a3] | 477 | CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
|
---|
[7a176b] | 478 | #else
|
---|
| 479 | simpleObservable1->changeMethod();
|
---|
| 480 | #endif
|
---|
| 481 |
|
---|
| 482 |
|
---|
[d5f216] | 483 | simpleObservable1->signOff(simpleObservable2);
|
---|
| 484 | simpleObservable2->signOff(simpleObservable1);
|
---|
[63c1f6] | 485 | // when we reach this line, although we broke the DAG assumption the circle check works fine
|
---|
| 486 | CPPUNIT_ASSERT(true);
|
---|
| 487 | }
|
---|