From f40433d28fc0d205876f772d5b6700670a84b157 Mon Sep 17 00:00:00 2001 From: Martin Delille Date: Fri, 7 Apr 2023 10:24:11 +0200 Subject: [PATCH] qt ctest (#14968) * [cpp-qt-client] Fix warning about deprecated count() method * [cpp-qt-client] Ignore build directory * [cpp-qt-client] Use ctest * Fix CMakeLists.txt for cpp-qt-client --- .github/workflows/samples-cpp-qt-client.yaml | 6 +- .../cpp-qt-client/CMakeLists.txt.mustache | 69 +++++++++++-------- .../cpp-qt-client/helpers-body.mustache | 2 +- samples/client/petstore/cpp-qt/.gitignore | 1 + samples/client/petstore/cpp-qt/CMakeLists.txt | 13 ++-- .../petstore/cpp-qt/build-and-test.bash | 10 +-- .../petstore/cpp-qt/client/CMakeLists.txt | 67 ++++++++++-------- .../petstore/cpp-qt/client/PFXHelpers.cpp | 2 +- 8 files changed, 98 insertions(+), 72 deletions(-) create mode 100644 samples/client/petstore/cpp-qt/.gitignore diff --git a/.github/workflows/samples-cpp-qt-client.yaml b/.github/workflows/samples-cpp-qt-client.yaml index 2ef3fbc96a1d..e1e6e4e5dc44 100644 --- a/.github/workflows/samples-cpp-qt-client.yaml +++ b/.github/workflows/samples-cpp-qt-client.yaml @@ -23,12 +23,16 @@ jobs: - ubuntu-latest - macOS-latest - windows-latest + include: + - os: windows-latest + tools: 'tools_openssl_x64' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - uses: jurplel/install-qt-action@v3 with: version: ${{ matrix.qt-version }} + tools: ${{ matrix.tools }} - name: Build working-directory: "samples/client/petstore/cpp-qt" - run: ./build-and-test.bash + run: cmake . && cmake --build . diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache index ae484139eb4a..338fbf63591e 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache @@ -2,39 +2,53 @@ cmake_minimum_required(VERSION 3.2) project({{{packageName}}}) -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CXX_STANDARD_REQUIRED ON) - -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() - -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Gui) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -file(GLOB_RECURSE HEADER_FILES "*.h") -file(GLOB_RECURSE SOURCE_FILES "*.cpp") - -add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) - -target_compile_options(${PROJECT_NAME} - PRIVATE - $<$,$,$>: - -Wall -Wno-unused-variable> -) +add_library(${PROJECT_NAME} +{{#models}} +{{#model}} + {{classname}}.h +{{/model}} +{{/models}} +{{#apiInfo}} +{{#apis}} +{{#operations}} + {{classname}}.h +{{/operations}} +{{/apis}} +{{/apiInfo}} + {{prefix}}Helpers.h + {{prefix}}HttpRequest.h + {{prefix}}Object.h + {{prefix}}Enum.h + {{prefix}}HttpFileElement.h + {{prefix}}ServerConfiguration.h + {{prefix}}ServerVariable.h + {{prefix}}Oauth.h +{{#models}} +{{#model}} + {{classname}}.cpp +{{/model}} +{{/models}} +{{#apiInfo}} +{{#apis}} +{{#operations}} + {{classname}}.cpp +{{/operations}} +{{/apis}} +{{/apiInfo}} + {{prefix}}Helpers.cpp + {{prefix}}HttpRequest.cpp + {{prefix}}HttpFileElement.cpp + {{prefix}}Oauth.cpp + ) target_include_directories(${PROJECT_NAME} PUBLIC - $ + $ $ ) @@ -48,11 +62,6 @@ target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES}{{/contentCompression}} ) -if(NOT APPLE) - find_package(OpenSSL REQUIRED) - target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto) -endif() - configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache index 0e19b1771fb5..707a93be1396 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache @@ -225,7 +225,7 @@ bool fromStringValue(const QString &inStr, QByteArray &value) { } else { value.clear(); value.append(inStr.toUtf8()); - return value.count() > 0; + return value.size() > 0; } } diff --git a/samples/client/petstore/cpp-qt/.gitignore b/samples/client/petstore/cpp-qt/.gitignore new file mode 100644 index 000000000000..378eac25d311 --- /dev/null +++ b/samples/client/petstore/cpp-qt/.gitignore @@ -0,0 +1 @@ +build diff --git a/samples/client/petstore/cpp-qt/CMakeLists.txt b/samples/client/petstore/cpp-qt/CMakeLists.txt index 5fb20c83ec91..4ec3a21f4904 100644 --- a/samples/client/petstore/cpp-qt/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt/CMakeLists.txt @@ -1,20 +1,25 @@ cmake_minimum_required(VERSION 3.2) -project(cpp-qt5-petstore) +project(cpp-qt-petstore) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui Test) + add_subdirectory(client) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Test) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test) -add_executable(${PROJECT_NAME} +add_executable(cpp-qt-petstore PetStore/main.cpp PetStore/PetApiTests.cpp PetStore/StoreApiTests.cpp PetStore/UserApiTests.cpp ) -target_link_libraries(${PROJECT_NAME} PRIVATE CppQtPetstoreClient Qt${QT_VERSION_MAJOR}::Test) +target_link_libraries(cpp-qt-petstore PRIVATE CppQtPetstoreClient Qt${QT_VERSION_MAJOR}::Test) + +enable_testing() + +add_test(NAME cpp-qt-petstore-test COMMAND cpp-qt-petstore) diff --git a/samples/client/petstore/cpp-qt/build-and-test.bash b/samples/client/petstore/cpp-qt/build-and-test.bash index 4104bdac1bc7..9602f77ede54 100755 --- a/samples/client/petstore/cpp-qt/build-and-test.bash +++ b/samples/client/petstore/cpp-qt/build-and-test.bash @@ -8,14 +8,14 @@ cd build cmake .. -make +cmake --build . if [[ -z "${RUN_VALGRIND_TESTS}" ]]; then - echo "Running Qt5 Petstore Tests" - ./cpp-qt5-petstore + echo "Running Qt Petstore Tests" + ctest else - echo "Running Qt5 Petstore Tests with Valgrind" - valgrind --leak-check=full ./cpp-qt5-petstore |& tee result.log || exit 1 + echo "Running Qt Petstore Tests with Valgrind" + valgrind --leak-check=full ./cpp-qt-petstore |& tee result.log || exit 1 testCount=$(cat result.log | grep 'Finished testing of' | wc -l) if [ $testCount == 3 ] then diff --git a/samples/client/petstore/cpp-qt/client/CMakeLists.txt b/samples/client/petstore/cpp-qt/client/CMakeLists.txt index 869830afa196..fb37e4dc2d50 100644 --- a/samples/client/petstore/cpp-qt/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt/client/CMakeLists.txt @@ -2,39 +2,51 @@ cmake_minimum_required(VERSION 3.2) project(CppQtPetstoreClient) -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CXX_STANDARD_REQUIRED ON) - -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() - -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Gui) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -file(GLOB_RECURSE HEADER_FILES "*.h") -file(GLOB_RECURSE SOURCE_FILES "*.cpp") - -add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) - -target_compile_options(${PROJECT_NAME} - PRIVATE - $<$,$,$>: - -Wall -Wno-unused-variable> -) +add_library(${PROJECT_NAME} + PFXApiResponse.h + PFXCategory.h + PFXOrder.h + PFXPet.h + PFXTag.h + PFXTestAnyType.h + PFXUser.h + PFXPetApi.h + PFXPrimitivesApi.h + PFXStoreApi.h + PFXUserApi.h + PFXHelpers.h + PFXHttpRequest.h + PFXObject.h + PFXEnum.h + PFXHttpFileElement.h + PFXServerConfiguration.h + PFXServerVariable.h + PFXOauth.h + PFXApiResponse.cpp + PFXCategory.cpp + PFXOrder.cpp + PFXPet.cpp + PFXTag.cpp + PFXTestAnyType.cpp + PFXUser.cpp + PFXPetApi.cpp + PFXPrimitivesApi.cpp + PFXStoreApi.cpp + PFXUserApi.cpp + PFXHelpers.cpp + PFXHttpRequest.cpp + PFXHttpFileElement.cpp + PFXOauth.cpp + ) target_include_directories(${PROJECT_NAME} PUBLIC - $ + $ $ ) @@ -46,11 +58,6 @@ target_link_libraries(${PROJECT_NAME} ) -if(NOT APPLE) - find_package(OpenSSL REQUIRED) - target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto) -endif() - configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" diff --git a/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp b/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp index aab9ed05f202..a25beb3c5173 100644 --- a/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp @@ -233,7 +233,7 @@ bool fromStringValue(const QString &inStr, QByteArray &value) { } else { value.clear(); value.append(inStr.toUtf8()); - return value.count() > 0; + return value.size() > 0; } }