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 11 #include <iostream> 12 #include <sstream> 13 #include <string> 14 #include "webrtc/libjingle/xmllite/xmlelement.h" 15 #include "webrtc/libjingle/xmpp/util_unittest.h" 16 #include "webrtc/libjingle/xmpp/xmppengine.h" 17 #include "webrtc/base/gunit.h" 18 19 namespace buzz { 20 WriteOutput(const char * bytes,size_t len)21void XmppTestHandler::WriteOutput(const char * bytes, size_t len) { 22 output_ << std::string(bytes, len); 23 } 24 StartTls(const std::string & cname)25void XmppTestHandler::StartTls(const std::string & cname) { 26 output_ << "[START-TLS " << cname << "]"; 27 } 28 CloseConnection()29void XmppTestHandler::CloseConnection() { 30 output_ << "[CLOSED]"; 31 } 32 OnStateChange(int state)33void XmppTestHandler::OnStateChange(int state) { 34 switch (static_cast<XmppEngine::State>(state)) { 35 case XmppEngine::STATE_START: 36 session_ << "[START]"; 37 break; 38 case XmppEngine::STATE_OPENING: 39 session_ << "[OPENING]"; 40 break; 41 case XmppEngine::STATE_OPEN: 42 session_ << "[OPEN]"; 43 break; 44 case XmppEngine::STATE_CLOSED: 45 session_ << "[CLOSED]"; 46 switch (engine_->GetError(NULL)) { 47 case XmppEngine::ERROR_NONE: 48 // do nothing 49 break; 50 case XmppEngine::ERROR_XML: 51 session_ << "[ERROR-XML]"; 52 break; 53 case XmppEngine::ERROR_STREAM: 54 session_ << "[ERROR-STREAM]"; 55 break; 56 case XmppEngine::ERROR_VERSION: 57 session_ << "[ERROR-VERSION]"; 58 break; 59 case XmppEngine::ERROR_UNAUTHORIZED: 60 session_ << "[ERROR-UNAUTHORIZED]"; 61 break; 62 case XmppEngine::ERROR_TLS: 63 session_ << "[ERROR-TLS]"; 64 break; 65 case XmppEngine::ERROR_AUTH: 66 session_ << "[ERROR-AUTH]"; 67 break; 68 case XmppEngine::ERROR_BIND: 69 session_ << "[ERROR-BIND]"; 70 break; 71 case XmppEngine::ERROR_CONNECTION_CLOSED: 72 session_ << "[ERROR-CONNECTION-CLOSED]"; 73 break; 74 case XmppEngine::ERROR_DOCUMENT_CLOSED: 75 session_ << "[ERROR-DOCUMENT-CLOSED]"; 76 break; 77 default: 78 break; 79 } 80 break; 81 default: 82 break; 83 } 84 } 85 HandleStanza(const XmlElement * stanza)86bool XmppTestHandler::HandleStanza(const XmlElement * stanza) { 87 stanza_ << stanza->Str(); 88 return true; 89 } 90 OutputActivity()91std::string XmppTestHandler::OutputActivity() { 92 std::string result = output_.str(); 93 output_.str(""); 94 return result; 95 } 96 SessionActivity()97std::string XmppTestHandler::SessionActivity() { 98 std::string result = session_.str(); 99 session_.str(""); 100 return result; 101 } 102 StanzaActivity()103std::string XmppTestHandler::StanzaActivity() { 104 std::string result = stanza_.str(); 105 stanza_.str(""); 106 return result; 107 } 108 109 } // namespace buzz 110