void Registration::createAccount( const DataForm& form )
 {
   const Tag *tmp = form.tag();
   if( tmp )
   {
     Tag *c = tmp->clone();
     m_parent->send( c );
   }
 }
示例#2
0
文件: search.cpp 项目: soubok/libset
  void Search::search( const JID& directory, const DataForm& form, SearchHandler *sh )
  {
    if( !m_parent || !directory || !sh )
      return;

    const std::string& id = m_parent->getID();

    Tag *iq = new Tag( "iq" );
    iq->addAttribute( "id", id );
    iq->addAttribute( "type", "set" );
    iq->addAttribute( "to", directory.full() );
    Tag *q = new Tag( iq, "query" );
    q->addAttribute( "xmlns", XMLNS_SEARCH );
    q->addChild( form.tag() );

    m_track[id] = sh;
    m_parent->trackID( this, id, DoSearch );
    m_parent->send( iq );
  }
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  DataForm *f;

  // -------
  name = "empty form";
  f = new DataForm();
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "empty form tag";
  f = new DataForm();
  if( f->tag() )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form title";
  std::string title = "form test title";
  f = new DataForm();
  f->setTitle( title );
  if( f->title() != title )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form instructions";
  StringList instructions;
  instructions.push_back( "form test instructions" );
  instructions.push_back( "line 2" );
  instructions.push_back( "line 3" );
  f = new DataForm();
  f->setInstructions( instructions );
  if( f->instructions() != instructions )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form type, title, instructions";
  // using StringList instructions from previous test case
  // using std::string title from pre-previous test case
  f = new DataForm( DataForm::FormTypeForm, instructions, title );
  if( f->instructions() != instructions )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->title() != title )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->type() != DataForm::FormTypeForm )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse empty Tag (ctor)";
  Tag *t = new Tag();
  f = new DataForm( t );
  delete t;
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse() empty Tag";
  f = new DataForm();
  t = new Tag();
  f->parse( t );
  delete t;
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse 0";
  f = new DataForm();
  f->parse( 0 );
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;





  if( fail == 0 )
  {
    printf( "DataForm: all tests passed\n" );
    return 0;
  }
  else
  {
    printf( "DataForm: %d test(s) failed\n", fail );
    return 1;
  }

}