Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ObserverTest.cpp

    r4fb5a3 r5e5283  
    1313
    1414#include "Patterns/Observer.hpp"
    15 #include "Helpers/Assert.hpp"
    1615
    1716#include <iostream>
     
    6665};
    6766
    68 class BlockObservable : public Observable {
    69 public:
    70   void changeMethod1(){
    71     OBSERVE;
    72     // test if we report correctly as blocked
    73     CPPUNIT_ASSERT(isBlocked());
    74   }
    75 
    76   void changeMethod2(){
    77     OBSERVE;
    78     internalMethod1();
    79     internalMethod2();
    80   }
    81 
    82   void internalMethod1(){
    83     // we did not block, but our caller did...
    84     // see if this is found
    85     CPPUNIT_ASSERT(isBlocked());
    86   }
    87 
    88   void internalMethod2(){
    89     OBSERVE;
    90     // Both this method and the caller do block
    91     // Does the reporting still work as expected?
    92     CPPUNIT_ASSERT(isBlocked());
    93   }
    94 
    95   void noChangeMethod(){
    96     // No Block introduced here
    97     // reported correctely?
    98     CPPUNIT_ASSERT(!isBlocked());
    99   }
    100 };
    101 
    10267class SuperObservable : public Observable {
    10368public:
     
    12186
    12287void ObserverTest::setUp() {
    123   ASSERT_DO(Assert::Throw);
    12488  simpleObservable1 = new SimpleObservable();
    12589  simpleObservable2 = new SimpleObservable();
    12690  callObservable = new CallObservable();
    12791  superObservable = new SuperObservable();
    128   blockObservable = new BlockObservable();
    12992
    13093  observer1 = new UpdateCountObserver();
     
    200163}
    201164
    202 void ObserverTest::doesReportTest(){
    203   // Actual checks are in the Stub-methods for this
    204   blockObservable->changeMethod1();
    205   blockObservable->changeMethod2();
    206   blockObservable->noChangeMethod();
    207 }
    208165
    209166void ObserverTest::CircleDetectionTest() {
     
    217174  // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE
    218175  simpleObservable1->signOn(simpleObservable1);
    219   CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
     176  simpleObservable1->changeMethod();
    220177
    221178  // more complex test
     
    223180  simpleObservable1->signOn(simpleObservable2);
    224181  simpleObservable2->signOn(simpleObservable1);
    225   CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
     182  simpleObservable1->changeMethod();
    226183  simpleObservable1->signOff(simpleObservable2);
    227184  simpleObservable2->signOff(simpleObservable1);
Note: See TracChangeset for help on using the changeset viewer.