From e8ba5dafc63de65ed8a469353b808e391633f0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 13 Apr 2016 01:24:55 +0200 Subject: NOISSUE remove dead unit tests and reorganize CMake code related to unit tests --- cmake/UnitTest.cmake | 49 +++++++++ cmake/UnitTest/TestUtil.h | 28 ++++++ cmake/UnitTest/generate_test_data.cmake | 26 +++++ cmake/UnitTest/test.manifest | 27 +++++ cmake/UnitTest/test.rc | 28 ++++++ tests/CMakeLists.txt | 148 +++++++++++++++------------- tests/TestUtil.h | 27 ----- tests/copy_tests.cmake | 13 --- tests/data/1.json | 6 +- tests/data/2.json | 4 +- tests/data/channels.json | 4 +- tests/test.manifest | 27 ----- tests/test.rc | 28 ------ tests/test_config.h.in | 3 - tests/tst_BaseWonkoEntityLocalLoadTask.cpp | 15 --- tests/tst_BaseWonkoEntityRemoteLoadTask.cpp | 15 --- tests/tst_UpdateChecker.cpp | 5 +- tests/tst_WonkoVersionList.cpp | 15 --- 18 files changed, 250 insertions(+), 218 deletions(-) create mode 100644 cmake/UnitTest.cmake create mode 100644 cmake/UnitTest/TestUtil.h create mode 100644 cmake/UnitTest/generate_test_data.cmake create mode 100644 cmake/UnitTest/test.manifest create mode 100644 cmake/UnitTest/test.rc delete mode 100644 tests/TestUtil.h delete mode 100644 tests/copy_tests.cmake delete mode 100644 tests/test.manifest delete mode 100644 tests/test.rc delete mode 100644 tests/test_config.h.in delete mode 100644 tests/tst_BaseWonkoEntityLocalLoadTask.cpp delete mode 100644 tests/tst_BaseWonkoEntityRemoteLoadTask.cpp delete mode 100644 tests/tst_WonkoVersionList.cpp diff --git a/cmake/UnitTest.cmake b/cmake/UnitTest.cmake new file mode 100644 index 00000000..1cbb2b60 --- /dev/null +++ b/cmake/UnitTest.cmake @@ -0,0 +1,49 @@ +find_package(Qt5Test REQUIRED) + +set(TEST_RESOURCE_PATH ${CMAKE_CURRENT_LIST_DIR}) + +message(${TEST_RESOURCE_PATH}) + +function(add_unit_test name) + set(options "") + set(oneValueArgs DATA) + set(multiValueArgs SOURCES LIBS QT) + + cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + if(WIN32) + add_executable(tst_${name} ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc) + else() + add_executable(tst_${name} ${OPT_SOURCES}) + endif() + + if(NOT "${OPT_DATA}" STREQUAL "") + set(TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data") + set(TEST_DATA_PATH_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${OPT_DATA}") + message("From ${TEST_DATA_PATH_SRC} to ${TEST_DATA_PATH}") + string(REGEX REPLACE "[/\\:]" "_" DATA_TARGET_NAME "${TEST_DATA_PATH_SRC}") + if(UNIX) + # on unix we get the third / from the filename + set(TEST_DATA_URL "file://${TEST_DATA_PATH}") + else() + # we don't on windows, so we have to add it ourselves + set(TEST_DATA_URL "file:///${TEST_DATA_PATH}") + endif() + if(NOT TARGET "${DATA_TARGET_NAME}") + add_custom_target(${DATA_TARGET_NAME}) + add_dependencies(tst_${name} ${DATA_TARGET_NAME}) + add_custom_command( + TARGET ${DATA_TARGET_NAME} + COMMAND ${CMAKE_COMMAND} "-DTEST_DATA_URL=${TEST_DATA_URL}" -DSOURCE=${TEST_DATA_PATH_SRC} -DDESTINATION=${TEST_DATA_PATH} -P ${TEST_RESOURCE_PATH}/UnitTest/generate_test_data.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() + endif() + + target_link_libraries(tst_${name} ${OPT_LIBS}) + qt5_use_modules(tst_${name} Test ${OPT_QT}) + + target_include_directories(tst_${name} PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/") + + add_test(NAME ${name} COMMAND tst_${name}) +endfunction() diff --git a/cmake/UnitTest/TestUtil.h b/cmake/UnitTest/TestUtil.h new file mode 100644 index 00000000..84f18a2e --- /dev/null +++ b/cmake/UnitTest/TestUtil.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +#define expandstr(s) expandstr2(s) +#define expandstr2(s) #s + +class TestsInternal +{ +public: + static QByteArray readFile(const QString &fileName) + { + QFile f(fileName); + f.open(QFile::ReadOnly); + return f.readAll(); + } + static QString readFileUtf8(const QString &fileName) + { + return QString::fromUtf8(readFile(fileName)); + } +}; + +#define MULTIMC_GET_TEST_FILE(file) TestsInternal::readFile(QFINDTESTDATA(file)) +#define MULTIMC_GET_TEST_FILE_UTF8(file) TestsInternal::readFileUtf8(QFINDTESTDATA(file)) + diff --git a/cmake/UnitTest/generate_test_data.cmake b/cmake/UnitTest/generate_test_data.cmake new file mode 100644 index 00000000..9de7410b --- /dev/null +++ b/cmake/UnitTest/generate_test_data.cmake @@ -0,0 +1,26 @@ +# Copy files from source directory to destination directory, substituting any +# variables. Create destination directory if it does not exist. + +function(configure_files srcDir destDir) + message(STATUS "Configuring directory ${destDir} from ${srcDir}") + make_directory(${destDir}) + + file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*) + foreach(templateFile ${templateFiles}) + set(srcTemplatePath ${srcDir}/${templateFile}) + if(NOT IS_DIRECTORY ${srcTemplatePath}) + message(STATUS "Configuring file ${templateFile}") + configure_file( + ${srcTemplatePath} + ${destDir}/${templateFile} + @ONLY + NEWLINE_STYLE LF + ) + else() + message(STATUS "Recursing? ${srcTemplatePath}") + configure_files("${srcTemplatePath}" "${destDir}/${templateFile}") + endif() + endforeach() +endfunction() + +configure_files(${SOURCE} ${DESTINATION}) \ No newline at end of file diff --git a/cmake/UnitTest/test.manifest b/cmake/UnitTest/test.manifest new file mode 100644 index 00000000..8b4dbb98 --- /dev/null +++ b/cmake/UnitTest/test.manifest @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + Custom Minecraft launcher for managing multiple installs. + + + + + + + + + + + \ No newline at end of file diff --git a/cmake/UnitTest/test.rc b/cmake/UnitTest/test.rc new file mode 100644 index 00000000..a288dba6 --- /dev/null +++ b/cmake/UnitTest/test.rc @@ -0,0 +1,28 @@ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include + +1 RT_MANIFEST "test.manifest" + +VS_VERSION_INFO VERSIONINFO +FILEVERSION 1,0,0,0 +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_APP +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "MultiMC Contributors" + VALUE "FileDescription", "Testcase" + VALUE "FileVersion", "1.0.0.0" + VALUE "ProductName", "MultiMC Testcase" + VALUE "ProductVersion", "5" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0000, 0x04b0 // Unicode + END +END diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 12fa4108..667aecd1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,66 +1,82 @@ -# run the unit tests with `make test` -find_package(Qt5Test) - -add_custom_target(test_data) - -unset(MultiMC_TESTS) -macro(add_unit_test name) - unset(srcs) - foreach(arg ${testname} ${ARGN}) - list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) - endforeach() - if(WIN32) - list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/test.rc) - endif() - add_executable(tst_${name} ${srcs}) - add_dependencies(tst_${name} test_data) - target_link_libraries(tst_${name} MultiMC_logic) - qt5_use_modules(tst_${name} Test Core Network) - list(APPEND MultiMC_TESTS tst_${name}) - add_test(NAME ${name} COMMAND tst_${name}) -endmacro() - -# Tests BEGIN # - -add_unit_test(gradlespecifier tst_gradlespecifier.cpp) -add_unit_test(userutils tst_userutils.cpp) -add_unit_test(modutils tst_modutils.cpp) -add_unit_test(inifile tst_inifile.cpp) -add_unit_test(FileSystem tst_FileSystem.cpp) -add_unit_test(Library tst_Library.cpp) -add_unit_test(UpdateChecker tst_UpdateChecker.cpp) -add_unit_test(DownloadTask tst_DownloadTask.cpp) -add_unit_test(filematchers tst_filematchers.cpp) -add_unit_test(ModList tst_ModList.cpp) -# add_unit_test(Resource tst_Resource.cpp) -add_unit_test(GZip tst_GZip.cpp) -add_unit_test(JavaVersion tst_JavaVersion.cpp) -add_unit_test(ParseUtils tst_ParseUtils.cpp) -add_unit_test(MojangVersionFormat tst_MojangVersionFormat.cpp) -add_unit_test(BaseWonkoEntityLocalLoadTask tst_BaseWonkoEntityLocalLoadTask.cpp) -add_unit_test(BaseWonkoEntityRemoteLoadTask tst_BaseWonkoEntityRemoteLoadTask.cpp) -add_unit_test(WonkoVersionList tst_WonkoVersionList.cpp) -add_unit_test(WonkoIndex tst_WonkoIndex.cpp) - -# Tests END # - - -set(MultiMC_TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data") -set(MultiMC_TEST_DATA_PATH_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/data") -set(MultiMC_TEST_DATA_PATH_SOURCE_RAW "${CMAKE_CURRENT_SOURCE_DIR}/data_raw") - -if(UNIX) - # on unix we get the third / from the filename - set(MultiMC_TEST_DATA_URL "file://${MultiMC_TEST_DATA_PATH}") -else() - # we don't on windows, so we have to add it ourselves - set(MultiMC_TEST_DATA_URL "file:///${MultiMC_TEST_DATA_PATH}") -endif() - -# clean and replace test data -add_custom_command( - TARGET test_data - COMMAND ${CMAKE_COMMAND} -DMultiMC_TEST_DATA_URL=${MultiMC_TEST_DATA_URL} -DMultiMC_TEST_DATA_PATH=${MultiMC_TEST_DATA_PATH} -DMultiMC_TEST_DATA_PATH_SOURCE=${MultiMC_TEST_DATA_PATH_SOURCE} -DMultiMC_TEST_DATA_PATH_SOURCE_RAW=${MultiMC_TEST_DATA_PATH_SOURCE_RAW} -P ${CMAKE_CURRENT_SOURCE_DIR}/copy_tests.cmake -) - -configure_file(test_config.h.in test_config.h @ONLY) +include(UnitTest) + +add_unit_test(gradlespecifier + SOURCES tst_gradlespecifier.cpp + LIBS MultiMC_logic + ) + +add_unit_test(userutils + SOURCES tst_userutils.cpp + LIBS MultiMC_logic + ) + +add_unit_test(modutils + SOURCES tst_modutils.cpp + LIBS MultiMC_logic + ) + +add_unit_test(inifile + SOURCES tst_inifile.cpp + LIBS MultiMC_logic + ) + +add_unit_test(FileSystem + SOURCES tst_FileSystem.cpp + LIBS MultiMC_logic + ) + +add_unit_test(Library + SOURCES tst_Library.cpp + LIBS MultiMC_logic + ) + +add_unit_test(UpdateChecker + SOURCES tst_UpdateChecker.cpp + LIBS MultiMC_logic + DATA data + ) + +add_unit_test(DownloadTask + SOURCES tst_DownloadTask.cpp + LIBS MultiMC_logic + DATA data_raw + ) + +add_unit_test(filematchers + SOURCES tst_filematchers.cpp + LIBS MultiMC_logic + ) + +add_unit_test(ModList + SOURCES tst_ModList.cpp + LIBS MultiMC_logic + ) + +# add_unit_test(Resource +# SOURCES tst_Resource.cpp +# ) + +add_unit_test(GZip + SOURCES tst_GZip.cpp + LIBS MultiMC_logic + ) + +add_unit_test(JavaVersion + SOURCES tst_JavaVersion.cpp + LIBS MultiMC_logic + ) + +add_unit_test(ParseUtils + SOURCES tst_ParseUtils.cpp + LIBS MultiMC_logic + ) + +add_unit_test(MojangVersionFormat + SOURCES tst_MojangVersionFormat.cpp + LIBS MultiMC_logic + ) + +add_unit_test(WonkoIndex + SOURCES tst_WonkoIndex.cpp + LIBS MultiMC_logic + ) diff --git a/tests/TestUtil.h b/tests/TestUtil.h deleted file mode 100644 index 5b0741b8..00000000 --- a/tests/TestUtil.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "test_config.h" - -class TestsInternal -{ -public: - static QByteArray readFile(const QString &fileName) - { - QFile f(fileName); - f.open(QFile::ReadOnly); - return f.readAll(); - } - static QString readFileUtf8(const QString &fileName) - { - return QString::fromUtf8(readFile(fileName)); - } -}; - -#define MULTIMC_GET_TEST_FILE(file) TestsInternal::readFile(QFINDTESTDATA(file)) -#define MULTIMC_GET_TEST_FILE_UTF8(file) TestsInternal::readFileUtf8(QFINDTESTDATA(file)) - diff --git a/tests/copy_tests.cmake b/tests/copy_tests.cmake deleted file mode 100644 index 0af7f730..00000000 --- a/tests/copy_tests.cmake +++ /dev/null @@ -1,13 +0,0 @@ -file(GLOB data_files "${MultiMC_TEST_DATA_PATH_SOURCE}/*") -foreach(data_file ${data_files}) - get_filename_component(filename ${data_file} NAME) - configure_file( - ${data_file} - ${MultiMC_TEST_DATA_PATH}/${filename} - @ONLY - NEWLINE_STYLE LF - ) -endforeach() - -file(GLOB raw_data_files "${MultiMC_TEST_DATA_PATH_SOURCE_RAW}/*") -file(COPY ${raw_data_files} DESTINATION ${MultiMC_TEST_DATA_PATH}/) diff --git a/tests/data/1.json b/tests/data/1.json index 7eda1618..3dd189e5 100644 --- a/tests/data/1.json +++ b/tests/data/1.json @@ -8,7 +8,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_URL@/fileOneA" + "Url": "@TEST_DATA_URL@/fileOneA" } ], "Executable": true, @@ -20,7 +20,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_URL@/fileTwo" + "Url": "@TEST_DATA_URL@/fileTwo" } ], "Executable": false, @@ -32,7 +32,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_URL@/fileThree" + "Url": "@TEST_DATA_URL@/fileThree" } ], "Executable": false, diff --git a/tests/data/2.json b/tests/data/2.json index de7d0e07..a7ba7029 100644 --- a/tests/data/2.json +++ b/tests/data/2.json @@ -8,7 +8,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_URL@/fileOneB" + "Url": "@TEST_DATA_URL@/fileOneB" } ], "Executable": true, @@ -20,7 +20,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_URL@/fileTwo" + "Url": "@TEST_DATA_URL@/fileTwo" } ], "Executable": false, diff --git a/tests/data/channels.json b/tests/data/channels.json index 10eede82..b46c64c8 100644 --- a/tests/data/channels.json +++ b/tests/data/channels.json @@ -5,13 +5,13 @@ "id": "develop", "name": "Develop", "description": "The channel called \"develop\"", - "url": "@MultiMC_TEST_DATA_URL@" + "url": "@TEST_DATA_URL@" }, { "id": "stable", "name": "Stable", "description": "It's stable at least", - "url": "@MultiMC_TEST_DATA_URL@" + "url": "@TEST_DATA_URL@" }, { "id": "42", diff --git a/tests/test.manifest b/tests/test.manifest deleted file mode 100644 index 8b4dbb98..00000000 --- a/tests/test.manifest +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - Custom Minecraft launcher for managing multiple installs. - - - - - - - - - - - \ No newline at end of file diff --git a/tests/test.rc b/tests/test.rc deleted file mode 100644 index a288dba6..00000000 --- a/tests/test.rc +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include - -1 RT_MANIFEST "test.manifest" - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 1,0,0,0 -FILEOS VOS_NT_WINDOWS32 -FILETYPE VFT_APP -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "CompanyName", "MultiMC Contributors" - VALUE "FileDescription", "Testcase" - VALUE "FileVersion", "1.0.0.0" - VALUE "ProductName", "MultiMC Testcase" - VALUE "ProductVersion", "5" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0000, 0x04b0 // Unicode - END -END diff --git a/tests/test_config.h.in b/tests/test_config.h.in deleted file mode 100644 index cf59f3e2..00000000 --- a/tests/test_config.h.in +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define MultiMC_TEST_DATA_URL "@MultiMC_TEST_DATA_URL@" diff --git a/tests/tst_BaseWonkoEntityLocalLoadTask.cpp b/tests/tst_BaseWonkoEntityLocalLoadTask.cpp deleted file mode 100644 index 74da222a..00000000 --- a/tests/tst_BaseWonkoEntityLocalLoadTask.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "TestUtil.h" - -#include "wonko/tasks/BaseWonkoEntityLocalLoadTask.h" - -class BaseWonkoEntityLocalLoadTaskTest : public QObject -{ - Q_OBJECT -private -slots: -}; - -QTEST_GUILESS_MAIN(BaseWonkoEntityLocalLoadTaskTest) - -#include "tst_BaseWonkoEntityLocalLoadTask.moc" diff --git a/tests/tst_BaseWonkoEntityRemoteLoadTask.cpp b/tests/tst_BaseWonkoEntityRemoteLoadTask.cpp deleted file mode 100644 index 3a12e04e..00000000 --- a/tests/tst_BaseWonkoEntityRemoteLoadTask.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "TestUtil.h" - -#include "wonko/tasks/BaseWonkoEntityRemoteLoadTask.h" - -class BaseWonkoEntityRemoteLoadTaskTest : public QObject -{ - Q_OBJECT -private -slots: -}; - -QTEST_GUILESS_MAIN(BaseWonkoEntityRemoteLoadTaskTest) - -#include "tst_BaseWonkoEntityRemoteLoadTask.moc" diff --git a/tests/tst_UpdateChecker.cpp b/tests/tst_UpdateChecker.cpp index de1ad718..3a0d3781 100644 --- a/tests/tst_UpdateChecker.cpp +++ b/tests/tst_UpdateChecker.cpp @@ -8,6 +8,7 @@ Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry) bool operator==(const UpdateChecker::ChannelListEntry &e1, const UpdateChecker::ChannelListEntry &e2) { + qDebug() << e1.url << "vs" << e2.url; return e1.id == e2.id && e1.name == e2.name && e1.description == e2.description && @@ -76,8 +77,8 @@ slots: << true << true << (QList() - << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", MultiMC_TEST_DATA_URL} - << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", MultiMC_TEST_DATA_URL} + << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("tests/data")} + << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("tests/data")} << UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"}); } void tst_ChannelListParsing() diff --git a/tests/tst_WonkoVersionList.cpp b/tests/tst_WonkoVersionList.cpp deleted file mode 100644 index 7cb21df7..00000000 --- a/tests/tst_WonkoVersionList.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "TestUtil.h" - -#include "wonko/WonkoVersionList.h" - -class WonkoVersionListTest : public QObject -{ - Q_OBJECT -private -slots: -}; - -QTEST_GUILESS_MAIN(WonkoVersionListTest) - -#include "tst_WonkoVersionList.moc" -- cgit v1.2.3