source: src/Patterns/Observer/unittests/stubs/ObserverStub.hpp@ d85532

Last change on this file since d85532 was d85532, checked in by Frederik Heber <heber@…>, 14 years ago

Added unit test on Relay.

  • added new stubs to ObserverStub implementing Relay.
  • Relay is friend of Notification.
  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[56d62f]1/*
2 * ObserverStub.hpp
3 *
4 * Created on: Jan 16, 2011
5 * Author: heber
6 */
7
8#ifndef OBSERVERSTUB_HPP_
9#define OBSERVERSTUB_HPP_
10
[e2e035e]11#include "Observer/Observer.hpp"
12#include "Observer/Observable.hpp"
13#include "Observer/ObservedIterator.hpp"
[d85532]14#include "Observer/Relay.hpp"
[56d62f]15
16class UpdateCountObserver : public Observer {
17public:
18 UpdateCountObserver();
[74e0f7]19 virtual ~UpdateCountObserver();
20
[56d62f]21 void update(Observable *publisher);
22 void subjectKilled(Observable *publisher);
23
24 int updates;
25};
26
27class SimpleObservable : public Observable {
28public:
29 SimpleObservable();
30
31 void changeMethod();
32};
33
34class CallObservable : public Observable {
35public:
36 CallObservable();
37
38 void changeMethod1();
39 void changeMethod2();
40};
41
42class BlockObservable : public Observable {
43public:
44 BlockObservable();
45
46 void changeMethod1();
47 void changeMethod2();
48
49 void internalMethod1();
50 void internalMethod2();
51
52 void noChangeMethod();
53};
54
55class SuperObservable : public Observable {
56public:
57 SuperObservable();
[74e0f7]58 virtual ~SuperObservable();
[56d62f]59
60 void changeMethod();
61
62 SimpleObservable *subObservable;
63};
64
65class NotificationObservable : public Observable {
66public:
67 NotificationObservable();
[74e0f7]68 virtual ~NotificationObservable();
69
70 enum NotificationType {
71 Operation1Notify = 0,
72 Operation2Notify = 1
73 };
[56d62f]74
75 void operation1();
76 void operation2();
77};
78
79class NotificationObserver : public Observer {
80public:
81 NotificationObserver(Notification_ptr notification);
[74e0f7]82 virtual ~NotificationObserver();
[56d62f]83
84 void update(Observable*);
85 void subjectKilled(Observable*);
86 void recieveNotification(Observable *publisher, Notification_ptr notification);
87
88 Notification_ptr requestedNotification;
89
90 bool wasNotified;
91};
92
93class ObservableSet : public Observable {
94public:
95 typedef std::set<SimpleObservable*> set;
96 typedef ObservedIterator<set> iterator;
97 typedef set::const_iterator const_iterator;
98
99 ObservableSet(int _num);
[74e0f7]100 virtual ~ObservableSet();
[56d62f]101
102 iterator begin();
103 iterator end();
104
105 const int num;
106
107private:
108 set theSet;
109};
110
111class ObservableMap : public Observable {
112public:
113 typedef std::map<int,SimpleObservable*> set;
114 typedef ObservedIterator<set> iterator;
115 typedef set::const_iterator const_iterator;
116
117 ObservableMap(int _num);
[74e0f7]118 virtual ~ObservableMap();
[56d62f]119
120 iterator begin();
121 iterator end();
122
123 const int num;
124
125private:
126 set theSet;
127};
128
[d85532]129class RelayTest : public Relay
130{
131public:
132 RelayTest();
133 ~RelayTest();
134private:
135};
136
137class RelayCountObserver : public Observer {
138public:
139 RelayCountObserver(const Observable * const relay);
140 virtual ~RelayCountObserver();
141
142 void update(Observable *publisher);
143 void subjectKilled(Observable *publisher);
144
145 int updates;
146private:
147 const Observable * const relay;
148};
[56d62f]149
150#endif /* OBSERVERSTUB_HPP_ */
Note: See TracBrowser for help on using the repository browser.