Browse Source

Fix ci build

- Change qml_grpc test suite singleton registration, to support
  Qt version lower than 5.14
- Add QT_PROTOBUF_NATIVE_GRPC_CHANNEL to CMake CACHE
- Fix minor issue in gRPCLookup
Alexey Edelev 4 years ago
parent
commit
7331233afb
4 changed files with 11 additions and 7 deletions
  1. 1 1
      cmake/gRPCLookup.cmake
  2. 2 0
      src/grpc/CMakeLists.txt
  3. 1 1
      tests/test_grpc_qml/http2.cpp
  4. 7 5
      tests/test_grpc_qml/test.h

+ 1 - 1
cmake/gRPCLookup.cmake

@@ -23,7 +23,7 @@ if(NOT gRPC_FOUND)
     endif()
 
     find_library(gRPC_CPP_LIBRARY grpc++)
-    if(NOT TARGET gRPC::grpc++ AND NOT gRPC_CPP_LIBRARY STREQUAL gRPC_LIBRARY-NOTFOUND)
+    if(NOT TARGET gRPC::grpc++ AND NOT gRPC_CPP_LIBRARY STREQUAL gRPC_CPP_LIBRARY-NOTFOUND)
         add_library(gRPC::grpc++ SHARED IMPORTED)
         set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_LOCATION ${gRPC_CPP_LIBRARY} INTERFACE_LINK_LIBRARIES protobuf::libprotobuf)
     endif()

+ 2 - 0
src/grpc/CMakeLists.txt

@@ -14,6 +14,8 @@ include(${QT_PROTOBUF_CMAKE_DIR}/Coverage.cmake)
 include(${QT_PROTOBUF_CMAKE_DIR}/GenerateQtHeaders.cmake)
 include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
 
+set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF CACHE BOOL "Enable native gRPC channel implementation")
+
 file(GLOB SOURCES qgrpcasyncoperationbase.cpp
     qgrpcasyncreply.cpp
     qgrpcsubscription.cpp

+ 1 - 1
tests/test_grpc_qml/http2.cpp

@@ -33,4 +33,4 @@ int main(int argc, char **argv)
 
 	TestSetup setup(std::make_shared<QGrpcHttp2Channel>(echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
 	return quick_test_main_with_setup(argc, argv, "qtgrpc_qml_test_http2", nullptr, &setup);
-}
+}

+ 7 - 5
tests/test_grpc_qml/test.h

@@ -39,18 +39,20 @@
 using namespace qtprotobufnamespace::tests;
 using namespace QtProtobuf;
 
+static std::unique_ptr<TestServiceClient> clientInstance;
+
 class TestSetup : public QObject {
     Q_OBJECT
 public:
     TestSetup(std::shared_ptr<QAbstractGrpcChannel> channel) {
+        clientInstance.reset(new TestServiceClient);
         QtProtobuf::qRegisterProtobufTypes();
         Q_PROTOBUF_IMPORT_QUICK_PLUGIN()
         Q_GRPC_IMPORT_QUICK_PLUGIN()
-        qmlRegisterSingletonType<TestServiceClient>("qtprotobufnamespace.tests", 1, 0, "TestServiceClient", [channel](QQmlEngine *engine, QJSEngine *) -> QObject *{
-            static TestServiceClient clientInstance;
-            clientInstance.attachChannel(channel);
-            engine->setObjectOwnership(&clientInstance, QQmlEngine::CppOwnership);
-            return &clientInstance;
+        clientInstance->attachChannel(channel);
+        qmlRegisterSingletonType<TestServiceClient>("qtprotobufnamespace.tests", 1, 0, "TestServiceClient", [](QQmlEngine *engine, QJSEngine *) -> QObject *{
+            engine->setObjectOwnership(clientInstance.get(), QQmlEngine::CppOwnership);
+            return clientInstance.get();
         });
     }
     ~TestSetup() = default;