OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This is mock for delicious testing. | 5 // This is mock for delicious testing. |
6 // It's very primitive, and it would have been better to use gmock, except | 6 // It's very primitive, and it would have been better to use gmock, except |
7 // that gmock is only for linux. | 7 // that gmock is only for linux. |
8 | 8 |
9 #ifndef JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ | 9 #ifndef JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ |
10 #define JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ | 10 #define JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "jingle/notifier/listener/mediator_thread.h" | 15 #include "jingle/notifier/listener/mediator_thread.h" |
16 #include "talk/xmpp/xmppclientsettings.h" | 16 |
17 namespace buzz { | |
18 class XmppClientSettings; | |
19 } | |
17 | 20 |
18 namespace notifier { | 21 namespace notifier { |
19 | 22 |
20 class MockMediatorThread : public MediatorThread { | 23 class MockMediatorThread : public MediatorThread { |
21 public: | 24 public: |
22 MockMediatorThread() : observer_(NULL) { | 25 MockMediatorThread(); |
23 Reset(); | |
24 } | |
25 | 26 |
26 virtual ~MockMediatorThread() {} | 27 virtual ~MockMediatorThread(); |
27 | 28 |
28 void Reset() { | 29 void Reset(); |
29 login_calls = 0; | |
30 logout_calls = 0; | |
31 start_calls = 0; | |
32 subscribe_calls = 0; | |
33 listen_calls = 0; | |
34 send_calls = 0; | |
35 } | |
36 | 30 |
37 virtual void AddObserver(Observer* observer) { | 31 virtual void AddObserver(Observer* observer); |
38 observer_ = observer; | |
39 } | |
40 | 32 |
41 virtual void RemoveObserver(Observer* observer) { | 33 virtual void RemoveObserver(Observer* observer); |
42 observer_ = NULL; | |
43 } | |
44 | 34 |
45 // Overridden from MediatorThread | 35 // Overridden from MediatorThread |
46 virtual void Login(const buzz::XmppClientSettings& settings) { | 36 virtual void Login(const buzz::XmppClientSettings& settings); |
47 login_calls++; | |
48 if (observer_) { | |
49 observer_->OnConnectionStateChange(true); | |
50 } | |
51 } | |
52 | 37 |
53 virtual void Logout() { | 38 virtual void Logout(); |
54 logout_calls++; | |
55 if (observer_) { | |
56 observer_->OnConnectionStateChange(false); | |
57 } | |
58 } | |
59 | 39 |
60 virtual void Start() { | 40 virtual void Start(); |
61 start_calls++; | |
62 } | |
63 | 41 |
64 virtual void SubscribeForUpdates( | 42 virtual void SubscribeForUpdates( |
65 const std::vector<std::string>& subscribed_services_list) { | 43 const std::vector<std::string>& subscribed_services_list); |
66 subscribe_calls++; | |
67 if (observer_) { | |
68 observer_->OnSubscriptionStateChange(true); | |
69 } | |
70 } | |
71 | 44 |
72 virtual void ListenForUpdates() { | 45 virtual void ListenForUpdates(); |
73 listen_calls++; | |
74 } | |
75 | 46 |
76 virtual void SendNotification(const OutgoingNotificationData &) { | 47 virtual void SendNotification(const OutgoingNotificationData &); |
77 send_calls++; | |
78 if (observer_) { | |
79 observer_->OnOutgoingNotification(); | |
80 } | |
81 } | |
82 | 48 |
83 void ReceiveNotification(const IncomingNotificationData& data) { | 49 void ReceiveNotification(const IncomingNotificationData& data); |
84 if (observer_) { | |
85 observer_->OnIncomingNotification(data); | |
86 } | |
87 } | |
88 | 50 |
89 Observer* observer_; | 51 Observer* observer_; |
90 // Intneral State | 52 // Intneral State |
Nico
2011/02/15 21:25:37
*Internal
| |
91 int login_calls; | 53 int login_calls; |
92 int logout_calls; | 54 int logout_calls; |
93 int start_calls; | 55 int start_calls; |
94 int subscribe_calls; | 56 int subscribe_calls; |
95 int listen_calls; | 57 int listen_calls; |
96 int send_calls; | 58 int send_calls; |
97 }; | 59 }; |
98 | 60 |
99 } // namespace notifier | 61 } // namespace notifier |
100 | 62 |
101 #endif // JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ | 63 #endif // JINGLE_NOTIFIER_LISTENER_MEDIATOR_THREAD_MOCK_H_ |
OLD | NEW |