Skip to content

Commit

Permalink
Add test for incompatible gRPC argument/return values
Browse files Browse the repository at this point in the history
  • Loading branch information
semlanik committed Jul 22, 2020
1 parent 9a2cb79 commit d4f112f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_grpc/clienttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,14 @@ TEST_F(ClientTest, MultipleSubscriptionsCancelTest)
ASSERT_TRUE(isFinished);
ASSERT_TRUE(isFinishedNext);
}

TEST_F(ClientTest, NonCompatibleArgRetTest)
{
TestServiceClient testClient;
testClient.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
SimpleIntMessage request(2048);
QPointer<SimpleStringMessage> result(new SimpleStringMessage);
ASSERT_TRUE(testClient.testMethodNonCompatibleArgRet(request, result) == QGrpcStatus::Ok);
ASSERT_STREQ(result->testFieldString().toStdString().c_str(), "2048");
delete result;
}
8 changes: 8 additions & 0 deletions tests/test_grpc/echoserver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class SimpleTestImpl final : public qtprotobufnamespace::tests::TestService::Ser
{
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, request->testfieldstring());
}

::grpc::Status testMethodNonCompatibleArgRet(grpc::ServerContext *, const qtprotobufnamespace::tests::SimpleIntMessage *request, qtprotobufnamespace::tests::SimpleStringMessage *response) override
{
std::cerr << "testMethodNonCompatibleArgRet called" << std::endl << request->testfield() << std::endl;
response->set_testfieldstring(std::to_string(request->testfield()));
return ::grpc::Status();
}

};

int main(int, char *[])
Expand Down
4 changes: 4 additions & 0 deletions tests/test_grpc/proto/simpletest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ message SimpleStringMessage {
string testFieldString = 6;
}

message SimpleIntMessage {
sint32 testField= 1;
}

message BlobMessage {
bytes testBytes = 1;
}
1 change: 1 addition & 0 deletions tests/test_grpc/proto/testservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ service TestService {
rpc testMethodBiStream(stream SimpleStringMessage) returns (stream SimpleStringMessage) {}
rpc testMethodBlobServerStream(BlobMessage) returns (stream BlobMessage) {}
rpc testMethodStatusMessage(SimpleStringMessage) returns (SimpleStringMessage) {}
rpc testMethodNonCompatibleArgRet(SimpleIntMessage) returns (SimpleStringMessage) {}
}
17 changes: 17 additions & 0 deletions tests/test_grpc_qml/qml/tst_grpc.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ TestCase {
testFieldString: "Test string"
}

SimpleIntMessage {
id: intMsg
testField: 1024
}

GrpcSubscription {
id: serverStreamSubscription
property bool ok: true
Expand Down Expand Up @@ -153,4 +158,16 @@ TestCase {
compare(serverStreamInvalidSubscription.ok, true, "Subscription data failed")
compare(serverStreamInvalidSubscription.enabled, false, "Subscription data failed")
}

function test_nonCompatibleArgRet() {
var called = false;
var errorCalled = false;
TestServiceClient.testMethodNonCompatibleArgRet(intMsg, function(result) {
called = result.testFieldString === "1024";
}, function(status) {
errorCalled = true
})
wait(300)
compare(called && !errorCalled, true, "testMethodNonCompatibleArgRet was not called proper way")
}
}

0 comments on commit d4f112f

Please sign in to comment.