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 +++++++++++++++++++ 5 files changed, 158 insertions(+) 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 (limited to 'cmake') 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 -- cgit v1.2.3