bool Adhoc::handleIqID( Stanza * stanza, int context ) { if( context != ExecuteAdhocCommand || stanza->subtype() != StanzaIqResult ) return false; AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); for( ; it != m_adhocTrackMap.end(); ++it ) { if( (*it).second.context == context && (*it).second.remote == stanza->from() ) { Tag *c = stanza->findChild( "command", "xmlns", XMLNS_ADHOC_COMMANDS ); if( c ) { const std::string& command = c->findAttribute( "node" ); const std::string& id = c->findAttribute( "sessionid" ); Tag *a = c->findChild( "actions" ); int actions = ActionCancel; Adhoc::AdhocExecuteActions def = ActionCancel; if( a ) { if( a->hasChild( "prev" ) ) actions |= ActionPrevious; if( a->hasChild( "next" ) ) actions |= ActionNext; if( a->hasChild( "complete" ) ) actions |= ActionComplete; const std::string& d = a->findAttribute( "execute" ); if( d == "next" ) def = ActionNext; else if( d == "prev" ) def = ActionPrevious; else if( d == "complete" ) def = ActionComplete; } Tag *n = c->findChild( "note" ); std::string note; AdhocNoteType type = AdhocNoteInfo; if( n ) { note = n->cdata(); if( n->hasAttribute( "type", "warn" ) ) type = AdhocNoteWarn; else if( n->hasAttribute( "type", "error" ) ) type = AdhocNoteError; } const std::string& s = c->findAttribute( "status" ); AdhocCommandStatus status = AdhocCommandStatusUnknown; if( s == "executing" ) status = AdhocCommandExecuting; else if( s == "completed" ) status = AdhocCommandCompleted; else if( s == "canceled" ) status = AdhocCommandCanceled; DataForm form; Tag *x = c->findChild( "x", "xmlns", XMLNS_X_DATA ); if( x ) form.parse( x ); (*it).second.ah->handleAdhocExecutionResult( stanza->from(), command, status, id, form, actions, def, note, type ); } m_adhocTrackMap.erase( it ); return true; } } return false; }
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; } }