Fix unit tests
This commit is contained in:
parent
756f7cf6af
commit
a9ea686577
|
@ -117,6 +117,25 @@ endif()
|
||||||
|
|
||||||
add_compile_options(${COMPILE_OPTIONS})
|
add_compile_options(${COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
add_definitions(
|
||||||
|
-DBOOST_BIND_NO_PLACEHOLDERS
|
||||||
|
-DQT_STRICT_ITERATORS
|
||||||
|
-DQT_NO_CAST_FROM_BYTEARRAY
|
||||||
|
-DQT_USE_QSTRINGBUILDER
|
||||||
|
-DQT_NO_URL_CAST_FROM_STRING
|
||||||
|
-DQT_NO_CAST_TO_ASCII
|
||||||
|
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
|
||||||
|
-DQT_NO_FOREACH
|
||||||
|
-DQT_ASCII_CAST_WARNINGS
|
||||||
|
-DQT_NO_CAST_FROM_ASCII
|
||||||
|
-DQT_NO_KEYWORDS
|
||||||
|
-DQT_NO_SIGNALS_SLOTS_KEYWORDS
|
||||||
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
add_definitions(-DUNICODE)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILD_WERROR)
|
if(BUILD_WERROR)
|
||||||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
||||||
endif()
|
endif()
|
||||||
|
@ -188,7 +207,6 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(GTest)
|
find_package(GTest)
|
||||||
find_library(GMOCK_LIBRARY gmock)
|
|
||||||
|
|
||||||
set(QT_VERSION_MAJOR 6)
|
set(QT_VERSION_MAJOR 6)
|
||||||
set(QT_MIN_VERSION 6.4.0)
|
set(QT_MIN_VERSION 6.4.0)
|
||||||
|
@ -384,28 +402,7 @@ if(WIN32 AND NOT ENABLE_WIN32_CONSOLE)
|
||||||
set_target_properties(strawberry PROPERTIES WIN32_EXECUTABLE TRUE)
|
set_target_properties(strawberry PROPERTIES WIN32_EXECUTABLE TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(strawberry PRIVATE
|
|
||||||
-DBOOST_BIND_NO_PLACEHOLDERS
|
|
||||||
-DQT_STRICT_ITERATORS
|
|
||||||
-DQT_NO_CAST_FROM_BYTEARRAY
|
|
||||||
-DQT_USE_QSTRINGBUILDER
|
|
||||||
-DQT_NO_URL_CAST_FROM_STRING
|
|
||||||
-DQT_NO_CAST_TO_ASCII
|
|
||||||
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
|
|
||||||
-DQT_NO_FOREACH
|
|
||||||
-DQT_ASCII_CAST_WARNINGS
|
|
||||||
-DQT_NO_CAST_FROM_ASCII
|
|
||||||
-DQT_NO_KEYWORDS
|
|
||||||
-DQT_NO_SIGNALS_SLOTS_KEYWORDS
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
target_compile_definitions(strawberry PRIVATE -DUNICODE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
|
||||||
|
|
||||||
src/core/logging.cpp
|
src/core/logging.cpp
|
||||||
src/core/mainwindow.cpp
|
src/core/mainwindow.cpp
|
||||||
src/core/application.cpp
|
src/core/application.cpp
|
||||||
|
@ -1406,7 +1403,9 @@ qt_wrap_cpp(SOURCES ${HEADERS})
|
||||||
qt_wrap_ui(SOURCES ${UI})
|
qt_wrap_ui(SOURCES ${UI})
|
||||||
qt_add_resources(SOURCES data/data.qrc data/icons.qrc)
|
qt_add_resources(SOURCES data/data.qrc data/icons.qrc)
|
||||||
|
|
||||||
target_sources(strawberry PRIVATE ${SOURCES})
|
add_library(strawberry_lib ${SOURCES})
|
||||||
|
|
||||||
|
target_sources(strawberry PRIVATE src/main.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_sources(strawberry PRIVATE windres.rc)
|
target_sources(strawberry PRIVATE windres.rc)
|
||||||
|
@ -1415,7 +1414,7 @@ endif()
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(dist)
|
add_subdirectory(dist)
|
||||||
|
|
||||||
if(GTest_FOUND AND GMOCK_LIBRARY AND Qt${QT_VERSION_MAJOR}Test_FOUND)
|
if(TARGET GTest::GTest AND Qt${QT_VERSION_MAJOR}Test_FOUND)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1440,15 +1439,22 @@ target_include_directories(strawberry PRIVATE
|
||||||
${CMAKE_BINARY_DIR}/src
|
${CMAKE_BINARY_DIR}/src
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_include_directories(strawberry_lib PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
${CMAKE_BINARY_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
if(SINGLEAPPLICATION_INCLUDE_DIRS)
|
if(SINGLEAPPLICATION_INCLUDE_DIRS)
|
||||||
target_include_directories(strawberry SYSTEM PRIVATE ${SINGLEAPPLICATION_INCLUDE_DIRS})
|
target_include_directories(strawberry SYSTEM PRIVATE ${SINGLEAPPLICATION_INCLUDE_DIRS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
|
if(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
|
||||||
target_include_directories(strawberry SYSTEM PRIVATE ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
|
target_include_directories(strawberry_lib SYSTEM PRIVATE ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(strawberry PRIVATE
|
target_link_libraries(strawberry_lib PRIVATE
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
PkgConfig::GLIB
|
PkgConfig::GLIB
|
||||||
PkgConfig::GOBJECT
|
PkgConfig::GOBJECT
|
||||||
|
@ -1484,11 +1490,10 @@ target_link_libraries(strawberry PRIVATE
|
||||||
$<$<BOOL:${FREEBSD}>:execinfo>
|
$<$<BOOL:${FREEBSD}>:execinfo>
|
||||||
$<$<BOOL:${WIN32}>:dsound dwmapi getopt-win::getopt>
|
$<$<BOOL:${WIN32}>:dsound dwmapi getopt-win::getopt>
|
||||||
$<$<BOOL:${MSVC}>:WindowsApp>
|
$<$<BOOL:${MSVC}>:WindowsApp>
|
||||||
${SINGLEAPPLICATION_LIBRARIES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
target_link_libraries(strawberry PRIVATE
|
target_link_libraries(strawberry_lib PRIVATE
|
||||||
"-framework Foundation"
|
"-framework Foundation"
|
||||||
"-framework AppKit"
|
"-framework AppKit"
|
||||||
"-framework Carbon"
|
"-framework Carbon"
|
||||||
|
@ -1500,6 +1505,20 @@ if(APPLE)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(strawberry PRIVATE
|
||||||
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
PkgConfig::GLIB
|
||||||
|
PkgConfig::GOBJECT
|
||||||
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
|
Qt${QT_VERSION_MAJOR}::Network
|
||||||
|
Qt${QT_VERSION_MAJOR}::Sql
|
||||||
|
Qt${QT_VERSION_MAJOR}::Gui
|
||||||
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
|
$<$<BOOL:${HAVE_DBUS}>:Qt${QT_VERSION_MAJOR}::DBus>
|
||||||
|
${SINGLEAPPLICATION_LIBRARIES}
|
||||||
|
strawberry_lib
|
||||||
|
)
|
||||||
|
|
||||||
if(NOT APPLE)
|
if(NOT APPLE)
|
||||||
install(TARGETS strawberry RUNTIME DESTINATION bin)
|
install(TARGETS strawberry RUNTIME DESTINATION bin)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
|
add_custom_target(strawberry_tests echo "Running Strawberry tests" WORKING_DIRECTORY ${CURRENT_BINARY_DIR})
|
||||||
|
add_custom_target(build_tests WORKING_DIRECTORY ${CURRENT_BINARY_DIR})
|
||||||
|
add_dependencies(strawberry_tests build_tests)
|
||||||
|
|
||||||
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
|
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
|
||||||
|
|
||||||
set(TESTUTILS-SOURCES
|
set(TESTUTILS-SOURCES
|
||||||
|
@ -14,21 +18,13 @@ set(TESTUTILS-MOC-HEADERS src/mock_networkaccessmanager.h src/test_utils.h src/t
|
||||||
qt_wrap_cpp(TESTUTILS-SOURCES-MOC ${TESTUTILS-MOC-HEADERS})
|
qt_wrap_cpp(TESTUTILS-SOURCES-MOC ${TESTUTILS-MOC-HEADERS})
|
||||||
|
|
||||||
add_library(test_utils STATIC EXCLUDE_FROM_ALL ${TESTUTILS-SOURCES} ${TESTUTILS-SOURCES-MOC})
|
add_library(test_utils STATIC EXCLUDE_FROM_ALL ${TESTUTILS-SOURCES} ${TESTUTILS-SOURCES-MOC})
|
||||||
target_include_directories(test_utils SYSTEM PRIVATE
|
|
||||||
${GTEST_INCLUDE_DIRS}
|
|
||||||
${GMOCK_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
target_include_directories(test_utils PRIVATE
|
target_include_directories(test_utils PRIVATE
|
||||||
${CMAKE_BINARY_DIR}/src
|
${CMAKE_BINARY_DIR}/src
|
||||||
${CMAKE_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
)
|
)
|
||||||
target_link_directories(test_utils PRIVATE
|
|
||||||
${SQLITE_LIBRARY_DIRS}
|
|
||||||
${TAGLIB_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
target_link_libraries(test_utils PRIVATE
|
target_link_libraries(test_utils PRIVATE
|
||||||
${GTEST_BOTH_LIBRARIES}
|
GTest::GTest
|
||||||
${GMOCK_LIBRARY}
|
GTest::gmock
|
||||||
Qt${QT_VERSION_MAJOR}::Core
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
Qt${QT_VERSION_MAJOR}::Network
|
Qt${QT_VERSION_MAJOR}::Network
|
||||||
|
@ -36,53 +32,58 @@ target_link_libraries(test_utils PRIVATE
|
||||||
Qt${QT_VERSION_MAJOR}::Test
|
Qt${QT_VERSION_MAJOR}::Test
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(strawberry_tests echo "Running Strawberry tests" WORKING_DIRECTORY ${CURRENT_BINARY_DIR})
|
|
||||||
add_custom_target(build_tests WORKING_DIRECTORY ${CURRENT_BINARY_DIR})
|
|
||||||
add_dependencies(strawberry_tests build_tests)
|
|
||||||
|
|
||||||
qt_add_resources(TEST-RESOURCE-SOURCES data/testdata.qrc ${CMAKE_SOURCE_DIR}/data/data.qrc ${CMAKE_SOURCE_DIR}/data/icons.qrc)
|
qt_add_resources(TEST-RESOURCE-SOURCES data/testdata.qrc ${CMAKE_SOURCE_DIR}/data/data.qrc ${CMAKE_SOURCE_DIR}/data/icons.qrc)
|
||||||
|
|
||||||
add_library(test_gui_main STATIC EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} src/main.cpp)
|
|
||||||
target_include_directories(test_gui_main PRIVATE
|
|
||||||
${CMAKE_BINARY_DIR}/src
|
|
||||||
${CMAKE_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(test_gui_main SYSTEM PRIVATE ${GSTREAMER_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
target_link_libraries(test_gui_main PRIVATE strawberry_lib)
|
|
||||||
set_target_properties(test_gui_main PROPERTIES COMPILE_DEFINITIONS GUI)
|
|
||||||
|
|
||||||
add_library(test_main STATIC EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} src/main.cpp)
|
add_library(test_main STATIC EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} src/main.cpp)
|
||||||
target_include_directories(test_main PRIVATE
|
target_include_directories(test_main PRIVATE
|
||||||
${CMAKE_BINARY_DIR}/src
|
${CMAKE_BINARY_DIR}/src
|
||||||
${CMAKE_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
)
|
)
|
||||||
if(HAVE_GSTREAMER)
|
target_link_libraries(test_main PRIVATE
|
||||||
target_include_directories(test_main SYSTEM PRIVATE ${GSTREAMER_INCLUDE_DIRS})
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
endif()
|
PkgConfig::GLIB
|
||||||
target_link_libraries(test_main PRIVATE strawberry_lib)
|
PkgConfig::GOBJECT
|
||||||
|
PkgConfig::GSTREAMER_BASE
|
||||||
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
|
strawberry_lib
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(test_gui_main STATIC EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} src/main.cpp)
|
||||||
|
target_include_directories(test_gui_main PRIVATE
|
||||||
|
${CMAKE_BINARY_DIR}/src
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
target_link_libraries(test_gui_main PRIVATE
|
||||||
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
PkgConfig::GLIB
|
||||||
|
PkgConfig::GOBJECT
|
||||||
|
PkgConfig::GSTREAMER_BASE
|
||||||
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
|
strawberry_lib
|
||||||
|
)
|
||||||
|
set_target_properties(test_gui_main PROPERTIES COMPILE_DEFINITIONS GUI)
|
||||||
|
|
||||||
# Given a file foo_test.cpp, creates a target foo_test and adds it to the test target.
|
# Given a file foo_test.cpp, creates a target foo_test and adds it to the test target.
|
||||||
macro(add_test_file test_source gui_required)
|
macro(add_test_file test_source gui_required)
|
||||||
get_filename_component(TEST_NAME ${test_source} NAME_WE)
|
get_filename_component(TEST_NAME ${test_source} NAME_WE)
|
||||||
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${test_source})
|
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${test_source})
|
||||||
target_include_directories(${TEST_NAME} SYSTEM PRIVATE
|
|
||||||
${GTEST_INCLUDE_DIRS}
|
|
||||||
${GMOCK_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
target_include_directories(${TEST_NAME} PRIVATE
|
target_include_directories(${TEST_NAME} PRIVATE
|
||||||
${CMAKE_BINARY_DIR}/src
|
${CMAKE_BINARY_DIR}/src
|
||||||
${CMAKE_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
${TAGLIB_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
target_link_libraries(${TEST_NAME} PRIVATE
|
target_link_libraries(${TEST_NAME} PRIVATE
|
||||||
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
PkgConfig::GLIB
|
||||||
|
PkgConfig::GOBJECT
|
||||||
|
PkgConfig::GSTREAMER_BASE
|
||||||
Qt${QT_VERSION_MAJOR}::Core
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
Qt${QT_VERSION_MAJOR}::Concurrent
|
Qt${QT_VERSION_MAJOR}::Concurrent
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
|
||||||
Qt${QT_VERSION_MAJOR}::Network
|
Qt${QT_VERSION_MAJOR}::Network
|
||||||
Qt${QT_VERSION_MAJOR}::Sql
|
Qt${QT_VERSION_MAJOR}::Sql
|
||||||
Qt${QT_VERSION_MAJOR}::Test
|
Qt${QT_VERSION_MAJOR}::Test
|
||||||
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
)
|
)
|
||||||
target_link_libraries(${TEST_NAME} PRIVATE test_utils)
|
target_link_libraries(${TEST_NAME} PRIVATE test_utils)
|
||||||
set(GUI_REQUIRED ${gui_required})
|
set(GUI_REQUIRED ${gui_required})
|
||||||
|
|
|
@ -20,7 +20,11 @@
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#ifdef GUI
|
||||||
# include <QApplication>
|
# include <QApplication>
|
||||||
|
#else
|
||||||
|
# include <QCoreApplication>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "logging_env.h"
|
#include "logging_env.h"
|
||||||
#include "metatypes_env.h"
|
#include "metatypes_env.h"
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#ifndef MOCK_NETWORKACCESSMANAGER_H
|
#ifndef MOCK_NETWORKACCESSMANAGER_H
|
||||||
#define MOCK_NETWORKACCESSMANAGER_H
|
#define MOCK_NETWORKACCESSMANAGER_H
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
@ -29,7 +31,6 @@
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
#include "gmock/gmock.h"
|
|
||||||
|
|
||||||
// Usage:
|
// Usage:
|
||||||
// Create a MockNetworkAccessManager.
|
// Create a MockNetworkAccessManager.
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
#include "core/settingsprovider.h"
|
|
||||||
#include "core/sqlrow.h"
|
#include "core/sqlrow.h"
|
||||||
#include "playlist/playlistitem.h"
|
#include "playlist/playlistitem.h"
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
#ifndef MOCK_SETTINGSPROVIDER_H
|
#ifndef MOCK_SETTINGSPROVIDER_H
|
||||||
#define MOCK_SETTINGSPROVIDER_H
|
#define MOCK_SETTINGSPROVIDER_H
|
||||||
|
|
||||||
#include "core/settingsprovider.h"
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#include "core/settingsprovider.h"
|
||||||
|
|
||||||
// clazy:excludeall=function-args-by-value
|
// clazy:excludeall=function-args-by-value
|
||||||
|
|
||||||
class MockSettingsProvider : public SettingsProvider {
|
class MockSettingsProvider : public SettingsProvider {
|
||||||
|
|
|
@ -34,9 +34,6 @@ class ResourcesEnvironment : public ::testing::Environment {
|
||||||
Q_INIT_RESOURCE(data);
|
Q_INIT_RESOURCE(data);
|
||||||
Q_INIT_RESOURCE(icons);
|
Q_INIT_RESOURCE(icons);
|
||||||
Q_INIT_RESOURCE(testdata);
|
Q_INIT_RESOURCE(testdata);
|
||||||
#ifdef HAVE_TRANSLATIONS
|
|
||||||
Q_INIT_RESOURCE(translations);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(ResourcesEnvironment)
|
Q_DISABLE_COPY(ResourcesEnvironment)
|
||||||
|
|
Loading…
Reference in New Issue