|
@@ -25,6 +25,9 @@
|
|
|
|
|
|
#include "testservice_grpc.qpb.h"
|
|
#include "testservice_grpc.qpb.h"
|
|
#include <QGrpcHttp2Channel>
|
|
#include <QGrpcHttp2Channel>
|
|
|
|
+#ifdef QT_PROTOBUF_NATIVE_GRPC_CHANNEL
|
|
|
|
+#include <QGrpcChannel>
|
|
|
|
+#endif
|
|
#include <QGrpcCredentials>
|
|
#include <QGrpcCredentials>
|
|
#include <QGrpcInsecureCredentials>
|
|
#include <QGrpcInsecureCredentials>
|
|
|
|
|
|
@@ -34,27 +37,65 @@
|
|
#include <QThread>
|
|
#include <QThread>
|
|
|
|
|
|
#include <QCoreApplication>
|
|
#include <QCoreApplication>
|
|
|
|
+
|
|
#include <gtest/gtest.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
+#include <gtest/gtest-param-test.h>
|
|
|
|
|
|
#include <qprotobufserializer.h>
|
|
#include <qprotobufserializer.h>
|
|
|
|
|
|
using namespace qtprotobufnamespace::tests;
|
|
using namespace qtprotobufnamespace::tests;
|
|
using namespace QtProtobuf;
|
|
using namespace QtProtobuf;
|
|
|
|
|
|
-class ClientTest : public ::testing::Test
|
|
|
|
|
|
+typedef TestServiceClient* createTestServiceClientFunc();
|
|
|
|
+
|
|
|
|
+class ClientTest : public ::testing::TestWithParam<createTestServiceClientFunc*>
|
|
{
|
|
{
|
|
|
|
+public:
|
|
|
|
+ static TestServiceClient * createHttp2Client() {
|
|
|
|
+ auto *c = new TestServiceClient();
|
|
|
|
+ c->attachChannel(std::make_shared<QGrpcHttp2Channel>(ClientTest::m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials())); \
|
|
|
|
+ return c;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+#ifdef QT_PROTOBUF_NATIVE_GRPC_CHANNEL
|
|
|
|
+ static TestServiceClient * createGrpcSocketClient() {
|
|
|
|
+ auto *c = new TestServiceClient();
|
|
|
|
+ c->attachChannel(std::make_shared<QGrpcChannel>(ClientTest::m_echoServerSocket, grpc::InsecureChannelCredentials())); \
|
|
|
|
+ return c;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static TestServiceClient * createGrpcHttpClient() {
|
|
|
|
+ auto *c = new TestServiceClient();
|
|
|
|
+ c->attachChannel(std::make_shared<QGrpcChannel>(ClientTest::m_echoServerAddressNative, grpc::InsecureChannelCredentials())); \
|
|
|
|
+ return c;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ static createTestServiceClientFunc *clientCreators[];
|
|
|
|
+
|
|
protected:
|
|
protected:
|
|
static void SetUpTestCase() {
|
|
static void SetUpTestCase() {
|
|
QtProtobuf::qRegisterProtobufTypes();
|
|
QtProtobuf::qRegisterProtobufTypes();
|
|
}
|
|
}
|
|
static QCoreApplication m_app;
|
|
static QCoreApplication m_app;
|
|
static int m_argc;
|
|
static int m_argc;
|
|
- static QUrl m_echoServerAddress;
|
|
|
|
|
|
+ static const QUrl m_echoServerAddress;
|
|
|
|
+ static const QString m_echoServerSocket;
|
|
|
|
+ static const QString m_echoServerAddressNative;
|
|
};
|
|
};
|
|
|
|
|
|
int ClientTest::m_argc(0);
|
|
int ClientTest::m_argc(0);
|
|
QCoreApplication ClientTest::m_app(m_argc, nullptr);
|
|
QCoreApplication ClientTest::m_app(m_argc, nullptr);
|
|
-QUrl ClientTest::m_echoServerAddress("http://localhost:50051", QUrl::StrictMode);
|
|
|
|
|
|
+const QUrl ClientTest::m_echoServerAddress("http://localhost:50051", QUrl::StrictMode);
|
|
|
|
+const QString ClientTest::m_echoServerAddressNative("localhost:50051");
|
|
|
|
+const QString ClientTest::m_echoServerSocket("unix:///tmp/test.sock");
|
|
|
|
+createTestServiceClientFunc* ClientTest::clientCreators[]{
|
|
|
|
+ ClientTest::createHttp2Client,
|
|
|
|
+#ifdef QT_PROTOBUF_NATIVE_GRPC_CHANNEL
|
|
|
|
+ ClientTest::createGrpcHttpClient,
|
|
|
|
+ ClientTest::createGrpcSocketClient,
|
|
|
|
+#endif
|
|
|
|
+};
|
|
|
|
|
|
TEST_F(ClientTest, CheckMethodsGeneration)
|
|
TEST_F(ClientTest, CheckMethodsGeneration)
|
|
{
|
|
{
|
|
@@ -69,28 +110,27 @@ TEST_F(ClientTest, CheckMethodsGeneration)
|
|
delete result;
|
|
delete result;
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
request.setTestFieldString("Hello beach!");
|
|
request.setTestFieldString("Hello beach!");
|
|
- ASSERT_TRUE(testClient.testMethod(request, result) == QGrpcStatus::Ok);
|
|
|
|
|
|
+ ASSERT_TRUE(testClient->testMethod(request, result) == QGrpcStatus::Ok);
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "Hello beach!");
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "Hello beach!");
|
|
delete result;
|
|
delete result;
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoAsyncTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoAsyncTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
request.setTestFieldString("Hello beach!");
|
|
request.setTestFieldString("Hello beach!");
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
- QGrpcAsyncReplyShared reply = testClient.testMethod(request);
|
|
|
|
|
|
+ QGrpcAsyncReplyShared reply = testClient->testMethod(request);
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [reply, &result, &waiter]() {
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [reply, &result, &waiter]() {
|
|
result = reply->read<SimpleStringMessage>();
|
|
result = reply->read<SimpleStringMessage>();
|
|
reply->deleteLater();
|
|
reply->deleteLater();
|
|
@@ -99,34 +139,35 @@ TEST_F(ClientTest, StringEchoAsyncTest)
|
|
|
|
|
|
waiter.exec();
|
|
waiter.exec();
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach!");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach!");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoAsync2Test)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoAsync2Test)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Hello beach!");
|
|
request.setTestFieldString("Hello beach!");
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
- testClient.testMethod(request, &m_app, [&result, &waiter](QGrpcAsyncReplyShared reply) {
|
|
|
|
|
|
+ testClient->testMethod(request, &m_app, [&result, &waiter](QGrpcAsyncReplyShared reply) {
|
|
result = reply->read<SimpleStringMessage>();
|
|
result = reply->read<SimpleStringMessage>();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
});
|
|
});
|
|
|
|
|
|
waiter.exec();
|
|
waiter.exec();
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach!");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach!");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoImmediateAsyncAbortTest)
|
|
|
|
|
|
+
|
|
|
|
+TEST_P(ClientTest, StringEchoImmediateAsyncAbortTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("sleep");
|
|
request.setTestFieldString("sleep");
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
- QGrpcAsyncReplyShared reply = testClient.testMethod(request);
|
|
|
|
|
|
+ QGrpcAsyncReplyShared reply = testClient->testMethod(request);
|
|
|
|
|
|
result.setTestFieldString("Result not changed by echo");
|
|
result.setTestFieldString("Result not changed by echo");
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [&waiter, &result, reply]() {
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [&waiter, &result, reply]() {
|
|
@@ -141,7 +182,7 @@ TEST_F(ClientTest, StringEchoImmediateAsyncAbortTest)
|
|
});
|
|
});
|
|
|
|
|
|
QGrpcStatus::StatusCode clientStatus = QGrpcStatus::StatusCode::Ok;
|
|
QGrpcStatus::StatusCode clientStatus = QGrpcStatus::StatusCode::Ok;
|
|
- QObject::connect(&testClient, &TestServiceClient::error, [&clientStatus](const QGrpcStatus &status) {
|
|
|
|
|
|
+ QObject::connect(testClient, &TestServiceClient::error, [&clientStatus](const QGrpcStatus &status) {
|
|
clientStatus = status.code();
|
|
clientStatus = status.code();
|
|
std::cerr << status.code() << ":" << status.message().toStdString();
|
|
std::cerr << status.code() << ":" << status.message().toStdString();
|
|
});
|
|
});
|
|
@@ -153,21 +194,21 @@ TEST_F(ClientTest, StringEchoImmediateAsyncAbortTest)
|
|
ASSERT_EQ(clientStatus, QGrpcStatus::StatusCode::Aborted);
|
|
ASSERT_EQ(clientStatus, QGrpcStatus::StatusCode::Aborted);
|
|
ASSERT_EQ(asyncStatus, QGrpcStatus::StatusCode::Aborted);
|
|
ASSERT_EQ(asyncStatus, QGrpcStatus::StatusCode::Aborted);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Result not changed by echo");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Result not changed by echo");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoDeferredAsyncAbortTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoDeferredAsyncAbortTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("sleep");
|
|
request.setTestFieldString("sleep");
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
- QGrpcAsyncReplyShared reply = testClient.testMethod(request);
|
|
|
|
|
|
+ QGrpcAsyncReplyShared reply = testClient->testMethod(request);
|
|
|
|
|
|
result.setTestFieldString("Result not changed by echo");
|
|
result.setTestFieldString("Result not changed by echo");
|
|
bool errorCalled = false;
|
|
bool errorCalled = false;
|
|
- reply = testClient.testMethod(request);
|
|
|
|
|
|
+ reply = testClient->testMethod(request);
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [reply, &result, &waiter]() {
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &m_app, [reply, &result, &waiter]() {
|
|
result = reply->read<SimpleStringMessage>();
|
|
result = reply->read<SimpleStringMessage>();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
@@ -183,12 +224,12 @@ TEST_F(ClientTest, StringEchoDeferredAsyncAbortTest)
|
|
|
|
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Result not changed by echo");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Result not changed by echo");
|
|
ASSERT_TRUE(errorCalled);
|
|
ASSERT_TRUE(errorCalled);
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoStreamTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoStreamTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
@@ -196,7 +237,7 @@ TEST_F(ClientTest, StringEchoStreamTest)
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &i, &waiter, subscription]() {
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &i, &waiter, subscription]() {
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
|
|
|
|
@@ -215,12 +256,12 @@ TEST_F(ClientTest, StringEchoStreamTest)
|
|
|
|
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoStreamAbortTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoStreamAbortTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
@@ -228,7 +269,7 @@ TEST_F(ClientTest, StringEchoStreamAbortTest)
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &i, &waiter, subscription]() {
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &i, &waiter, subscription]() {
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
++i;
|
|
++i;
|
|
@@ -246,12 +287,12 @@ TEST_F(ClientTest, StringEchoStreamAbortTest)
|
|
|
|
|
|
ASSERT_EQ(i, 3);
|
|
ASSERT_EQ(i, 3);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoStreamAbortByTimerTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoStreamAbortByTimerTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
@@ -260,7 +301,7 @@ TEST_F(ClientTest, StringEchoStreamAbortByTimerTest)
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
QTimer::singleShot(3500, subscription.get(), [subscription]() {
|
|
QTimer::singleShot(3500, subscription.get(), [subscription]() {
|
|
subscription->cancel();
|
|
subscription->cancel();
|
|
});
|
|
});
|
|
@@ -289,12 +330,12 @@ TEST_F(ClientTest, StringEchoStreamAbortByTimerTest)
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3");
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(!isError);
|
|
ASSERT_TRUE(!isError);
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoStreamTestRetUpdates)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoStreamTestRetUpdates)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
|
|
|
|
@@ -302,7 +343,7 @@ TEST_F(ClientTest, StringEchoStreamTestRetUpdates)
|
|
|
|
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
- testClient.subscribeTestMethodServerStreamUpdates(request, result);
|
|
|
|
|
|
+ testClient->subscribeTestMethodServerStreamUpdates(request, result);
|
|
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
QObject::connect(result.data(), &SimpleStringMessage::testFieldStringChanged, &m_app, [&i]() {
|
|
QObject::connect(result.data(), &SimpleStringMessage::testFieldStringChanged, &m_app, [&i]() {
|
|
@@ -315,13 +356,13 @@ TEST_F(ClientTest, StringEchoStreamTestRetUpdates)
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "Stream4");
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "Stream4");
|
|
delete result;
|
|
delete result;
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(ClientTest, HugeBlobEchoStreamTest)
|
|
|
|
|
|
+TEST_P(ClientTest, HugeBlobEchoStreamTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
BlobMessage result;
|
|
BlobMessage result;
|
|
BlobMessage request;
|
|
BlobMessage request;
|
|
QFile testFile("testfile");
|
|
QFile testFile("testfile");
|
|
@@ -331,7 +372,7 @@ TEST_F(ClientTest, HugeBlobEchoStreamTest)
|
|
QByteArray dataHash = QCryptographicHash::hash(request.testBytes(), QCryptographicHash::Sha256);
|
|
QByteArray dataHash = QCryptographicHash::hash(request.testBytes(), QCryptographicHash::Sha256);
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
- auto subscription = testClient.subscribeTestMethodBlobServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodBlobServerStreamUpdates(request);
|
|
|
|
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &waiter, subscription]() {
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &m_app, [&result, &waiter, subscription]() {
|
|
BlobMessage ret = subscription->read<BlobMessage>();
|
|
BlobMessage ret = subscription->read<BlobMessage>();
|
|
@@ -345,18 +386,18 @@ TEST_F(ClientTest, HugeBlobEchoStreamTest)
|
|
|
|
|
|
QByteArray returnDataHash = QCryptographicHash::hash(result.testBytes(), QCryptographicHash::Sha256);
|
|
QByteArray returnDataHash = QCryptographicHash::hash(result.testBytes(), QCryptographicHash::Sha256);
|
|
ASSERT_TRUE(returnDataHash == dataHash);
|
|
ASSERT_TRUE(returnDataHash == dataHash);
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StatusMessageAsyncTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StatusMessageAsyncTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QString statusMessage;
|
|
QString statusMessage;
|
|
|
|
|
|
- QGrpcAsyncReplyShared reply = testClient.testMethodStatusMessage(request);
|
|
|
|
|
|
+ QGrpcAsyncReplyShared reply = testClient->testMethodStatusMessage(request);
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
asyncStatus = status.code();
|
|
asyncStatus = status.code();
|
|
statusMessage = status.message();
|
|
statusMessage = status.message();
|
|
@@ -367,68 +408,69 @@ TEST_F(ClientTest, StatusMessageAsyncTest)
|
|
waiter.exec();
|
|
waiter.exec();
|
|
|
|
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StatusMessageClientAsyncTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StatusMessageClientAsyncTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QString statusMessage;
|
|
QString statusMessage;
|
|
|
|
|
|
- QObject::connect(&testClient, &TestServiceClient::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
|
|
|
|
+ QObject::connect(testClient, &TestServiceClient::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
asyncStatus = status.code();
|
|
asyncStatus = status.code();
|
|
statusMessage = status.message();
|
|
statusMessage = status.message();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
});
|
|
});
|
|
|
|
|
|
- testClient.testMethodStatusMessage(request);
|
|
|
|
|
|
+ testClient->testMethodStatusMessage(request);
|
|
|
|
|
|
QTimer::singleShot(20000, &waiter, &QEventLoop::quit);
|
|
QTimer::singleShot(20000, &waiter, &QEventLoop::quit);
|
|
waiter.exec();
|
|
waiter.exec();
|
|
|
|
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StatusMessageClientSyncTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StatusMessageClientSyncTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
QPointer<SimpleStringMessage> ret(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> ret(new SimpleStringMessage);
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QString statusMessage;
|
|
QString statusMessage;
|
|
|
|
|
|
- QObject::connect(&testClient, &TestServiceClient::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
|
|
|
|
+ QObject::connect(testClient, &TestServiceClient::error, [&asyncStatus, &waiter, &statusMessage](const QGrpcStatus &status) {
|
|
asyncStatus = status.code();
|
|
asyncStatus = status.code();
|
|
statusMessage = status.message();
|
|
statusMessage = status.message();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
});
|
|
});
|
|
|
|
|
|
- testClient.testMethodStatusMessage(request, ret);
|
|
|
|
|
|
+ testClient->testMethodStatusMessage(request, ret);
|
|
QTimer::singleShot(20000, &waiter, &QEventLoop::quit);
|
|
QTimer::singleShot(20000, &waiter, &QEventLoop::quit);
|
|
waiter.exec();
|
|
waiter.exec();
|
|
|
|
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
ASSERT_STREQ(statusMessage.toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
delete ret;
|
|
delete ret;
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StatusMessageClientSyncTestReturnedStatus)
|
|
|
|
|
|
+TEST_P(ClientTest, StatusMessageClientSyncTestReturnedStatus)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
QPointer<SimpleStringMessage> ret(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> ret(new SimpleStringMessage);
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QString statusMessage;
|
|
QString statusMessage;
|
|
|
|
|
|
- QGrpcStatus status = testClient.testMethodStatusMessage(request, ret);
|
|
|
|
|
|
+ QGrpcStatus status = testClient->testMethodStatusMessage(request, ret);
|
|
|
|
|
|
ASSERT_STREQ(status.message().toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
ASSERT_STREQ(status.message().toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
delete ret;
|
|
delete ret;
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -468,11 +510,10 @@ TEST_F(ClientTest, ClientSyncTestUnattachedChannelSignal)
|
|
delete ret;
|
|
delete ret;
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, AsyncReplySubscribeTest)
|
|
|
|
|
|
+TEST_P(ClientTest, AsyncReplySubscribeTest)
|
|
{
|
|
{
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
QTimer callTimeout;
|
|
QTimer callTimeout;
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
SimpleStringMessage request(QString{"Some status message"});
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QGrpcStatus::StatusCode asyncStatus = QGrpcStatus::StatusCode::Ok;
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
@@ -480,7 +521,7 @@ TEST_F(ClientTest, AsyncReplySubscribeTest)
|
|
|
|
|
|
QObject::connect(&callTimeout, &QTimer::timeout, &waiter, &QEventLoop::quit);
|
|
QObject::connect(&callTimeout, &QTimer::timeout, &waiter, &QEventLoop::quit);
|
|
callTimeout.setInterval(5000);
|
|
callTimeout.setInterval(5000);
|
|
- auto reply = testClient.testMethodStatusMessage(request);
|
|
|
|
|
|
+ auto reply = testClient->testMethodStatusMessage(request);
|
|
|
|
|
|
reply->subscribe(&m_app, []() {
|
|
reply->subscribe(&m_app, []() {
|
|
ASSERT_TRUE(false);
|
|
ASSERT_TRUE(false);
|
|
@@ -500,7 +541,7 @@ TEST_F(ClientTest, AsyncReplySubscribeTest)
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
request.setTestFieldString("Hello beach!");
|
|
request.setTestFieldString("Hello beach!");
|
|
|
|
|
|
- reply = testClient.testMethod(request);
|
|
|
|
|
|
+ reply = testClient->testMethod(request);
|
|
reply->subscribe(&m_app, [reply, &result, &waiter]() {
|
|
reply->subscribe(&m_app, [reply, &result, &waiter]() {
|
|
result = reply->read<SimpleStringMessage>();
|
|
result = reply->read<SimpleStringMessage>();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
@@ -514,7 +555,7 @@ TEST_F(ClientTest, AsyncReplySubscribeTest)
|
|
result.setTestFieldString("");
|
|
result.setTestFieldString("");
|
|
request.setTestFieldString("Hello beach1!");
|
|
request.setTestFieldString("Hello beach1!");
|
|
|
|
|
|
- reply = testClient.testMethod(request);
|
|
|
|
|
|
+ reply = testClient->testMethod(request);
|
|
reply->subscribe(&m_app, [reply, &result, &waiter]() {
|
|
reply->subscribe(&m_app, [reply, &result, &waiter]() {
|
|
result = reply->read<SimpleStringMessage>();
|
|
result = reply->read<SimpleStringMessage>();
|
|
waiter.quit();
|
|
waiter.quit();
|
|
@@ -526,19 +567,19 @@ TEST_F(ClientTest, AsyncReplySubscribeTest)
|
|
waiter.exec();
|
|
waiter.exec();
|
|
callTimeout.stop();
|
|
callTimeout.stop();
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), request.testFieldString().toStdString().c_str());
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, MultipleSubscriptionsTest)
|
|
|
|
|
|
+TEST_P(ClientTest, MultipleSubscriptionsTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
|
|
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
- auto subscriptionNext = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
+ auto subscriptionNext = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
|
|
|
|
@@ -555,18 +596,18 @@ TEST_F(ClientTest, MultipleSubscriptionsTest)
|
|
|
|
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, MultipleSubscriptionsCancelTest)
|
|
|
|
|
|
+TEST_P(ClientTest, MultipleSubscriptionsCancelTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
|
|
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
- auto subscriptionNext = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
+ auto subscriptionNext = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
|
|
|
|
@@ -585,10 +626,10 @@ TEST_F(ClientTest, MultipleSubscriptionsCancelTest)
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(isFinishedNext);
|
|
ASSERT_TRUE(isFinishedNext);
|
|
|
|
|
|
- subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
ASSERT_NE(subscription, subscriptionNext);
|
|
ASSERT_NE(subscription, subscriptionNext);
|
|
|
|
|
|
- subscriptionNext = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ subscriptionNext = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
ASSERT_EQ(subscription, subscriptionNext);
|
|
|
|
|
|
@@ -606,29 +647,29 @@ TEST_F(ClientTest, MultipleSubscriptionsCancelTest)
|
|
|
|
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(isFinished);
|
|
ASSERT_TRUE(isFinishedNext);
|
|
ASSERT_TRUE(isFinishedNext);
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, NonCompatibleArgRetTest)
|
|
|
|
|
|
+TEST_P(ClientTest, NonCompatibleArgRetTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleIntMessage request(2048);
|
|
SimpleIntMessage request(2048);
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
- ASSERT_TRUE(testClient.testMethodNonCompatibleArgRet(request, result) == QGrpcStatus::Ok);
|
|
|
|
|
|
+ ASSERT_TRUE(testClient->testMethodNonCompatibleArgRet(request, result) == QGrpcStatus::Ok);
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "2048");
|
|
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "2048");
|
|
delete result;
|
|
delete result;
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoThreadTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoThreadTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
|
|
request.setTestFieldString("Hello beach from thread!");
|
|
request.setTestFieldString("Hello beach from thread!");
|
|
bool ok = false;
|
|
bool ok = false;
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
- ok = testClient.testMethod(request, result) == QGrpcStatus::Ok;
|
|
|
|
|
|
+ ok = testClient->testMethod(request, result) == QGrpcStatus::Ok;
|
|
}));
|
|
}));
|
|
|
|
|
|
thread->start();
|
|
thread->start();
|
|
@@ -644,7 +685,7 @@ TEST_F(ClientTest, StringEchoThreadTest)
|
|
result = new SimpleStringMessage();
|
|
result = new SimpleStringMessage();
|
|
ok = false;
|
|
ok = false;
|
|
thread.reset(QThread::create([&](){
|
|
thread.reset(QThread::create([&](){
|
|
- ok = testClient.testMethod(request, result) == QGrpcStatus::Ok;
|
|
|
|
|
|
+ ok = testClient->testMethod(request, result) == QGrpcStatus::Ok;
|
|
}));
|
|
}));
|
|
|
|
|
|
thread->start();
|
|
thread->start();
|
|
@@ -653,13 +694,13 @@ TEST_F(ClientTest, StringEchoThreadTest)
|
|
wait.exec();
|
|
wait.exec();
|
|
|
|
|
|
ASSERT_TRUE(!ok);
|
|
ASSERT_TRUE(!ok);
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoAsyncThreadTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoAsyncThreadTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
request.setTestFieldString("Hello beach from thread!");
|
|
request.setTestFieldString("Hello beach from thread!");
|
|
@@ -669,7 +710,7 @@ TEST_F(ClientTest, StringEchoAsyncThreadTest)
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QThread *validThread = QThread::currentThread();
|
|
QThread *validThread = QThread::currentThread();
|
|
- QGrpcAsyncReplyShared reply = testClient.testMethod(request);
|
|
|
|
|
|
+ QGrpcAsyncReplyShared reply = testClient->testMethod(request);
|
|
QObject::connect(reply.get(), &QObject::destroyed, [&replyDestroyed]{replyDestroyed = true;});
|
|
QObject::connect(reply.get(), &QObject::destroyed, [&replyDestroyed]{replyDestroyed = true;});
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &waiter, [reply, &result, &waiter, &threadsOk, validThread]() {
|
|
QObject::connect(reply.get(), &QGrpcAsyncReply::finished, &waiter, [reply, &result, &waiter, &threadsOk, validThread]() {
|
|
threadsOk &= reply->thread() != QThread::currentThread();
|
|
threadsOk &= reply->thread() != QThread::currentThread();
|
|
@@ -688,12 +729,12 @@ TEST_F(ClientTest, StringEchoAsyncThreadTest)
|
|
ASSERT_TRUE(replyDestroyed);
|
|
ASSERT_TRUE(replyDestroyed);
|
|
ASSERT_TRUE(threadsOk);
|
|
ASSERT_TRUE(threadsOk);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach from thread!");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Hello beach from thread!");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StringEchoStreamThreadTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StringEchoStreamThreadTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));
|
|
|
|
|
|
+ auto testClient = (*GetParam())();
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
@@ -703,7 +744,7 @@ TEST_F(ClientTest, StringEchoStreamThreadTest)
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
std::shared_ptr<QThread> thread(QThread::create([&](){
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
QThread *validThread = QThread::currentThread();
|
|
QThread *validThread = QThread::currentThread();
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &waiter, [&result, &i, &waiter, subscription, &threadsOk, validThread]() {
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::updated, &waiter, [&result, &i, &waiter, subscription, &threadsOk, validThread]() {
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
SimpleStringMessage ret = subscription->read<SimpleStringMessage>();
|
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
|
@@ -729,6 +770,7 @@ TEST_F(ClientTest, StringEchoStreamThreadTest)
|
|
ASSERT_TRUE(threadsOk);
|
|
ASSERT_TRUE(threadsOk);
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_EQ(i, 4);
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
ASSERT_STREQ(result.testFieldString().toStdString().c_str(), "Stream1Stream2Stream3Stream4");
|
|
|
|
+ testClient->deleteLater();
|
|
}
|
|
}
|
|
|
|
|
|
TEST_F(ClientTest, AttachChannelThreadTest)
|
|
TEST_F(ClientTest, AttachChannelThreadTest)
|
|
@@ -745,10 +787,9 @@ TEST_F(ClientTest, AttachChannelThreadTest)
|
|
}, ".*");
|
|
}, ".*");
|
|
}
|
|
}
|
|
|
|
|
|
-TEST_F(ClientTest, StreamCancelWhileErrorTimeoutTest)
|
|
|
|
|
|
+TEST_P(ClientTest, StreamCancelWhileErrorTimeoutTest)
|
|
{
|
|
{
|
|
- TestServiceClient testClient;
|
|
|
|
- testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(QUrl("http://localhost:50052", QUrl::StrictMode), QGrpcInsecureCallCredentials() | QGrpcInsecureChannelCredentials()));//Invalid port
|
|
|
|
|
|
+ auto *testClient = (*GetParam())();;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage result;
|
|
SimpleStringMessage request;
|
|
SimpleStringMessage request;
|
|
request.setTestFieldString("Stream");
|
|
request.setTestFieldString("Stream");
|
|
@@ -756,7 +797,7 @@ TEST_F(ClientTest, StreamCancelWhileErrorTimeoutTest)
|
|
QEventLoop waiter;
|
|
QEventLoop waiter;
|
|
|
|
|
|
bool ok = false;
|
|
bool ok = false;
|
|
- auto subscription = testClient.subscribeTestMethodServerStreamUpdates(request);
|
|
|
|
|
|
+ auto subscription = testClient->subscribeTestMethodServerStreamUpdates(request);
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::finished, &m_app, [&ok, &waiter]() {
|
|
QObject::connect(subscription.get(), &QGrpcSubscription::finished, &m_app, [&ok, &waiter]() {
|
|
ok = true;
|
|
ok = true;
|
|
waiter.quit();
|
|
waiter.quit();
|
|
@@ -770,3 +811,4 @@ TEST_F(ClientTest, StreamCancelWhileErrorTimeoutTest)
|
|
ASSERT_TRUE(ok);
|
|
ASSERT_TRUE(ok);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+INSTANTIATE_TEST_SUITE_P(ClientTest, ClientTest, ::testing::ValuesIn(ClientTest::clientCreators));
|