X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcontrib%2Flibqxt-2007-10-24%2Ftests%2Frpc%2Fmain.cpp;fp=src%2Fcontrib%2Flibqxt-2007-10-24%2Ftests%2Frpc%2Fmain.cpp;h=e54b72816b4e1a3fbd5baed21f9014731a766562;hp=0000000000000000000000000000000000000000;hb=a634acadbcf6017474f68a3eaf7cb632660e9e49;hpb=cd122ca8e0d2c0ffc5397e0a813c75d791a7e6e3 diff --git a/src/contrib/libqxt-2007-10-24/tests/rpc/main.cpp b/src/contrib/libqxt-2007-10-24/tests/rpc/main.cpp new file mode 100644 index 00000000..e54b7281 --- /dev/null +++ b/src/contrib/libqxt-2007-10-24/tests/rpc/main.cpp @@ -0,0 +1,108 @@ +/** ***** QxtRPCPeer loopback test ******/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class RPCTest: public QObject +{ + Q_OBJECT +private: + QxtRPCPeer* peer; +signals: + void wave(QString); + void counterwave(QString); + void networkedwave(quint64,QString); + + +private slots: + void initTestCase() + {} + + + + void loopback() + { + QxtFifo io; + QxtRPCPeer peer(&io); + QVERIFY2(peer.attachSignal (this, SIGNAL( wave ( QString ) ) ),"cannot attach signal"); + QVERIFY2(peer.attachSlot ( SIGNAL( wave ( QString ) ),this, SIGNAL( counterwave(QString )) ),"cannot attach slot"); + + QSignalSpy spy(this, SIGNAL(counterwave(QString))); + QSignalSpy spyr(&io, SIGNAL(readyRead())); + + emit(wave("world")); + + QCoreApplication::processEvents (); + QCoreApplication::processEvents (); + + QVERIFY2 (spyr.count()> 0, "buffer not emitting readyRead" ); + + QVERIFY2 (spy.count()> 0, "no signal received" ); + QVERIFY2 (spy.count()< 2, "wtf, two signals received?" ); + + QList arguments = spy.takeFirst(); + QVERIFY2(arguments.at(0).toString()=="world","argument missmatch"); + } + void directcall() + { + QxtFifo io; + QxtRPCPeer peer(&io); + QVERIFY2(peer.attachSlot ( SIGNAL( wave ( QString ) ),this, SIGNAL( counterwave(QString )) ),"cannot attach slot"); + + QSignalSpy spy(this, SIGNAL(counterwave(QString))); + QSignalSpy spyr(&io, SIGNAL(readyRead())); + peer.call(SIGNAL(wave ( QString ) ),QString("world")); + + QCoreApplication::processEvents (); + QCoreApplication::processEvents (); + + + QVERIFY2 (spyr.count()> 0, "buffer not emitting readyRead" ); + + QVERIFY2 (spy.count()> 0, "no signal received" ); + QVERIFY2 (spy.count()< 2, "wtf, two signals received?" ); + + QList arguments = spy.takeFirst(); + QVERIFY2(arguments.at(0).toString()=="world","argument missmatch"); + } + + void TcpServerIo() + { + QxtRPCPeer server(QxtRPCPeer::Server); + QVERIFY2(server.attachSlot (SIGNAL(wave(QString)),this,SIGNAL(networkedwave(quint64,QString))),"cannot attach slot"); + + + QVERIFY(server.listen (QHostAddress::LocalHost, 23444)); + + + QxtRPCPeer client(QxtRPCPeer::Client); + client.connect (QHostAddress::LocalHost, 23444); + QVERIFY(qobject_cast(client.socket())->waitForConnected ( 30000 )); + + + QSignalSpy spy(this, SIGNAL(networkedwave(quint64,QString))); + client.call(SIGNAL(wave(QString)),QString("world")); + + + QCoreApplication::processEvents (); + QCoreApplication::processEvents (); + QCoreApplication::processEvents (); + + QVERIFY2 (spy.count()> 0, "no signal received" ); + QVERIFY2 (spy.count()< 2, "wtf, two signals received?" ); + + QList arguments = spy.takeFirst(); + QVERIFY2(arguments.at(1).toString()=="world","argument missmatch"); + } + void cleanupTestCase() + {} +}; + +QTEST_MAIN(RPCTest) +#include "main.moc"