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