util_unittest.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2004 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. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_UTIL_UNITTEST_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_UTIL_UNITTEST_H_
  12. #include <sstream>
  13. #include <string>
  14. #include "third_party/libjingle_xmpp/xmpp/xmppengine.h"
  15. namespace jingle_xmpp {
  16. // This class captures callbacks from engine.
  17. class XmppTestHandler : public XmppOutputHandler, public XmppSessionHandler,
  18. public XmppStanzaHandler {
  19. public:
  20. explicit XmppTestHandler(XmppEngine* engine) : engine_(engine) {}
  21. virtual ~XmppTestHandler() {}
  22. void SetEngine(XmppEngine* engine);
  23. // Output handler
  24. virtual void WriteOutput(const char * bytes, size_t len);
  25. virtual void StartTls(const std::string & cname);
  26. virtual void CloseConnection();
  27. // Session handler
  28. virtual void OnStateChange(int state);
  29. // Stanza handler
  30. virtual bool HandleStanza(const XmlElement* stanza);
  31. std::string OutputActivity();
  32. std::string SessionActivity();
  33. std::string StanzaActivity();
  34. private:
  35. XmppEngine* engine_;
  36. std::stringstream output_;
  37. std::stringstream session_;
  38. std::stringstream stanza_;
  39. };
  40. } // namespace jingle_xmpp
  41. inline std::ostream& operator<<(std::ostream& os, const jingle_xmpp::Jid& jid) {
  42. os << jid.Str();
  43. return os;
  44. }
  45. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_UTIL_UNITTEST_H_