14
15
#include <cstdio> // [s]print[f]
16
class ClientTest : public Client, /*LogHandler,*/ ConnectionListener
17
class ClientTest : public Client, LogHandler, ConnectionListener
19
20
ClientTest( const JID& jid, const std::string& password, int port = -1 )
20
: Client( jid, password, port ), m_idCount( 0 ), m_connected( 0 ), m_disconnected( 0 )
21
: Client( jid, password, port ), m_connected( 0 ), m_disconnected( 0 ), m_log( false )
22
// logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
23
logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
23
24
registerConnectionListener( this );
25
27
virtual ~ClientTest() {}
26
// virtual void handleLog( LogLevel level, LogArea area, const std::string& message )
28
// printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() );
30
virtual void onConnect() { ++m_connected; disconnect(); }
28
virtual void handleLog( LogLevel level, LogArea area, const std::string& message )
31
printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() );
33
virtual void onConnect()
38
if( jidCopy == "a@b/c" )
31
41
virtual void onDisconnect( ConnectionError e )
186
197
"</stream:features>",
187
198
"<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>",
201
{ // connection/auth goes ok. basic xep-0198 (stream management) ack'ing
202
"<stream:stream from='jabber.cc' id='6kpid3u736sqjwd65n25wm57mzz10wz7hopvsj2w' version='1.0' "
203
"xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
204
"<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
205
"<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
206
"<mechanism>PLAIN</mechanism>"
207
"<mechanism>DIGEST-MD5</mechanism>"
209
"</stream:features>",
210
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
211
"bm9uY2U9ImhvS1I2VkZDSGFibUVYY01weFhlL0QrcVZjWEdyMUdFNzQ0MVFzM2MxY2M9IixyZWFsbT0iamFiYmV"
212
"yLmNjIixxb3A9ImF1dGgsYXV0aC1pbnQsYXV0aC1jb25mIixjaXBoZXI9InJjNC00MCxyYzQtNTYscmM0LGRlcyw"
213
"zZGVzIixtYXhidWY9MTAyNCxjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw=="
215
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
216
"cnNwYXV0aD1mNGFhZTM0YWY0N2I1MmM0MmQ2NWQzY2NjMGNjN2YyNA=="
218
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>",
219
"<stream:stream from='jabber.cc' id='1o4p1gz2h0m1wvqutohs24d439nbv9zxx4nykm11' version='1.0' "
220
"xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
221
"<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
222
"<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>"
223
"<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>"
224
"<sm xmlns='urn:xmpp:sm:3'/>"
225
"</stream:features>",
226
"<iq id='uid1' type='result' xmlns='jabber:client'>"
227
"<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>"
228
"<jid>hurkhurk@jabber.cc/gloox</jid></bind></iq>",
229
"<enabled xmlns='urn:xmpp:sm:3' resume='true' id='some-long-id'/>",
230
"<iq id='uid2' type='result' xmlns='jabber:client'/>",
231
"<iq id='uid3' type='result' xmlns='jabber:client'><query xmlns='jabber:iq:private'>"
232
"<roster xmlns='roster:delimiter'>::</roster></query></iq>"
233
"<iq id='uid4' type='result' xmlns='jabber:client'><query xmlns='jabber:iq:roster'/></iq>",
236
{ // connection/auth goes ok.
237
"<stream:stream from='jabber.cc' id='6kpid3u736sqjwd65n25wm57mzz10wz7hopvsj2w' version='1.0' "
238
"xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
239
"<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
240
"<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
241
"<mechanism>PLAIN</mechanism>"
242
"<mechanism>DIGEST-MD5</mechanism>"
244
"</stream:features>",
245
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
246
"bm9uY2U9ImhvS1I2VkZDSGFibUVYY01weFhlL0QrcVZjWEdyMUdFNzQ0MVFzM2MxY2M9IixyZWFsbT0iamFiYmV"
247
"yLmNjIixxb3A9ImF1dGgsYXV0aC1pbnQsYXV0aC1jb25mIixjaXBoZXI9InJjNC00MCxyYzQtNTYscmM0LGRlcyw"
248
"zZGVzIixtYXhidWY9MTAyNCxjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw=="
250
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
251
"cnNwYXV0aD1mNGFhZTM0YWY0N2I1MmM0MmQ2NWQzY2NjMGNjN2YyNA=="
253
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>",
254
"<stream:stream from='jabber.cc' id='1o4p1gz2h0m1wvqutohs24d439nbv9zxx4nykm11' version='1.0' "
255
"xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
256
"<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
257
"<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>"
258
"<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>"
259
"<sm xmlns='urn:xmpp:sm:3'/>"
260
"</stream:features>",
261
"<resumed xmlns='urn:xmpp:sm:3' h='3' previd='some-long-id' />",
262
"<r xmlns='urn:xmpp:sm:3'/>",
263
"<message from='someone' to='someother'><body>something</body></message>",
192
268
int main( int /*argc*/, char** /*argv*/ )
206
282
c->setConnectionImpl( conn );
207
283
c->setTls( TLSDisabled );
208
284
c->setCompression( false );
285
// c->setLog( true );
287
// printf( "connected: %d, disconnected: %d, reason: %d\n", c->connected(), c->disconnected(), c->disconnectReason() );
210
288
if( c->connected() != 1 || c->disconnected() != 1 || c->disconnectReason() != ConnUserDisconnected )
213
printf( "test '%s' failed\n", name.c_str() );
291
fprintf( stderr, "test '%s' failed\n", name.c_str() );
257
337
c->setConnectionImpl( conn );
258
338
c->setTls( TLSDisabled );
259
339
c->setCompression( false );
340
// c->setLog( true );
261
342
if( c->connected() != 0 || c->disconnected() != 1 || c->disconnectReason() != ConnStreamError
262
343
|| c->streamErrorReason() != StreamErrorXmlNotWellFormed )
265
printf( "test '%s' failed: %d, %d\n", name.c_str(), c->disconnectReason(), c->streamErrorReason() );
346
fprintf( stderr, "test '%s' failed: %d, %d\n", name.c_str(), c->disconnectReason(), c->streamErrorReason() );
274
355
c->setConnectionImpl( conn );
275
356
c->setTls( TLSDisabled );
276
357
c->setCompression( false );
358
// c->setLog( true );
277
359
for( int i = 1; i <= 100; ++i )
280
362
if( c->connected() != 0 || c->disconnected() != i || c->disconnectReason() != ConnIoError )
283
printf( "test '%s' failed, %d, %d, %d\n", name.c_str(),
365
fprintf( stderr, "test '%s' failed, %d, %d, %d\n", name.c_str(),
284
366
c->connected(), c->disconnected(),
285
367
c->disconnectReason() );
296
378
c->setConnectionImpl( conn );
297
379
c->setTls( TLSDisabled );
298
380
c->setCompression( false );
381
// c->setLog( true );
299
382
for( int i = 1; i <= 100; ++i )
302
385
if( c->connected() != i || c->disconnected() != i || c->disconnectReason() != ConnUserDisconnected )
305
printf( "test '%s' failed, %d, %d, %d\n", name.c_str(),
388
fprintf( stderr, "test '%s' failed, %d, %d, %d\n", name.c_str(),
306
389
c->connected(), c->disconnected(),
307
390
c->disconnectReason() );
310
c->m_idCount = 0; // FIXME re-using this variable in subsequent connection attempts
311
// causes inconsistencies with the hard-coded replies.
400
name = "stream management test 1: basic ack";
401
c = new ClientTest( j, "b" );
402
conn = new ConnectionImpl( c, 4 );
403
c->setConnectionImpl( conn );
404
c->setTls( TLSDisabled );
405
c->setCompression( false );
406
c->setStreamManagement( true, false );
407
// c->setLog( true );
409
// printf( "connected: %d, disconnected: %d, reason: %d\n", c->connected(), c->disconnected(), c->disconnectReason() );
410
if( c->connected() != 1 || c->disconnected() != 1 || c->disconnectReason() != ConnUserDisconnected )
413
fprintf( stderr, "test '%s' failed, %d, %d, %d\n", name.c_str(),
414
c->connected(), c->disconnected(),
415
c->disconnectReason() );
423
name = "stream management test 2: resume";
424
c = new ClientTest( j, "b" );
425
conn = new ConnectionImpl( c, 4 );
426
c->setConnectionImpl( conn );
427
c->setTls( TLSDisabled );
428
c->setCompression( false );
429
c->setStreamManagement( true, true );
430
// c->setLog( true );
432
// printf( "connected: %d, disconnected: %d, reason: %d\n", c->connected(), c->disconnected(), c->disconnectReason() );
433
if( c->connected() != 1 || c->disconnected() != 1 || c->disconnectReason() != ConnIoError )
436
fprintf( stderr, "test '%s' part 1 failed, %d, %d, %d\n", name.c_str(),
437
c->connected(), c->disconnected(),
438
c->disconnectReason() );
442
conn = new ConnectionImpl( c, 5 );
443
c->setConnectionImpl( conn );
445
// printf( "connected: %d, disconnected: %d, reason: %d\n", c->connected(), c->disconnected(), c->disconnectReason() );
446
if( c->connected() != 2 || c->disconnected() != 2 || c->disconnectReason() != ConnIoError )
449
fprintf( stderr, "test '%s' part 2 failed, %d, %d, %d\n", name.c_str(),
450
c->connected(), c->disconnected(),
451
c->disconnectReason() );