From c918e1bc505992587b31d8a77d4386d487f5cb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 17 Dec 2021 21:49:32 +0100 Subject: [PATCH] added building of GUI tests to CMake (#3619) --- cmake/findDependencies.cmake | 14 +++++++++--- gui/CMakeLists.txt | 5 ++++- gui/test/CMakeLists.txt | 7 ++++++ gui/test/benchmark/CMakeLists.txt | 1 + gui/test/benchmark/simple/CMakeLists.txt | 19 ++++++++++++++++ gui/test/benchmark/simple/benchmarksimple.h | 5 +++-- gui/test/cppchecklibrarydata/CMakeLists.txt | 10 +++++++++ gui/test/filelist/CMakeLists.txt | 15 +++++++++++++ gui/test/projectfile/CMakeLists.txt | 11 +++++++++ gui/test/translationhandler/CMakeLists.txt | 11 +++++++++ gui/test/xmlreportv2/CMakeLists.txt | 25 +++++++++++++++++++++ gui/translationhandler.cpp | 9 ++++---- 12 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 gui/test/CMakeLists.txt create mode 100644 gui/test/benchmark/CMakeLists.txt create mode 100644 gui/test/benchmark/simple/CMakeLists.txt create mode 100644 gui/test/cppchecklibrarydata/CMakeLists.txt create mode 100644 gui/test/filelist/CMakeLists.txt create mode 100644 gui/test/projectfile/CMakeLists.txt create mode 100644 gui/test/translationhandler/CMakeLists.txt create mode 100644 gui/test/xmlreportv2/CMakeLists.txt diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index ffc61743e..cbd50f19b 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -1,8 +1,16 @@ if (BUILD_GUI) - if (NOT WITH_QCHART) - find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help REQUIRED) + if (BUILD_TESTS) + if (NOT WITH_QCHART) + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test REQUIRED) + else() + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test Charts REQUIRED) + endif() else() - find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Charts REQUIRED) + if (NOT WITH_QCHART) + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help REQUIRED) + else() + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Charts REQUIRED) + endif() endif() endif() diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 8f88a996f..213ad5918 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -40,7 +40,7 @@ if (BUILD_GUI) endif() target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport Qt5::Help) if(WITH_QCHART) - target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART ) + target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART) target_link_libraries(cppcheck-gui Qt5::Charts) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -59,4 +59,7 @@ if (BUILD_GUI) install(FILES cppcheck-gui.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps) install(FILES cppcheck-gui.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/64x64/apps) + if (BUILD_TESTS) + add_subdirectory(test) + endif() endif() diff --git a/gui/test/CMakeLists.txt b/gui/test/CMakeLists.txt new file mode 100644 index 000000000..ba349e1f8 --- /dev/null +++ b/gui/test/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(benchmark) +add_subdirectory(cppchecklibrarydata) +add_subdirectory(filelist) +add_subdirectory(projectfile) +add_subdirectory(translationhandler) +add_subdirectory(xmlreportv2) +# TODO: add all tests to CTest \ No newline at end of file diff --git a/gui/test/benchmark/CMakeLists.txt b/gui/test/benchmark/CMakeLists.txt new file mode 100644 index 000000000..6b23a955a --- /dev/null +++ b/gui/test/benchmark/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(simple) \ No newline at end of file diff --git a/gui/test/benchmark/simple/CMakeLists.txt b/gui/test/benchmark/simple/CMakeLists.txt new file mode 100644 index 000000000..78cf81270 --- /dev/null +++ b/gui/test/benchmark/simple/CMakeLists.txt @@ -0,0 +1,19 @@ +qt5_wrap_cpp(test-benchmark-simple_SRC benchmarksimple.h) +add_custom_target(build-testbenchmark-simple-deps SOURCES ${test-benchmark-simple_SRC}) +add_dependencies(gui-build-deps build-testbenchmark-simple-deps) +add_executable(benchmark-simple + ${test-benchmark-simple_SRC} + benchmarksimple.cpp + $ + $ + $ + ) +target_include_directories(benchmark-simple PRIVATE ${CMAKE_SOURCE_DIR}/lib) +target_compile_definitions(benchmark-simple PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(benchmark-simple Qt5::Core Qt5::Test) +if (HAVE_RULES) + target_link_libraries(benchmark-simple ${PCRE_LIBRARY}) +endif() +if (USE_Z3) + target_link_libraries(benchmark-simple ${Z3_LIBRARIES}) +endif() \ No newline at end of file diff --git a/gui/test/benchmark/simple/benchmarksimple.h b/gui/test/benchmark/simple/benchmarksimple.h index ed953ec4d..bc6c28e44 100644 --- a/gui/test/benchmark/simple/benchmarksimple.h +++ b/gui/test/benchmark/simple/benchmarksimple.h @@ -31,6 +31,7 @@ private slots: private: // Empty implementations of ErrorLogger methods. // We don't care about the output in the benchmark tests. - void reportOut(const std::string & outmsg) override {} - void reportErr(const ErrorMessage &msg) override {} + void reportOut(const std::string & /*outmsg*/, Color /*c*/ = Color::Reset) override {} + void reportErr(const ErrorMessage &/*msg*/) override {} + void bughuntingReport(const std::string &/*str*/) override {} }; diff --git a/gui/test/cppchecklibrarydata/CMakeLists.txt b/gui/test/cppchecklibrarydata/CMakeLists.txt new file mode 100644 index 000000000..419e643c5 --- /dev/null +++ b/gui/test/cppchecklibrarydata/CMakeLists.txt @@ -0,0 +1,10 @@ +qt5_wrap_cpp(test-cppchecklibrarydata_SRC testcppchecklibrarydata.h) +add_custom_target(build-cppchecklibrarydata-deps SOURCES ${test-cppchecklibrarydata_SRC}) +add_dependencies(gui-build-deps build-cppchecklibrarydata-deps) +add_executable(test-cppchecklibrarydata + ${test-cppchecklibrarydata_SRC} + testcppchecklibrarydata.cpp + ${CMAKE_SOURCE_DIR}/gui/cppchecklibrarydata.cpp + ) +target_include_directories(test-cppchecklibrarydata PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-cppchecklibrarydata Qt5::Core Qt5::Test) \ No newline at end of file diff --git a/gui/test/filelist/CMakeLists.txt b/gui/test/filelist/CMakeLists.txt new file mode 100644 index 000000000..883840557 --- /dev/null +++ b/gui/test/filelist/CMakeLists.txt @@ -0,0 +1,15 @@ +qt5_wrap_cpp(test-filelist_SRC testfilelist.h) +add_custom_target(build-testfilelist-deps SOURCES ${test-filelist_SRC}) +add_dependencies(gui-build-deps build-testfilelist-deps) +add_executable(test-filelist + ${test-filelist_SRC} + testfilelist.cpp + ${CMAKE_SOURCE_DIR}/gui/filelist.cpp + ${CMAKE_SOURCE_DIR}/lib/pathmatch.cpp + ${CMAKE_SOURCE_DIR}/lib/path.cpp + ${CMAKE_SOURCE_DIR}/lib/utils.cpp + $ + ) +target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp) +target_compile_definitions(test-filelist PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(test-filelist Qt5::Core Qt5::Test) \ No newline at end of file diff --git a/gui/test/projectfile/CMakeLists.txt b/gui/test/projectfile/CMakeLists.txt new file mode 100644 index 000000000..8fd101356 --- /dev/null +++ b/gui/test/projectfile/CMakeLists.txt @@ -0,0 +1,11 @@ +qt5_wrap_cpp(test-projectfile_SRC testprojectfile.h ${CMAKE_SOURCE_DIR}/gui/projectfile.h) +add_custom_target(build-projectfile-deps SOURCES ${test-projectfile_SRC}) +add_dependencies(gui-build-deps build-projectfile-deps) +add_executable(test-projectfile + ${test-projectfile_SRC} + testprojectfile.cpp + ${CMAKE_SOURCE_DIR}/gui/projectfile.cpp + ) +target_include_directories(test-projectfile PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib) +target_compile_definitions(test-projectfile PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(test-projectfile Qt5::Core Qt5::Test) \ No newline at end of file diff --git a/gui/test/translationhandler/CMakeLists.txt b/gui/test/translationhandler/CMakeLists.txt new file mode 100644 index 000000000..1cd8d33d4 --- /dev/null +++ b/gui/test/translationhandler/CMakeLists.txt @@ -0,0 +1,11 @@ +qt5_wrap_cpp(test-translationhandler_SRC testtranslationhandler.h ${CMAKE_SOURCE_DIR}/gui/translationhandler.h) +add_custom_target(build-translationhandler-deps SOURCES ${test-translationhandler_SRC}) +add_dependencies(gui-build-deps build-translationhandler-deps) +add_executable(test-translationhandler + ${test-translationhandler_SRC} + testtranslationhandler.cpp + ${CMAKE_SOURCE_DIR}/gui/common.cpp + ${CMAKE_SOURCE_DIR}/gui/translationhandler.cpp + ) +target_include_directories(test-translationhandler PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-translationhandler Qt5::Core Qt5::Widgets Qt5::Test) \ No newline at end of file diff --git a/gui/test/xmlreportv2/CMakeLists.txt b/gui/test/xmlreportv2/CMakeLists.txt new file mode 100644 index 000000000..a244ea722 --- /dev/null +++ b/gui/test/xmlreportv2/CMakeLists.txt @@ -0,0 +1,25 @@ +qt5_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h) +add_custom_target(build-xmlreportv2-deps SOURCES ${test-xmlreportv2_SRC}) +add_dependencies(gui-build-deps build-xmlreportv2-deps) +if(USE_BUNDLED_TINYXML2) + list(APPEND test-xmlreportv2_SRC $) +endif() +add_executable(test-xmlreportv2 + ${test-xmlreportv2_SRC} + testxmlreportv2.cpp + ${CMAKE_SOURCE_DIR}/gui/erroritem.cpp + ${CMAKE_SOURCE_DIR}/gui/report.cpp + ${CMAKE_SOURCE_DIR}/gui/xmlreport.cpp + ${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp + $ + $ + ) +target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib) +target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(test-xmlreportv2 Qt5::Core Qt5::Test) +if (HAVE_RULES) + target_link_libraries(test-xmlreportv2 ${PCRE_LIBRARY}) +endif() +if (USE_Z3) + target_link_libraries(test-xmlreportv2 ${Z3_LIBRARIES}) +endif() \ No newline at end of file diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 066ee00b9..4deb0a023 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -30,11 +30,10 @@ // Provide own translations for standard buttons. This (garbage) code is needed to enforce them to appear in .ts files even after "lupdate gui.pro" static void unused() { -// NOTE: Keeping semi-colons at end of macro for style preference - Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "OK")); - Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel")); - Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Close")); - Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Save")); + Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "OK")) + Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel")) + Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Close")) + Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Save")) } TranslationHandler::TranslationHandler(QObject *parent) :