You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/01/18 19:40:52 UTC
[7/8] thrift git commit: THRIFT-3566: fixed TQTcpServerTest - it was
never executed and working Client: C++ Patch: Sebastian Zenker
THRIFT-3566: fixed TQTcpServerTest - it was never executed and working
Client: C++
Patch: Sebastian Zenker
C++/Qt: TQTcpServerTest did never execute the actual test method test_communicate() as it wasn't declared as a Qt slot. The test gets now executed but it is broken because server and (synchronous) client cannot be executed in the same thread.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3506b66c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3506b66c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3506b66c
Branch: refs/heads/master
Commit: 3506b66cc04d3a9f6860b8cd7f4275468b91ac31
Parents: 9c4193d
Author: Sebastian Zenker <se...@gmx.de>
Authored: Mon Jan 18 08:37:54 2016 +0100
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Tue Jan 19 02:48:07 2016 +0900
----------------------------------------------------------------------
lib/cpp/test/qt/TQTcpServerTest.cpp | 91 ++++++++++++++++++++------------
1 file changed, 57 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/3506b66c/lib/cpp/test/qt/TQTcpServerTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/qt/TQTcpServerTest.cpp b/lib/cpp/test/qt/TQTcpServerTest.cpp
index 0cad6a9..422d771 100644
--- a/lib/cpp/test/qt/TQTcpServerTest.cpp
+++ b/lib/cpp/test/qt/TQTcpServerTest.cpp
@@ -5,6 +5,7 @@
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
+#include <QThread>
#ifndef Q_MOC_RUN
#include <boost/smart_ptr.hpp>
@@ -42,46 +43,68 @@ struct AsyncHandler : public test::ParentServiceCobSvIf {
};
class TQTcpServerTest : public QObject {
- void init() {
- // setup server
- serverSocket.reset(new QTcpServer);
- server.reset(new async::TQTcpServer(serverSocket,
- boost::make_shared<test::ParentServiceAsyncProcessor>(
- boost::make_shared<AsyncHandler>()),
- boost::make_shared<protocol::TBinaryProtocolFactory>()));
- QVERIFY(serverSocket->listen(QHostAddress::LocalHost));
- int port = serverSocket->serverPort();
- QVERIFY(port > 0);
-
- // setup client
- socket.reset(new QTcpSocket);
- client.reset(new test::ParentServiceClient(boost::make_shared<protocol::TBinaryProtocol>(
- boost::make_shared<transport::TQIODeviceTransport>(socket))));
- socket->connectToHost(QHostAddress::LocalHost, port);
- QVERIFY(socket->waitForConnected());
- }
-
- void cleanup() {
- socket->close();
- serverSocket->close();
- }
+ Q_OBJECT
- void test_communicate() {
- client->addString("foo");
- client->addString("bar");
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void test_communicate();
- std::vector<std::string> reply;
- client->getStrings(reply);
- QCOMPARE(reply[0], "foo");
- QCOMPARE(reply[1], "foo");
- }
-
- boost::shared_ptr<QTcpServer> serverSocket;
+private:
+ boost::shared_ptr<QThread> serverThread;
boost::shared_ptr<async::TQTcpServer> server;
- boost::shared_ptr<QTcpSocket> socket;
boost::shared_ptr<test::ParentServiceClient> client;
};
+void TQTcpServerTest::initTestCase() {
+ // setup server
+ boost::shared_ptr<QTcpServer> serverSocket = boost::make_shared<QTcpServer>();
+ server.reset(new async::TQTcpServer(serverSocket,
+ boost::make_shared<test::ParentServiceAsyncProcessor>(
+ boost::make_shared<AsyncHandler>()),
+ boost::make_shared<protocol::TBinaryProtocolFactory>()));
+ QVERIFY(serverSocket->listen(QHostAddress::LocalHost));
+ int port = serverSocket->serverPort();
+ QVERIFY(port > 0);
+
+ //setup server thread and move server to it
+ serverThread.reset(new QThread());
+ serverSocket->moveToThread(serverThread.get());
+ server->moveToThread(serverThread.get());
+ serverThread->start();
+
+ // setup client
+ boost::shared_ptr<QTcpSocket> socket = boost::make_shared<QTcpSocket>();
+ client.reset(new test::ParentServiceClient(boost::make_shared<protocol::TBinaryProtocol>(
+ boost::make_shared<transport::TQIODeviceTransport>(socket))));
+ socket->connectToHost(QHostAddress::LocalHost, port);
+ QVERIFY(socket->waitForConnected());
+}
+
+void TQTcpServerTest::cleanupTestCase() {
+ //first, stop the thread which holds the server
+ serverThread->quit();
+ serverThread->wait();
+ // now, it is safe to delete the server
+ server.reset();
+ // delete thread now
+ serverThread.reset();
+
+ // cleanup client
+ client.reset();
+}
+
+void TQTcpServerTest::test_communicate() {
+ client->addString("foo");
+ client->addString("bar");
+
+ std::vector<std::string> reply;
+ client->getStrings(reply);
+ QCOMPARE(QString::fromStdString(reply[0]), QString("foo"));
+ QCOMPARE(QString::fromStdString(reply[1]), QString("bar"));
+}
+
+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QTEST_GUILESS_MAIN(TQTcpServerTest);
#else