CMake: Make qtgrpc tests standalone projects

Add the boilerplate standalone test prelude to each test, so that they
can be opened with an IDE without the qt-cmake-standalone-test script,
but directly with qt-cmake or cmake.

Boilerplate was added using the following scripts:
https://git.qt.io/alcroito/cmake_refactor

Manual adjustments were made where the code was inserted in the wrong
location.

Adapt the grpc client tests manually to make them work in standalone
variant. Also some projects are renamed manually since their
subdirectories contain more than one test target, so the target
name doesn't reflect the project scope.

Task-number: QTBUG-93020
Change-Id: Ifa68664073c5947f28db0a67bab25521d4f9a523
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-07-03 20:39:54 +02:00 committed by Alexey Edelev
parent e9f6546483
commit e66b3ac4c8
32 changed files with 197 additions and 9 deletions

View File

@ -1,6 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_grpc_client LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
include("../shared/test_server/CMakeLists.txt")
endif()
if(NOT TARGET testserver)
return()
endif()
@ -24,6 +32,8 @@ qt_internal_add_test(tst_grpc_client
tst_grpc_client.cpp
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/../shared
DEFINES
TEST_GRPC_SERVER_PATH="$<TARGET_FILE:testserver>"
LIBRARIES
Qt::Test
Qt::Core

View File

@ -26,6 +26,7 @@
# include <grpcpp/security/credentials.h>
#endif
#include "testservice_client.grpc.qpb.h"
#include <message_latency_defs.h>
using namespace Qt::Literals::StringLiterals;
@ -156,7 +157,7 @@ private:
void startServer()
{
serverProc = std::make_unique<QProcess>();
QString serverPath = QFINDTESTDATA("../shared/test_server/testserver");
QString serverPath = QFINDTESTDATA(TEST_GRPC_SERVER_PATH);
QVERIFY2(!serverPath.isEmpty(), "testserver binary is missing");
QObject::connect(serverProc.get(), &QProcess::readyReadStandardOutput, this,
[this] { qInfo() << serverProc->readAllStandardOutput(); });

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_grpc_server LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_grpc_server_qtgrpc_gen
PROTO_FILES
${CMAKE_CURRENT_SOURCE_DIR}/../shared/proto/testservice.proto

View File

@ -0,0 +1,6 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QT_GRPC_TEST_MESSAGE_LATENCY
# define QT_GRPC_TEST_MESSAGE_LATENCY 300
#endif

View File

@ -50,11 +50,15 @@ target_link_libraries(TestServerRunner_grpc_gen
add_library(TestServerRunner
STATIC
testserverrunner.cpp
testserverrunner.h
${CMAKE_CURRENT_LIST_DIR}/testserverrunner.cpp
${CMAKE_CURRENT_LIST_DIR}/testserverrunner.h
)
target_include_directories(TestServerRunner PRIVATE ${out_dir})
target_include_directories(TestServerRunner
PRIVATE
${out_dir}
${CMAKE_CURRENT_LIST_DIR}/..
)
target_link_libraries(TestServerRunner
PRIVATE
@ -63,18 +67,23 @@ target_link_libraries(TestServerRunner
Qt6::Core
)
set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/assets/cert.pem"
PROPERTIES QT_RESOURCE_ALIAS assets/cert.pem)
set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/assets/key.pem"
PROPERTIES QT_RESOURCE_ALIAS assets/key.pem)
qt_add_resources(TestServerRunner
"keys"
PREFIX
"/"
FILES
"assets/cert.pem"
"assets/key.pem"
"${CMAKE_CURRENT_LIST_DIR}/assets/cert.pem"
"${CMAKE_CURRENT_LIST_DIR}/assets/key.pem"
)
qt_internal_add_executable(testserver
SOURCES
testserver.cpp
${CMAKE_CURRENT_LIST_DIR}/testserver.cpp
LIBRARIES
TestServerRunner
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
@ -83,7 +92,7 @@ qt_internal_add_executable(testserver
qt_internal_add_executable(securetestserver
SOURCES
securetestserver.cpp
${CMAKE_CURRENT_LIST_DIR}/securetestserver.cpp
LIBRARIES
TestServerRunner
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"

View File

@ -8,6 +8,8 @@
#include <QString>
#include "testservice.grpc.pb.h"
#include <message_latency_defs.h>
#include <grpc++/grpc++.h>
#include <memory>

View File

@ -1,6 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_grpc_ssl_client LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
include("../shared/test_server/CMakeLists.txt")
endif()
if(NOT TARGET securetestserver)
return()
endif()
@ -25,6 +33,8 @@ qt_internal_add_test(tst_grpc_ssl_client
tst_grpc_ssl_client.cpp
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/../shared
DEFINES
TEST_GRPC_SERVER_PATH="$<TARGET_FILE:securetestserver>"
LIBRARIES
Qt::Test
Qt::Core

View File

@ -68,7 +68,7 @@ private:
void startServer()
{
serverProc = std::make_unique<QProcess>();
QString serverPath = QFINDTESTDATA("../shared/test_server/securetestserver");
QString serverPath = QFINDTESTDATA(TEST_GRPC_SERVER_PATH);
QVERIFY2(!serverPath.isEmpty(), "securetestserver binary is missing");
serverProc->start(serverPath);
serverProc->waitForStarted();

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_grpc_unattached_channel LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_grpc_unattached_channel_qtgrpc_gen
PROTO_FILES
${CMAKE_CURRENT_SOURCE_DIR}/../shared/proto/testservice.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_qtgrpcgen LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_qtgrpcgen
SOURCES
tst_qtgrpcgen.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_basic LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_basictypes_gen
PROTO_FILES
proto/basicmessages.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_converters LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_converter
SOURCES
tst_protobuf_converter.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_duplicated_metatypes LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_duplicatedmetatypes
SOURCES
tst_protobuf_duplicatedmetatypes.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_enums LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_enumtypes_gen
PROTO_FILES
enummessages.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_externalpackage LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_externalpackage
SOURCES
tst_protobuf_externalpackage.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_extranamespace LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_extranamespace_qtprotobuf_gen
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
PROTO_FILES proto/extranamespace.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_nested LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_nestedtypes_qtprotobuf_gen
PROTO_FILES
proto/nestedmessages.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_nopackage LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_nopackagetypes_qtprotobuf_gen
PROTO_FILES
../../shared/data/proto/nopackage.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_qprotobuflazymessagepointer LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_qprotobuflazymessagepointer
SOURCES
tst_qprotobuflazymessagepointer.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_qprotobufoneof LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_qprotobufoneof
SOURCES
tst_qprotobufoneof.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_recursive LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_recursive_gen
PROTO_FILES
recursive.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_sequence LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_sequence
SOURCES
tst_protobuf_sequence.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_syntax LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt6_add_protobuf(tst_protobuf_syntax_qtprotobuf_gen
PROTO_FILES
../../shared/data/proto/syntax.proto

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_wellknown LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_any
SOURCES
tst_protobuf_any.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_qtprotobufgen LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_qtprotobufgen
SOURCES
tst_qtprotobufgen.cpp

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_basic_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_basictypes_qml
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_enums_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_enumtypes_qml
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_messagelists_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_repeated_qml
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_nested_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_nestedtypes_qtprotobuf_qmltest
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_nopackage_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_nopackage_qml
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_syntax_qml LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_syntax_qml
QMLTEST
SOURCES

View File

@ -1,6 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_protobuf_protobufqttypes LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_protobuf_qtcoretypes
SOURCES
qtprotobufqttypescoretest.cpp