added building of GUI tests to CMake (#3619)

This commit is contained in:
Oliver Stöneberg 2021-12-17 21:49:32 +01:00 committed by GitHub
parent e7db974606
commit c918e1bc50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 121 additions and 11 deletions

View File

@ -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()

View File

@ -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()

7
gui/test/CMakeLists.txt Normal file
View File

@ -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

View File

@ -0,0 +1 @@
add_subdirectory(simple)

View File

@ -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_OBJECTS:lib_objs>
$<TARGET_OBJECTS:tinyxml2_objs>
$<TARGET_OBJECTS:simplecpp_objs>
)
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()

View File

@ -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 {}
};

View File

@ -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)

View File

@ -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_OBJECTS:simplecpp_objs>
)
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)

View File

@ -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)

View File

@ -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)

View File

@ -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 $<TARGET_OBJECTS:tinyxml2_objs>)
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_OBJECTS:lib_objs>
$<TARGET_OBJECTS:simplecpp_objs>
)
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()

View File

@ -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) :