Ejemplo n.º 1
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty vcard request";
    VCard v;
    t = v.tag();
    if( !t || t->xml() != "<vCard xmlns='" + XMLNS_VCARD_TEMP + "' version='3.0'/>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  name = "VCard/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new VCard() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "vCard", "xmlns", XMLNS_VCARD_TEMP );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const VCard* se = iq.findExtension<VCard>( ExtVCard );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;


  printf( "VCard: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    printf( "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 2
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;

  // -------
  {
    name = "empty tag() test";
    FlexibleOffline::Offline foo;
    if( false )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
  }


  StanzaExtensionFactory sef;
  sef.registerExtension( new FlexibleOffline::Offline() );
  // -------
  {
    name = "FlexibleOffline::Offline/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "offline", "xmlns", XMLNS_OFFLINE );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const FlexibleOffline::Offline* se = iq.findExtension<FlexibleOffline::Offline>( ExtFlexOffline );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  printf( "FlexibleOffline::Offline: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 3
0
int main()
{
  std::string name;
  int fail = 0;
  // -------
  {
  }

  // -------
  {
    name = "PubSub::Manager::PubSub/SEFactory test";
    StanzaExtensionFactory sef;
    sef.registerExtension( new PubSub::Manager::PubSub() );
    Tag* f = new Tag( "iq" );
    new Tag( f, "pubsub", "xmlns", XMLNS_PUBSUB );
    IQ iq( IQ::Get, JID(), "" );
    sef.addExtensions( iq, f );
    const PubSub::Manager::PubSub* se = iq.findExtension<PubSub::Manager::PubSub>( ExtPubSub );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }





  printf( "PubSub::Manager::PubSub: " );
  if( fail )
    fprintf( stderr, "%d test(s) failed\n", fail );
  else
    printf( "OK\n" );

}
Ejemplo n.º 4
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "set role 'none'";
    MUCRoom::MUCAdmin ma( RoleNone, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' role='none'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set role 'visitor'";
    MUCRoom::MUCAdmin ma( RoleVisitor, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' role='visitor'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set role 'participant'";
    MUCRoom::MUCAdmin ma( RoleParticipant, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' role='participant'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set role 'moderator'";
    MUCRoom::MUCAdmin ma( RoleModerator, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' role='moderator'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set affiliation 'none'";
    MUCRoom::MUCAdmin ma( AffiliationNone, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' affiliation='none'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set affiliation 'outcast'";
    MUCRoom::MUCAdmin ma( AffiliationOutcast, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' affiliation='outcast'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set affiliation 'member'";
    MUCRoom::MUCAdmin ma( AffiliationMember, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' affiliation='member'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set affiliation 'owner'";
    MUCRoom::MUCAdmin ma( AffiliationOwner, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' affiliation='owner'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "set affiliation 'admin'";
    MUCRoom::MUCAdmin ma( AffiliationAdmin, "foo", "fooish" );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item nick='foo' affiliation='admin'>"
         "<reason>fooish</reason>"
         "</item></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "request role list: 'participant'";
    MUCRoom::MUCAdmin ma( RequestVoiceList );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item role='participant'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "request role list: 'moderator'";
    MUCRoom::MUCAdmin ma( RequestModeratorList );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item role='moderator'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "request affiliation list: 'outcast'";
    MUCRoom::MUCAdmin ma( RequestBanList );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item affiliation='outcast'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "request affiliation list: 'member'";
    MUCRoom::MUCAdmin ma( RequestMemberList );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item affiliation='member'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "store affiliation list: 'member'";
    MUCListItemList list;
    list.push_back( MUCListItem( JID( "foo@bar" ) ) );
    list.push_back( MUCListItem( JID( "bar@foo" ) ) );
    MUCRoom::MUCAdmin ma( StoreMemberList, list );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item jid='foo@bar' affiliation='member'/>"
         "<item jid='bar@foo' affiliation='member'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "store role list: 'participant'";
    MUCListItemList list;
    list.push_back( MUCListItem( JID( "foo@bar" ) ) );
    list.push_back( MUCListItem( JID( "bar@foo" ) ) );
    MUCRoom::MUCAdmin ma( StoreVoiceList, list );
    t = ma.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_ADMIN + "'>"
         "<item jid='foo@bar' role='participant'/>"
         "<item jid='bar@foo' role='participant'/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "parse member list from Tag";
    Tag q( "query" );
    q.setXmlns( XMLNS_MUC_ADMIN );
    Tag* i = new Tag( &q, "item", "jid", "foo@bar" );
    i->addAttribute( "affiliation", "member" );
    i = new Tag( &q, "item", "jid", "bar@foo" );
    i->addAttribute( "affiliation", "member" );
    MUCRoom::MUCAdmin ma( &q );
    Tag* t = ma.tag();
    if( !t || q != *t )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  name = "MUCRoom::MUCAdmin/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new MUCRoom::MUCAdmin() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "query", "xmlns", XMLNS_MUC_ADMIN );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const MUCRoom::MUCAdmin* se = iq.findExtension<MUCRoom::MUCAdmin>( ExtMUCAdmin );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


  printf( "MUCRoom::MUCAdmin: " );
  if( !fail )
    printf( "OK\n" );
  else
    fprintf( stderr, "%d test(s) failed\n", fail );

  return fail;
}
Ejemplo n.º 5
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty tag() test";
    SHIM shim;
    t = shim.tag();
    if( t )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "headers to tag to headers, part 1/2";
    SHIM::HeaderList hl;
    hl.insert( std::make_pair( "created", "yesterday" ) );
    hl.insert( std::make_pair( "name", "foo" ) );
    SHIM shim( hl );
    t = shim.tag();
    if( t->xml() != "<headers xmlns='"+ XMLNS_SHIM + "'><header name='created'>yesterday</header><header name='name'>foo</header></headers>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }

    name = "headers to tag to headers, part 2/2";
    SHIM s( t );
    if( s.headers() != hl )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  StanzaExtensionFactory sef;
  sef.registerExtension( new SHIM() );
  // -------
  {
    name = "SHIM/SEFactory test";
    Tag* f = new Tag( "message" );
    new Tag( f, "headers", "xmlns", XMLNS_SHIM );
    Message msg( Message::Normal, JID(), "" );
    sef.addExtensions( msg, f );
    const SHIM* se = msg.findExtension<SHIM>( ExtSHIM );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  printf( "SHIM: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 6
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;


  // -------
  {
    name = "empty <amp>";
    AMP a;
    t = a.tag();
    if( t )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "empty <amp>, per-hop = true";
    AMP a( true );
    t = a.tag();
    if( t )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "one rule";
    AMP a;
    a.addRule( new AMP::Rule( "foodate", AMP::ActionDrop ) );
    t = a.tag();
    if( !t || t->xml() != "<amp xmlns='" + XMLNS_AMP + "'>"
                          "<rule condition='expire-at' action='drop' value='foodate'/>"
                          "</amp>" )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "one rule, per-hop = true";
    AMP a( true );
    a.addRule( new AMP::Rule( "foodate", AMP::ActionDrop ) );
    t = a.tag();
    if( !t || t->xml() != "<amp xmlns='" + XMLNS_AMP + "' per-hop='true'>"
         "<rule condition='expire-at' action='drop' value='foodate'/>"
         "</amp>" )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "2 rules, per-hop = true";
    AMP a( true );
    a.addRule( new AMP::Rule( "foodate", AMP::ActionDrop ) );
    a.addRule( new AMP::Rule( AMP::DeliverNone, AMP::ActionDrop ) );
    t = a.tag();
    if( !t || t->xml() != "<amp xmlns='" + XMLNS_AMP + "' per-hop='true'>"
         "<rule condition='expire-at' action='drop' value='foodate'/>"
         "<rule condition='deliver' action='drop' value='none'/>"
         "</amp>" )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "2 rules()";
    AMP a( true );
    a.addRule( new AMP::Rule( "foodate", AMP::ActionDrop ) );
    a.addRule( new AMP::Rule( AMP::DeliverNone, AMP::ActionDrop ) );
    if( a.rules().size() != 2 )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
  }

  // -------
  {
    name = "Tag ctor";
    Tag* q = new Tag( "amp" );
    q->setXmlns( XMLNS_AMP );
    q->addAttribute( "from", "foofrom" );
    q->addAttribute( "to", "footo" );
    q->addAttribute( "status", "notify" );
    q->addAttribute( "per-hop", "true" );
    Tag* r = new Tag( q, "rule" );
    r->addAttribute( "condition", "deliver" );
    r->addAttribute( "action", "error" );
    r->addAttribute( "value", "forward" );
    AMP a( q );
    t = a.tag();
    if( *t != *q )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
    delete q;
    q = 0;
  }

  // -------
  name = "AMP/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new AMP() );
  Tag* f = new Tag( "message" );
  new Tag( f, "amp", "xmlns", XMLNS_AMP );
  Message msg( Message::Normal, JID() );
  sef.addExtensions( msg, f );
  const AMP* se = msg.findExtension<AMP>( ExtAMP );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;


  if( fail == 0 )
  {
    printf( "AMP: OK\n" );
    return 0;
  }
  else
  {
    printf( "AMP: %d test(s) failed\n", fail );
    return 1;
  }

}
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag* t = 0;

  // -------
  {
    name = "presence broadcast";
    Tag* x = new Tag( "x" );
    x->setXmlns( XMLNS_MUC_USER );
    Tag* i = new Tag( x, "item" );
    i->addAttribute( "jid", "foo@bar" );
    i->addAttribute( "role", "participant" );
    i->addAttribute( "affiliation", "member" );
    MUCRoom::MUCUser mu( x );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
                          "<item jid='foo@bar' role='participant' affiliation='member'/>"
                          "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete x;
  }


  // -------
  {
    name = "presence broadcast incl status codes";
    Tag* x = new Tag( "x" );
    x->setXmlns( XMLNS_MUC_USER );
    Tag* i = new Tag( x, "item" );
    i->addAttribute( "jid", "foo@bar" );
    i->addAttribute( "role", "participant" );
    i->addAttribute( "affiliation", "member" );
    new Tag( i, "actor", "jid", "foojid" );
    new Tag( x, "status", "code", "100" );
    new Tag( x, "status", "code", "101" );
    new Tag( x, "status", "code", "110" );
    new Tag( x, "status", "code", "170" );
    new Tag( x, "status", "code", "201" );
    new Tag( x, "status", "code", "210" );
    new Tag( x, "status", "code", "301" );
    new Tag( x, "status", "code", "303" );
    new Tag( x, "status", "code", "307" );
    new Tag( x, "status", "code", "321" );
    new Tag( x, "status", "code", "322" );
    new Tag( x, "status", "code", "332" );
    MUCRoom::MUCUser mu( x );
    t = mu.tag();
    if( !t || *t != *x )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:\n%s\n%s\n", name.c_str(), x->xml().c_str(), t->xml().c_str() );
    }
    delete t;
    delete x;
  }

  // -------
  {
    name = "inviting someone";
    MUCRoom::MUCUser mu( MUCRoom::OpInviteTo, "foo@bar", "why not?", "somethread" );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<invite to='foo@bar'>"
         "<reason>why not?</reason>"
         "<continue thread='somethread'/>"
         "</invite>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "being invited";
    MUCRoom::MUCUser mu( MUCRoom::OpInviteFrom, "foo@bar", "why not?", "somethread" );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<invite from='foo@bar'>"
         "<reason>why not?</reason>"
         "<continue thread='somethread'/>"
         "</invite>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "parse invitation";
    Tag* x = new Tag( "x" );
    x->setXmlns( XMLNS_MUC_USER );
    Tag* i = new Tag( x, "invite" );
    i->addAttribute( "to", "foo@bar" );
    new Tag( i, "reason", "why not?" );
    new Tag( i, "continue", "thread", "somethread" );
    new Tag( x, "password", "foopwd" );
    MUCRoom::MUCUser mu( x );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<invite to='foo@bar'>"
         "<reason>why not?</reason>"
         "<continue thread='somethread'/>"
         "</invite>"
         "<password>foopwd</password>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete x;
  }

  // -------
  {
    name = "decline invitation";
    MUCRoom::MUCUser mu( MUCRoom::OpDeclineTo, "bar@foo", "because." );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<decline to='bar@foo'>"
         "<reason>because.</reason>"
         "</decline>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "decline invitation";
    MUCRoom::MUCUser mu( MUCRoom::OpDeclineFrom, "bar@foo", "because." );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<decline from='bar@foo'>"
         "<reason>because.</reason>"
         "</decline>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "parse decline";
    Tag* x = new Tag( "x" );
    x->setXmlns( XMLNS_MUC_USER );
    Tag* i = new Tag( x, "decline" );
    i->addAttribute( "from", "foo@bar" );
    new Tag( i, "reason", "because." );
    MUCRoom::MUCUser mu( x );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<decline from='foo@bar'>"
         "<reason>because.</reason>"
         "</decline>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete x;
  }

  // -------
  {
    // this is for parsing incoming stanzas only.
    // for actively destroying a room (as the owner), see MUCOwner
    name = "destroying a room";
    Tag* x = new Tag( "x" );
    x->setXmlns( XMLNS_MUC_USER );
    Tag* d = new Tag( x, "destroy" );
    d->addAttribute( "jid", "foo@bar" );
    new Tag( d, "reason", "fooreason" );
    MUCRoom::MUCUser mu( x );
    t = mu.tag();
    if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC_USER + "'>"
         "<destroy jid='foo@bar'>"
         "<reason>fooreason</reason>"
         "</destroy>"
         "</x>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete x;
  }

  // -------
  {
    name = "MUCRoom::MUCUser/SEFactory test (message)";
    StanzaExtensionFactory sef;
    sef.registerExtension( new MUCRoom::MUCUser() );
    Tag* f = new Tag( "message" );
    new Tag( f, "x", "xmlns", XMLNS_MUC_USER );
    Message msg( Message::Groupchat, JID(), "" );
    sef.addExtensions( msg, f );
    const MUCRoom::MUCUser* se = msg.findExtension<MUCRoom::MUCUser>( ExtMUCUser );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }

  // -------
  {
    name = "MUCRoom::MUCUser/SEFactory test (presence)";
    StanzaExtensionFactory sef;
    sef.registerExtension( new MUCRoom::MUCUser() );
    Tag* f = new Tag( "presence" );
    new Tag( f, "x", "xmlns", XMLNS_MUC_USER );
    Presence pres( Presence::Available, JID(), "" );
    sef.addExtensions( pres, f );
    const MUCRoom::MUCUser* se = pres.findExtension<MUCRoom::MUCUser>( ExtMUCUser );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  printf( "MUCRoom::MUCUser: "******"OK\n" );
  else
    fprintf( stderr, "%d test(s) failed\n", fail );

  return fail;
}
Ejemplo n.º 8
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;
  OOB *d;

  // -------
  name = "parsing 0 tag";
  d = new OOB( 0 );
  if( d->tag() != 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------------------
  // jabber:x:oob tests
  // -------------------
  Tag *x = new Tag( "x" );
  x->addAttribute( "xmlns", XMLNS_X_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", false );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", false );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;


  // -------------------
  // jabber:iq:oob tests
  // -------------------

  delete x;
  x  = 0;
  x = new Tag( "query" );
  x->addAttribute( "xmlns", XMLNS_IQ_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", true );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", true );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;


  delete x;
  x = 0;


  StanzaExtensionFactory sef;

  // -------
  name = "OOB/SEFactory test";
  OOB* oob = new OOB( 0 ); // deleted by StanzaExtensionFactory sef;
  sef.registerExtension( oob );
  Tag* f = new Tag( "iq" );
  Tag* b = new Tag( f, "query", "xmlns", XMLNS_IQ_OOB );
  new Tag( b, "url", "url" );
  new Tag( b, "desc", "desc" );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const OOB* se = iq.findExtension<OOB>( ExtOOB );
  if( se == 0 || se->url() != "url" || se->desc() != "desc" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


  if( fail == 0 )
  {
    printf( "OOB: OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "OOB: %d test(s) failed\n", fail );
    return 1;
  }

}
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "create Tag";
    UniqueMUCRoom::Unique uq;
    t = uq.tag();
    if( !t || t->xml() != "<unique xmlns='" + XMLNS_MUC_UNIQUE + "'/>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "parse Tag";
    Tag u( "unique" );
    u.setXmlns( XMLNS_MUC_UNIQUE );
    u.setCData( "foo" );
    UniqueMUCRoom::Unique uq( &u );
    t = uq.tag();
    if( !t || t->xml() != "<unique xmlns='" + XMLNS_MUC_UNIQUE + "'>"
                          "foo</unique>"
       || uq.name() != "foo" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  name = "UniqueMUCRoom::Unique/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new UniqueMUCRoom::Unique() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "unique", "xmlns", XMLNS_MUC_UNIQUE );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const UniqueMUCRoom::Unique* se = iq.findExtension<UniqueMUCRoom::Unique>( ExtMUCUnique );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;


  printf( "UniqueMUCRoom::Unique: " );
  if( !fail )
    printf( "OK\n" );
  else
    printf( "%d test(s) failed\n", fail );

  return fail;
}
Ejemplo n.º 10
0
int main( int /*argc*/, char** /*argv*/ )
{
    int fail = 0;
    std::string name;
    Tag *t;


    // -------
    {
        name = "request roster";
        RosterManager::Query rq;
        t = rq.tag();
        if( t->xml() != "<query xmlns='" + XMLNS_ROSTER + "'/>" )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
        }
        delete t;
        t = 0;
    }

    // -------
    {
        name = "add/update item";
        StringList sl;
        sl.push_back( "group1" );
        sl.push_back( "group2" );
        RosterManager::Query rq( JID( "foof" ), "name", sl );
        t = rq.tag();
        if( t->xml() != "<query xmlns='" + XMLNS_ROSTER + "'>"
                "<item jid='foof' name='name'>"
                "<group>group1</group>"
                "<group>group2</group>"
                "</item></query>" )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
        }
        delete t;
        t = 0;
    }

    // -------
    {
        name = "remove item";
        RosterManager::Query rq( JID( "foof" ) );
        t = rq.tag();
        if( t->xml() != "<query xmlns='" + XMLNS_ROSTER + "'>"
                "<item jid='foof' subscription='remove'/>"
                "</query>" )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
        }
        delete t;
        t = 0;
    }

    // -------
    {
        name = "initial roster";
        Tag* q = new Tag( "query" );
        q->setXmlns( XMLNS_ROSTER );
        Tag* i = new Tag( q, "item", "jid", "foo1" );
        i->addAttribute( "name", "name1" );
        i->addAttribute( "subscription", "from" );
        i = new Tag( q, "item", "jid", "foo2" );
        i->addAttribute( "name", "name2" );
        i->addAttribute( "subscription", "both" );
        RosterManager::Query rq( q );
        t = rq.tag();
        if( *t != *q || rq.roster().size() != 2 )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
        }
        delete t;
        t = 0;
        delete q;
    }

    // -------
    {
        name = "roster push";
        Tag* q = new Tag( "query" );
        q->setXmlns( XMLNS_ROSTER );
        Tag* i = new Tag( q, "item", "jid", "foo1" );
        i->addAttribute( "name", "name1" );
        i->addAttribute( "subscription", "from" );
        new Tag( i, "group", "group1" );
        new Tag( i, "group", "group2" );
        RosterManager::Query rq( q );
        t = rq.tag();
        if( *t != *q )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
            printf( "     got: %s\n", t->xml().c_str() );
            printf( "expected: %s\n", q->xml().c_str() );
        }
        delete t;
        t = 0;
        delete q;
    }


    // -------
    name = "RosterManager::Query/SEFactory test";
    StanzaExtensionFactory sef;
    sef.registerExtension( new RosterManager::Query() );
    Tag* f = new Tag( "iq" );
    new Tag( f, "query", "xmlns", XMLNS_ROSTER );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const RosterManager::Query* se = iq.findExtension<RosterManager::Query>( ExtRoster );
    if( se == 0 )
    {
        ++fail;
        printf( "test '%s' failed\n", name.c_str() );
    }
    delete f;


    if( fail == 0 )
    {
        printf( "RosterManager::Query: OK\n" );
        return 0;
    }
    else
    {
        printf( "RosterManager::Query: %d test(s) failed\n", fail );
        return 1;
    }

}
Ejemplo n.º 11
0
             int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty tag() test";
    FeatureNeg fn;
    t = fn.tag();
    if( t )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "tag() test";
    FeatureNeg fn( new DataForm( TypeForm ) );
    t = fn.tag();
    if( !t || t->xml() != "<feature xmlns='" + XMLNS_FEATURE_NEG + "'>"
                          "<x xmlns='" + XMLNS_X_DATA + "' type='form'/>"
                          "</feature>" )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    // t re-used in next test
  }

  // -------
  {
    name = "parse tag";
    FeatureNeg fn( t ); // re-using t from previous test
    Tag* t2 = fn.tag();
    if( !t2 || *t2 != *t )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t2;
    delete t;
    t = 0;
  }

  // -------
  name = "FeatureNeg/SEFactory test (IQ)";
  StanzaExtensionFactory sef;
  sef.registerExtension( new FeatureNeg() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "feature", "xmlns", XMLNS_FEATURE_NEG );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const FeatureNeg* se = iq.findExtension<FeatureNeg>( ExtFeatureNeg );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;

  // -------
  name = "FeatureNeg/SEFactory test (Message)";
  f = new Tag( "message" );
  new Tag( f, "feature", "xmlns", XMLNS_FEATURE_NEG );
  Message msg( Message::Normal, JID() );
  sef.addExtensions( msg, f );
  se = msg.findExtension<FeatureNeg>( ExtFeatureNeg );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;

  if( fail == 0 )
  {
    printf( "FeatureNeg: OK\n" );
    return 0;
  }
  else
  {
    printf( "FeatureNeg: %d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 12
0
TEST(Gloox, LastActivityQuery)
{
  int fail = 0;
  std::string name;

  // -------
  {
    name = "empty tag() test";
    LastActivity::Query laq;
    if( false )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
  }

  // -------
  {
    name = "parse test";
    Tag* t = new Tag( "query" );
    t->setXmlns( XMLNS_LAST );
    t->addAttribute( "seconds", "123" );
    t->setCData( "foo" );
    LastActivity::Query laq( t );
    if( laq.seconds() != 123 || laq.status() != "foo" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }

  // -------
    name = "tag() test"; // uses t from previous test
    Tag* s = laq.tag();
    if( *t != *s )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete s;
  }




  StanzaExtensionFactory sef;
  sef.registerExtension( new LastActivity::Query() );
  // -------
  {
    name = "LastActivity::Query/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "query", "xmlns", XMLNS_LAST );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const LastActivity::Query* se = iq.findExtension<LastActivity::Query>( ExtLastActivity );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


EXPECT_EQ(0, fail);

//printf( "LastActivity::Query: " );
//    if( fail == 0 )
//  {
//    printf( "OK\n" );
//    return 0;
//  }
//  else
//  {
//    fprintf( stderr, "%d test(s) failed\n", fail );
//    return 1;
//  }

}
Ejemplo n.º 13
0
int main( int /*argc*/, char** /*argv*/ )
{
    int fail = 0;
    std::string name;
    Tag* t = 0;


    // -------
    {
        name = "joining a room";
        MUCRoom::MUC mu;
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'/>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "joining a password-protected room";
        MUCRoom::MUC mu( "foopwd" );
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'>"
                "<password>foopwd</password>"
                "</x>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "joining room, requesting room history 1";
        MUCRoom::MUC mu( EmptyString, MUCRoom::HistorySince, "foodate" );
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'>"
                "<history since='foodate'/>"
                "</x>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "joining room, requesting room history 2";
        MUCRoom::MUC mu( EmptyString, MUCRoom::HistoryMaxChars, EmptyString, 100 );
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'>"
                "<history maxchars='100'/>"
                "</x>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "joining room, requesting room history 3";
        MUCRoom::MUC mu( EmptyString, MUCRoom::HistoryMaxStanzas, EmptyString, 100 );
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'>"
                "<history maxstanzas='100'/>"
                "</x>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "joining room, requesting room history 4 + password";
        MUCRoom::MUC mu( "foopwd", MUCRoom::HistorySeconds, EmptyString, 100 );
        t = mu.tag();
        if( !t || t->xml() != "<x xmlns='" + XMLNS_MUC + "'>"
                "<history seconds='100'/>"
                "<password>foopwd</password>"
                "</x>" )
        {
            ++fail;
            printf( "test '%s' failed:%s \n", name.c_str(), t->xml().c_str() );
        }
        delete t;
    }

    // -------
    {
        name = "MUCRoom::MUC/SEFactory test (presence)";
        StanzaExtensionFactory sef;
        sef.registerExtension( new MUCRoom::MUC() );
        Tag* f = new Tag( "presence" );
        new Tag( f, "x", "xmlns", XMLNS_MUC );
        Presence pres( Presence::Available, JID(), "" );
        sef.addExtensions( pres, f );
        const MUCRoom::MUC* se = pres.findExtension<MUCRoom::MUC>( ExtMUC );
        if( se == 0 )
        {
            ++fail;
            printf( "test '%s' failed\n", name.c_str() );
        }
        delete f;
    }


    printf( "MUCRoom::MUC: " );
    if( !fail )
        printf( "OK\n" );
    else
        printf( "%d test(s) failed\n", fail );

    return fail;
}
Ejemplo n.º 14
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;


  // -------
  {
    name = "execute specific command";
    Adhoc::Command ac( "somecmd", Adhoc::Command::Execute );
    t = ac.tag();
    if( t->xml() != "<command xmlns='" + XMLNS_ADHOC_COMMANDS + "' node='somecmd' action='execute'/>"
        || ac.node() != "somecmd" || ac.action() != Adhoc::Command::Execute )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "execute specific command /w session";
    Adhoc::Command ac( "somecmd", "somesession", Adhoc::Command::Execute );
    t = ac.tag();
    if( t->xml() != "<command xmlns='" + XMLNS_ADHOC_COMMANDS + "' node='somecmd' action='execute' sessionid='somesession'/>"
        || ac.node() != "somecmd" || ac.sessionID() != "somesession"
        || ac.action() != Adhoc::Command::Execute )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "Tag ctor";
    t = new Tag( "command" );
    t->setXmlns( XMLNS_ADHOC_COMMANDS );
    t->addAttribute( "node", "somecmd" );
    t->addAttribute( "sessionid", "somesession" );
    t->addAttribute( "action", "execute" );
    Tag* f = new Tag( t, "x" );
    f->setXmlns( XMLNS_X_DATA );
    Adhoc::Command ac( t );
    if( ac.node() != "somecmd" || ac.sessionID() != "somesession"
        || ac.action() != Adhoc::Command::Execute || ac.form() == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  name = "Adhoc::Command/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new Adhoc::Command( "foo", Adhoc::Command::Execute) );
  Tag* f = new Tag( "iq" );
  new Tag( f, "command", "xmlns", XMLNS_ADHOC_COMMANDS );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const Adhoc::Command* se = iq.findExtension<Adhoc::Command>( ExtAdhocCommand );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


  if( fail == 0 )
  {
    printf( "Adhoc::Command: OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "Adhoc::Command: %d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 15
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "request config form";
    MUCRoom::MUCOwner mo( MUCRoom::MUCOwner::TypeRequestConfig );
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "submit config form";
    MUCRoom::MUCOwner mo( MUCRoom::MUCOwner::TypeSendConfig, new DataForm( /*DataForm::*/TypeForm ) );
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'>"
                            "<x xmlns='" + XMLNS_X_DATA + "' type='form'/>"
                          "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "cancel initial room config";
    MUCRoom::MUCOwner mo( MUCRoom::MUCOwner::TypeCancelConfig );
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'>"
                            "<x xmlns='" + XMLNS_X_DATA + "' type='cancel'/>"
                          "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // ------
  {
    name = "request instant room";
    MUCRoom::MUCOwner mo( MUCRoom::MUCOwner::TypeInstantRoom );
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'>"
                            "<x xmlns='" + XMLNS_X_DATA + "' type='submit'/>"
                          "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // ------
  {
    name = "destroy room";
    MUCRoom::MUCOwner mo( JID( "foo" ), "foobar", "foopwd" );
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'>"
                            "<destroy jid='foo'>"
                              "<reason>foobar</reason>"
                              "<password>foopwd</password>"
                            "</destroy></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // ------
  {
    name = "destroy room w/o alternate venue";
    MUCRoom::MUCOwner mo;
    t = mo.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_MUC_OWNER + "'>"
         "<destroy/></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // ------
  {
    name = "from Tag: request room config";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_MUC_OWNER );
    MUCRoom::MUCOwner mo( d );
    t = mo.tag();
    if( !t || *t != *d )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }

  // ------
  {
    name = "from Tag: destroy room";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_MUC_OWNER );
    Tag* destroy = new Tag( d, "destroy" );
    destroy->addAttribute( "jid", "alternate" );
    new Tag( destroy, "reason", "reason" );
    new Tag( destroy, "password", "pwd" );
    MUCRoom::MUCOwner mo( d );
    t = mo.tag();
    if( !t || *t != *d )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  name = "MUCRoom::MUCOwner/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new MUCRoom::MUCOwner() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "query", "xmlns", XMLNS_MUC_OWNER );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const MUCRoom::MUCOwner* se = iq.findExtension<MUCRoom::MUCOwner>( ExtMUCOwner );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


  printf( "MUCRoom::MUCOwner: " );
  if( !fail )
    printf( "OK\n" );
  else
    fprintf( stderr, "%d test(s) failed\n", fail );

  return fail;
}
Ejemplo n.º 16
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty tag() test";
    Receipt r( Receipt::Invalid );
    t = r.tag();
    if( t )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "request";
    Receipt r( Receipt::Request );
    t = r.tag();
    if( t->xml() != "<request xmlns='"+ XMLNS_RECEIPTS + "'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "received";
    Receipt r( Receipt::Received );
    t = r.tag();
    if( t->xml() != "<received xmlns='"+ XMLNS_RECEIPTS + "'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  StanzaExtensionFactory sef;
  sef.registerExtension( new Receipt( Receipt::Invalid ) );
  // -------
  {
    name = "Receipt::Request/SEFactory test";
    Tag* f = new Tag( "message" );
    new Tag( f, "request", "xmlns", XMLNS_RECEIPTS );
    Message msg( Message::Normal, JID(), "" );
    sef.addExtensions( msg, f );
    const Receipt* se = msg.findExtension<Receipt>( ExtReceipt );
    if( se == 0 || se->rcpt() != Receipt::Request )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }

  // -------
  {
    name = "Receipt::Received/SEFactory test";
    Tag* f = new Tag( "message" );
    new Tag( f, "received", "xmlns", XMLNS_RECEIPTS );
    Message msg( Message::Normal, JID(), "" );
    sef.addExtensions( msg, f );
    const Receipt* se = msg.findExtension<Receipt>( ExtReceipt );
    if( se == 0 || se->rcpt() != Receipt::Received )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }

  printf( "Receipt: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 17
0
int main_test1( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag* t = 0;


  // -------
  {
    name = "field request";
    NonSaslAuth::Query q( "user" );
    t = q.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
                          "<username>user</username></query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "reply w/ pwd";
    Tag* q = new Tag( "query" );
    q->setXmlns( XMLNS_AUTH );
    new Tag( q, "username" );
    new Tag( q, "password" );
    new Tag( q, "resource" );
    NonSaslAuth::Query n( q );
    NonSaslAuth::Query* nq = n.newInstance( "user", "sid", "pwd", "resource" );
    t = nq->tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
                          "<username>user</username>"
                          "<password>pwd</password>"
                          "<resource>resource</resource>"
                          "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete nq;
    delete q;
    delete t;
    t = 0;
  }

  // -------
  {
    name = "reply w/ digest";
    Tag* q = new Tag( "query" );
    q->setXmlns( XMLNS_AUTH );
    new Tag( q, "username" );
    new Tag( q, "password" );
    new Tag( q, "digest" );
    new Tag( q, "resource" );
    NonSaslAuth::Query n( q );
    NonSaslAuth::Query* nq = n.newInstance( "user", "sid", "pwd", "resource" );
    SHA sha;
    sha.feed( "sid" );
    sha.feed( "pwd" );
    t = nq->tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
         "<username>user</username>"
         "<digest>" + sha.hex() + "</digest>"
         "<resource>resource</resource>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete nq;
    delete q;
    delete t;
    t = 0;
  }

  // -------
  {
    StanzaExtensionFactory sef;
    sef.registerExtension( new NonSaslAuth::Query() );
    name = "NonSaslAuth::Query/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "query", "xmlns", XMLNS_AUTH );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const NonSaslAuth::Query* se = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
    if( se == 0 )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  if( fail == 0 )
  {
    printf( "NonSaslAuth::Query: OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "NonSaslAuth::Query: %d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 18
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  JID jid( "foo@bar/barfoo" );

  // -------
  {
    name = "invalid Jingle 1";
    Jingle::Session::Jingle js;
    Tag* t = js.tag();
    if( t )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "invalid Jingle 2";
    Jingle::Session::Jingle js( Jingle::SessionAccept, JID(), JID(), 0, "" );
    Tag* t = js.tag();
    if( t )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, content-accept";
    Jingle::Session::Jingle js( Jingle::ContentAccept, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='content-accept' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, content-add";
    Jingle::Session::Jingle js( Jingle::ContentAdd, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='content-add' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, content-modify";
    Jingle::Session::Jingle js( Jingle::ContentModify, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='content-modify' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, content-reject";
    Jingle::Session::Jingle js( Jingle::ContentReject, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='content-reject' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, content-remove";
    Jingle::Session::Jingle js( Jingle::ContentRemove, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='content-remove' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, description-info";
    Jingle::Session::Jingle js( Jingle::DescriptionInfo, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='description-info' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, session-accept";
    Jingle::Session::Jingle js( Jingle::SessionAccept, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='session-accept' responder='foo@bar/barfoo' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, session-info";
    Jingle::Session::Jingle js( Jingle::SessionInfo, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='session-info' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, session-initiate";
    Jingle::Session::Jingle js( Jingle::SessionInitiate, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='session-initiate' initiator='foo@bar/barfoo' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, session-terminate";
    Jingle::Session::Jingle js( Jingle::SessionTerminate, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='session-terminate' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, transport-accept";
    Jingle::Session::Jingle js( Jingle::TransportAccept, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='transport-accept' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, transport-info";
    Jingle::Session::Jingle js( Jingle::TransportInfo, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='transport-info' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, transport-reject";
    Jingle::Session::Jingle js( Jingle::TransportReject, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='transport-reject' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "empty Jingle, transport-replace";
    Jingle::Session::Jingle js( Jingle::TransportReplace, jid, jid, 0, "somesid" );
    Tag* t = js.tag();
    if( !t || t->xml() != "<jingle xmlns='" + XMLNS_JINGLE + "' "
      "action='transport-replace' sid='somesid'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
  }




  // -------
  name = "Jingle::Session::Jingle/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new Jingle::Session::Jingle() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "jingle", "xmlns", XMLNS_JINGLE );
  IQ iq( IQ::Get, JID() );
  sef.addExtensions( iq, f );
  const Jingle::Session::Jingle* se = iq.findExtension<Jingle::Session::Jingle>( ExtJingle );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;



  if( fail == 0 )
  {
    printf( "Jingle::Session::Jingle: OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "Jingle::Session::Jingle: %d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 19
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty disco#info request";
    Disco::Info di;
    t = di.tag();
    if( t->xml() != "<query xmlns='" + XMLNS_DISCO_INFO + "'/>"
        || !di.node().empty() )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "empty (default) disco#info reply";
    Disco::Info di( EmptyString, true );
    t = di.tag();
    if( t->xml() != "<query xmlns='" + XMLNS_DISCO_INFO + "'>"
                    "<feature var='" + XMLNS_DISCO_INFO + "'/>"
                    "<feature var='" + XMLNS_DISCO_ITEMS + "'/>"
        "</query>"
        || !di.node().empty() )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "empty disco#info request + node + default features";
    Disco::Info di( "somenode", true );
    t = di.tag();
    if( t->xml() != "<query xmlns='" + XMLNS_DISCO_INFO + "' node='somenode'>"
                    "<feature var='" + XMLNS_DISCO_INFO + "'/>"
                    "<feature var='" + XMLNS_DISCO_ITEMS + "'/>"
                    "</query>"
        || di.node() != "somenode" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "empty disco#info request + node - default features";
    Disco::Info di( "somenode" );
    t = di.tag();
    if( t->xml() != "<query xmlns='" + XMLNS_DISCO_INFO + "' node='somenode'/>"
        || di.node() != "somenode" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "setnode()";
    Disco::Info di( "somenode" );
    di.setNode( "othernode" );
    if( di.node() != "othernode" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
  }

  // -------
  {
    name = "Tag ctor";
    t = new Tag( "query" );
    t->setXmlns( XMLNS_DISCO_INFO );
    t->addAttribute( "node", "somenode" );
    Tag* i = new Tag( t, "identity", "category", "category1" );
    i->addAttribute( "type", "type1" );
    i->addAttribute( "name", "name1" );
    i = new Tag( t, "identity", "category", "category2" );
    i->addAttribute( "type", "type1" );
    i->addAttribute( "name", "name1" );
    i = new Tag( t, "identity", "category", "category3" );
    i->addAttribute( "type", "type1" );
    i->addAttribute( "name", "name1" );
    new Tag( t, "feature", "var", "foo1" );
    new Tag( t, "feature", "var", "foo2" );
    new Tag( t, "feature", "var", "foo3" );
    Disco::Info di( t );
    if( di.node() != "somenode" || di.identities().size() != 3 || di.features().size() != 3
        || !di.hasFeature( "foo1" ) || !di.hasFeature( "foo2" ) || !di.hasFeature( "foo3" ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  name = "Disco::Info/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new Disco::Info() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "query", "xmlns", XMLNS_DISCO_INFO );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const Disco::Info* se = iq.findExtension<Disco::Info>( ExtDiscoInfo );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


  if( fail == 0 )
  {
    printf( "Disco::Info: OK\n" );
    return 0;
  }
  else
  {
    fprintf( stderr, "Disco::Info: %d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 20
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty tag() test";
    SIManager::SI si;
    t = si.tag();
    if( t )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "full ctor";
    Tag* t1 = new Tag( "foo" );
    Tag* t2 = new Tag( "bar" );
    SIManager::SI si( t1, t2, "id", "mime", "prof" );
    t = si.tag();
    if( !t || t->name() != "si" || t->xmlns() != XMLNS_SI
        || !t->hasAttribute( "id", "id" )
        || !t->hasAttribute( "mime-type", "mime" )
        || !t->hasAttribute( "profile", "prof" )
        || !t->hasChild( "foo" )
        || !t->hasChild( "bar" ) )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "tag ctor";
    Tag* s = new Tag( "si" );
    s->setXmlns( XMLNS_SI );
    s->addAttribute( "id", "id" );
    s->addAttribute( "mime-type", "mime" );
    s->addAttribute( "profile", "prof" );
    Tag* f1 = new Tag( s, "file" );
    f1->setXmlns( XMLNS_SI_FT );
    Tag* f2 = new Tag( s, "feature" );
    f2->setXmlns( XMLNS_FEATURE_NEG );

    SIManager::SI si( s );
    t = si.tag();
    if( !t || *t != *s )
    {
      ++fail;
      printf( "test '%s' failed:\n%s\n%s\n", name.c_str(), t->xml().c_str(), s->xml().c_str() );
    }
    delete s;
    delete t;
    t = 0;
  }

  StanzaExtensionFactory sef;
  sef.registerExtension( new SIManager::SI() );
  // -------
  {
    name = "SIManager::SI/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "si", "xmlns", XMLNS_SI );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const SIManager::SI* se = iq.findExtension<SIManager::SI>( ExtSI );
    if( se == 0 )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  printf( "SIManager::SI: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    printf( "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 21
0
TEST(Gloox, RegistrationQuery)
{
  int fail = 0;
  std::string name;

  // -------
  {
    name = "fetch reg fields";
    Registration::Query sq;
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "receive reg fields";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_REGISTER );
    new Tag( d, "instructions", "foobar" );
    new Tag( d, "username" );
    new Tag( d, "password" );
    new Tag( d, "email" );
    Registration::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<instructions>foobar</instructions>"
         "<username/>"
         "<password/>"
         "<email/>"
         "</query>"
         || sq.instructions() != "foobar"
         || sq.fields() != ( Registration::FieldUsername | Registration::FieldPassword
                             | Registration::FieldEmail ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  {
    name = "reg by fields";
    RegistrationFields rf;
    rf.username = "******";
    rf.password = "******";
    rf.email = "email";
    Registration::Query sq( Registration::FieldUsername | Registration::FieldPassword
                            | Registration::FieldEmail, rf );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<username>foo</username>"
         "<password>bar</password>"
         "<email>email</email>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "receive search form";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_REGISTER );
    Tag* f = new Tag( d, "x" );
    f->setXmlns( XMLNS_X_DATA );
    f->addAttribute( "type", "form" );
    Registration::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<x xmlns='" + XMLNS_X_DATA + "' type='form'/>"
         "</query>"
         || !sq.form() )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  {
    name = "reg by form";
    DataForm* form = new DataForm( TypeSubmit );
    Registration::Query sq( form );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
       "<x xmlns='" + XMLNS_X_DATA + "' type='submit'/>"
       "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "remove account";
    Registration::Query sq( true );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<remove/>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "change password";
    RegistrationFields rf;
    rf.username = "******";
    rf.password = "******";
    Registration::Query sq( Registration::FieldUsername | Registration::FieldPassword, rf );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<username>foobar</username>"
         "<password>newpwd</password>"
         "</query>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "redirection";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_REGISTER );
    new Tag( d, "instructions", "foobar" );
    Tag* x = new Tag( d, "x" );
    x->setXmlns( XMLNS_X_OOB );
    new Tag( x, "url", "http://camaya.net/gloox" );
    Registration::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_REGISTER + "'>"
         "<instructions>foobar</instructions>"
         "<x xmlns='" + XMLNS_X_OOB + "'>"
         "<url>http://camaya.net/gloox</url>"
         "</x>"
         "</query>"
         || sq.instructions() != "foobar"
         || sq.oob()->url() != "http://camaya.net/gloox" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }




  // -------
  name = "Registration::Query/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new Registration::Query() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "query", "xmlns", XMLNS_REGISTER );
  IQ iq( IQ::Get, JID() );
  sef.addExtensions( iq, f );
  const Registration::Query* se = iq.findExtension<Registration::Query>( ExtRegistration );
  if( se == 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;



EXPECT_EQ(0, fail);

//printf( "Registration::Query: " );
//    if( fail == 0 )
//  {
//    printf( "OK\n" );
//    return 0;
//  }
//  else
//  {
//    fprintf( stderr, "%d test(s) failed\n", fail );
//    return 1;
//  }

}
Ejemplo n.º 22
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  t1 = new Tag( "foo" );
  t1->setXmlns( "test" );
  new Tag( t1, "foobar" );
  Tag *t;
  ClientBase* cb = new ClientBase();
  PrivateXML px( cb );

  // -------
  {
    name = "store xml";
    cb->setTest( 1 );
    px.storeXML( t1->clone(), cb );
    if( !cb->ok() )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
  }

    // -------
  {
    name = "request xml";
    cb->setTest( 2 );
    px.requestXML( "foo", "test", cb );
    if( !cb->ok() )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
  }

  StanzaExtensionFactory sef;
  sef.registerExtension( new PrivateXML::Query() );
  // -------
  {
    name = "Query/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "query", "xmlns", XMLNS_PRIVATE_XML );
    IQ iq( IQ::Get, JID(), "" );
    sef.addExtensions( iq, f );
    const PrivateXML::Query* se = iq.findExtension<PrivateXML::Query>( ExtPrivateXML );
    if( se == 0 )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }

  delete t1;
  delete cb;

  printf( "PrivateXML: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    printf( "%d test(s) failed\n", fail );
    return 1;
  }

}
Ejemplo n.º 23
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;

  // -------
  {
    name = "fetch fields";
    Search::Query sq;
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'/>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "receive search fields";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_SEARCH );
    new Tag( d, "instructions", "foobar" );
    new Tag( d, "first" );
    new Tag( d, "last" );
    new Tag( d, "email" );
    new Tag( d, "nick" );
    Search::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
         "<instructions>foobar</instructions>"
         "<first/>"
         "<last/>"
         "<nick/>"
         "<email/>"
         "</query>"
         || sq.instructions() != "foobar"
         || sq.fields() != ( SearchFieldFirst | SearchFieldLast | SearchFieldNick | SearchFieldEmail ) )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  {
    name = "receive search form";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_SEARCH );
    Tag* f = new Tag( d, "x" );
    f->setXmlns( XMLNS_X_DATA );
    f->addAttribute( "type", "form" );
    Search::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
         "<x xmlns='" + XMLNS_X_DATA + "' type='form'/>"
         "</query>"
         || !sq.form() )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  {
    name = "search by form";
    DataForm* form = new DataForm( TypeSubmit );
    Search::Query sq( form );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
       "<x xmlns='" + XMLNS_X_DATA + "' type='submit'/>"
       "</query>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "search by fields";
    SearchFieldStruct sfs( "first", "last", "nick", "email" );
    Search::Query sq( SearchFieldFirst | SearchFieldLast | SearchFieldNick | SearchFieldEmail, sfs );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
         "<first>first</first>"
         "<last>last</last>"
         "<nick>nick</nick>"
         "<email>email</email>"
         "</query>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
  }

  // -------
  {
    name = "receive form result";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_SEARCH );
    Tag* f = new Tag( d, "x" );
    f->setXmlns( XMLNS_X_DATA );
    f->addAttribute( "type", "result" );
    Search::Query sq( d );
    Tag* t = sq.tag();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
         "<x xmlns='" + XMLNS_X_DATA + "' type='result'/>"
         "</query>" )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    delete d;
  }

  // -------
  {
    name = "receive fields result";
    Tag* d = new Tag( "query" );
    d->setXmlns( XMLNS_SEARCH );
    Tag* i = new Tag( d, "item" );
    i->addAttribute( "jid", "foo@bar" );
    new Tag( i, "first", "first1" );
    new Tag( i, "last", "last1" );
    new Tag( i, "email", "email1" );
    new Tag( i, "nick", "nick1" );
    i = new Tag( d, "item" );
    i->addAttribute( "jid", "foo@bar2" );
    new Tag( i, "first", "first2" );
    new Tag( i, "last", "last2" );
    new Tag( i, "nick", "nick2" );
    new Tag( i, "email", "email2" );
    Search::Query sq( d );
    Tag* t = sq.tag();
    SearchResultList srl = sq.result();
    if( !t || t->xml() != "<query xmlns='" + XMLNS_SEARCH + "'>"
         "<item jid='foo@bar'>"
         "<first>first1</first>"
         "<last>last1</last>"
         "<nick>nick1</nick>"
         "<email>email1</email></item>"
         "<item jid='foo@bar2'>"
         "<first>first2</first>"
         "<last>last2</last>"
         "<nick>nick2</nick>"
         "<email>email2</email></item>"
         "</query>"
       || srl.size() != 2 )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    delete d;
  }




  // -------
  name = "Search::Query/SEFactory test";
  StanzaExtensionFactory sef;
  sef.registerExtension( new Search::Query() );
  Tag* f = new Tag( "iq" );
  new Tag( f, "query", "xmlns", XMLNS_SEARCH );
  IQ iq( IQ::Get, JID() );
  sef.addExtensions( iq, f );
  const Search::Query* se = iq.findExtension<Search::Query>( ExtSearch );
  if( se == 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;



  printf( "Search::Query: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    printf( "%d test(s) failed\n", fail );
    return 1;
  }

}