Procházet zdrojové kódy

Add test for incompatible gRPC argument/return values

Alexey Edelev před 4 roky
rodič
revize
3add1f886c

+ 11 - 0
tests/test_grpc/clienttest.cpp

@@ -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 - 0
tests/test_grpc/echoserver/main.cpp

@@ -63,6 +63,14 @@ public:
     {
         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 *[])

+ 4 - 0
tests/test_grpc/proto/simpletest.proto

@@ -6,6 +6,10 @@ message SimpleStringMessage {
     string testFieldString = 6;
 }
 
+message SimpleIntMessage {
+    sint32 testField= 1;
+}
+
 message BlobMessage {
     bytes testBytes = 1;
 }

+ 1 - 0
tests/test_grpc/proto/testservice.proto

@@ -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 - 0
tests/test_grpc_qml/qml/tst_grpc.qml

@@ -37,6 +37,11 @@ TestCase {
         testFieldString: "Test string"
     }
 
+    SimpleIntMessage {
+        id: intMsg
+        testField: 1024
+    }
+
     QtObject {
         id: returnMsg
         property string ret: serverStreamSubscription.returnValue.testFieldString
@@ -158,4 +163,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")
+    }
 }