1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(test): Move mocks into their own library

Avoid re-compiling sources for each test that uses them.
This commit is contained in:
Anthony Bilinski 2022-02-26 20:02:40 -08:00
parent 40846f886c
commit bc751c8e1c
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
12 changed files with 44 additions and 17 deletions

View File

@ -22,24 +22,21 @@
enable_testing()
set(MOCK_SOURCES
test/mock/mockcoreidhandler.cpp
test/mock/mockgroupquery.cpp
test/mock/mockcoresettings.cpp
)
function(auto_test subsystem module extra_deps)
add_executable(test_${module}
test/${subsystem}/${module}_test.cpp ${extra_deps} ${MOCK_SOURCES})
test/${subsystem}/${module}_test.cpp ${extra_deps})
target_link_libraries(test_${module}
${PROJECT_NAME}_static
${CHECK_LIBRARIES}
Qt5::Test)
Qt5::Test
mock_library)
add_test(
NAME test_${module}
COMMAND ${TEST_CROSSCOMPILING_EMULATOR} test_${module})
endfunction()
add_subdirectory(test/mock)
auto_test(core core "${${PROJECT_NAME}_RESOURCES}")
auto_test(core core_online "${${PROJECT_NAME}_RESOURCES}")
auto_test(core contactid "")

View File

@ -23,7 +23,7 @@
#include "src/model/ibootstraplistgenerator.h"
#include "src/net/bootstrapnodeupdater.h"
#include "src/persistence/settings.h"
#include "test/mock/mockcoresettings.h"
#include "mock/mockcoresettings.h"
#include <QSignalSpy>
#include <QtGlobal>

View File

@ -23,7 +23,7 @@
#include "src/net/bootstrapnodeupdater.h"
#include "src/model/ibootstraplistgenerator.h"
#include "src/persistence/settings.h"
#include "test/mock/mockcoresettings.h"
#include "mock/mockcoresettings.h"
#include <QtTest/QtTest>
#include <QtGlobal>

30
test/mock/CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
# Copyright © 2022 by The qTox Project Contributors
#
# This file is part of qTox, a Qt-based graphical interface for Tox.
# qTox is libre software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qTox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qTox. If not, see <http://www.gnu.org/licenses/>
add_library(mock_library STATIC
include/mock/mockcoreidhandler.h
src/mockcoreidhandler.cpp
include/mock/mockgroupquery.h
src/mockgroupquery.cpp
include/mock/mockcoresettings.h
src/mockcoresettings.cpp)
target_include_directories(mock_library PUBLIC include/)
target_link_libraries(mock_library
util_library
Qt5::Core
Qt5::Network
Qt5::Gui)

View File

@ -17,6 +17,6 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mockcoreidhandler.h"
#include "mock/mockcoreidhandler.h"
MockCoreIdHandler::~MockCoreIdHandler() = default;

View File

@ -17,6 +17,6 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "test/mock/mockcoresettings.h"
#include "mock/mockcoresettings.h"
MockSettings::~MockSettings() = default;

View File

@ -17,6 +17,6 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mockgroupquery.h"
#include "mock/mockgroupquery.h"
MockGroupQuery::~MockGroupQuery() = default;

View File

@ -25,8 +25,8 @@
#include "src/persistence/igroupsettings.h"
#include "util/interface.h"
#include "test/mock/mockcoreidhandler.h"
#include "test/mock/mockgroupquery.h"
#include "mock/mockcoreidhandler.h"
#include "mock/mockgroupquery.h"
#include <QObject>
#include <QtTest/QtTest>

View File

@ -20,8 +20,8 @@
#include "src/model/notificationgenerator.h"
#include "test/mock/mockcoreidhandler.h"
#include "test/mock/mockgroupquery.h"
#include "mock/mockcoreidhandler.h"
#include "mock/mockgroupquery.h"
#include <QObject>
#include <QtTest/QtTest>