Skip to content

Commit

Permalink
qt ctest (#14968)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
MartinDelille committed Apr 7, 2023
1 parent b2be167 commit f40433d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 72 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/samples-cpp-qt-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

Expand All @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpp-qt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
13 changes: 9 additions & 4 deletions samples/client/petstore/cpp-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 5 additions & 5 deletions samples/client/petstore/cpp-qt/build-and-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 37 additions & 30 deletions samples/client/petstore/cpp-qt/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/client/PFXHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit f40433d

Please sign in to comment.