OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 // A fake XmppClient for use in unit tests. | |
12 | |
13 #ifndef WEBRTC_LIBJINGLE_XMPP_FAKEXMPPCLIENT_H_ | |
14 #define WEBRTC_LIBJINGLE_XMPP_FAKEXMPPCLIENT_H_ | |
15 | |
16 #include <algorithm> | |
17 #include <string> | |
18 #include <vector> | |
19 | |
20 #include "webrtc/libjingle/xmpp/xmpptask.h" | |
21 | |
22 namespace buzz { | |
23 | |
24 class XmlElement; | |
25 | |
26 class FakeXmppClient : public XmppTaskParentInterface, | |
27 public XmppClientInterface { | |
28 public: | |
29 explicit FakeXmppClient(rtc::TaskParent* parent) | |
30 : XmppTaskParentInterface(parent) { | |
31 } | |
32 | |
33 // As XmppTaskParentInterface | |
34 virtual XmppClientInterface* GetClient() { | |
35 return this; | |
36 } | |
37 | |
38 virtual int ProcessStart() { | |
39 return STATE_RESPONSE; | |
40 } | |
41 | |
42 // As XmppClientInterface | |
43 virtual XmppEngine::State GetState() const { | |
44 return XmppEngine::STATE_OPEN; | |
45 } | |
46 | |
47 virtual const Jid& jid() const { | |
48 return jid_; | |
49 } | |
50 | |
51 virtual std::string NextId() { | |
52 // Implement if needed for tests. | |
53 return "0"; | |
54 } | |
55 | |
56 virtual XmppReturnStatus SendStanza(const XmlElement* stanza) { | |
57 sent_stanzas_.push_back(stanza); | |
58 return XMPP_RETURN_OK; | |
59 } | |
60 | |
61 const std::vector<const XmlElement*>& sent_stanzas() { | |
62 return sent_stanzas_; | |
63 } | |
64 | |
65 virtual XmppReturnStatus SendStanzaError( | |
66 const XmlElement * pelOriginal, | |
67 XmppStanzaError code, | |
68 const std::string & text) { | |
69 // Implement if needed for tests. | |
70 return XMPP_RETURN_OK; | |
71 } | |
72 | |
73 virtual void AddXmppTask(XmppTask* task, | |
74 XmppEngine::HandlerLevel level) { | |
75 tasks_.push_back(task); | |
76 } | |
77 | |
78 virtual void RemoveXmppTask(XmppTask* task) { | |
79 std::remove(tasks_.begin(), tasks_.end(), task); | |
80 } | |
81 | |
82 // As FakeXmppClient | |
83 void set_jid(const Jid& jid) { | |
84 jid_ = jid; | |
85 } | |
86 | |
87 // Takes ownership of stanza. | |
88 void HandleStanza(XmlElement* stanza) { | |
89 for (std::vector<XmppTask*>::iterator task = tasks_.begin(); | |
90 task != tasks_.end(); ++task) { | |
91 if ((*task)->HandleStanza(stanza)) { | |
92 delete stanza; | |
93 return; | |
94 } | |
95 } | |
96 delete stanza; | |
97 } | |
98 | |
99 private: | |
100 Jid jid_; | |
101 std::vector<XmppTask*> tasks_; | |
102 std::vector<const XmlElement*> sent_stanzas_; | |
103 }; | |
104 | |
105 } // namespace buzz | |
106 | |
107 #endif // WEBRTC_LIBJINGLE_XMPP_FAKEXMPPCLIENT_H_ | |
OLD | NEW |