refactor: move away from UnitTest.cmake

This commit is contained in:
Sefa Eyeoglu 2022-06-12 01:46:30 +02:00
parent ba939c92ec
commit effe46db86
No known key found for this signature in database
GPG Key ID: C10411294912A422
28 changed files with 106 additions and 340 deletions

View File

@ -6,14 +6,12 @@ if(WIN32)
endif() endif()
project(Launcher) project(Launcher)
include(CTest)
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD) string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
if(IS_IN_SOURCE_BUILD) if(IS_IN_SOURCE_BUILD)
message(FATAL_ERROR "You are building the Launcher in-source. Please separate the build tree from the source tree.") message(FATAL_ERROR "You are building the Launcher in-source. Please separate the build tree from the source tree.")
endif() endif()
##################################### Set CMake options ##################################### ##################################### Set CMake options #####################################
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
@ -63,6 +61,17 @@ if(ENABLE_LTO)
endif() endif()
endif() endif()
option(BUILD_TESTING "Build the testing tree." ON)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH "${ECM_MODULE_PATH};${CMAKE_MODULE_PATH}")
if (BUILD_TESTING)
include(CTest)
include(ECMAddTests)
enable_testing()
endif()
##################################### Set Application options ##################################### ##################################### Set Application options #####################################
######## Set URLs ######## ######## Set URLs ########
@ -102,8 +111,6 @@ set(Launcher_MATRIX_URL "https://matrix.to/#/#polymc:matrix.org" CACHE STRING "U
# Discord URL # Discord URL
set(Launcher_DISCORD_URL "https://discord.gg/Z52pwxWCHP" CACHE STRING "URL for the Discord guild.") set(Launcher_DISCORD_URL "https://discord.gg/Z52pwxWCHP" CACHE STRING "URL for the Discord guild.")
# Subreddit URL # Subreddit URL
set(Launcher_SUBREDDIT_URL "https://www.reddit.com/r/PolyMCLauncher/" CACHE STRING "URL for the subreddit.") set(Launcher_SUBREDDIT_URL "https://www.reddit.com/r/PolyMCLauncher/" CACHE STRING "URL for the subreddit.")

View File

@ -1,50 +0,0 @@
find_package(Qt5Test REQUIRED)
set(TEST_RESOURCE_PATH ${CMAKE_CURRENT_LIST_DIR})
message(${TEST_RESOURCE_PATH})
function(add_unit_test name)
if(BUILD_TESTING)
set(options "")
set(oneValueArgs DATA)
set(multiValueArgs SOURCES LIBS)
cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if(WIN32)
add_executable(${name}_test ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc)
else()
add_executable(${name}_test ${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(${name}_test ${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(${name}_test Qt5::Test ${OPT_LIBS})
target_include_directories(${name}_test PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/")
add_test(NAME ${name} COMMAND ${name}_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
endfunction()

View File

@ -1,28 +0,0 @@
#pragma once
#include <QFile>
#include <QCoreApplication>
#include <QTest>
#include <QDir>
#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 GET_TEST_FILE(file) TestsInternal::readFile(QFINDTESTDATA(file))
#define GET_TEST_FILE_UTF8(file) TestsInternal::readFileUtf8(QFINDTESTDATA(file))

View File

@ -1,23 +0,0 @@
# Copy files from source directory to destination directory, substituting any
# variables. Create destination directory if it does not exist.
function(configure_files srcDir destDir)
make_directory(${destDir})
file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
foreach(templateFile ${templateFiles})
set(srcTemplatePath ${srcDir}/${templateFile})
if(NOT IS_DIRECTORY ${srcTemplatePath})
configure_file(
${srcTemplatePath}
${destDir}/${templateFile}
@ONLY
NEWLINE_STYLE LF
)
else()
configure_files("${srcTemplatePath}" "${destDir}/${templateFile}")
endif()
endforeach()
endfunction()
configure_files(${SOURCE} ${DESTINATION})

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity name="Launcher.Test.0" type="win32" version="5.0.0.0" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<description>Custom Minecraft launcher for managing multiple installs.</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates app support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates app support for Windows Developer Preview / Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
</assembly>

View File

@ -1,28 +0,0 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
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 & PolyMC Contributors"
VALUE "FileDescription", "Testcase"
VALUE "FileVersion", "1.0.0.0"
VALUE "ProductName", "Launcher Testcase"
VALUE "ProductVersion", "5"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0000, 0x04b0 // Unicode
END
END

View File

@ -4,8 +4,6 @@ project(application)
######## Sources and headers ######## ######## Sources and headers ########
include (UnitTest)
set(CORE_SOURCES set(CORE_SOURCES
# LOGIC - Base classes and infrastructure # LOGIC - Base classes and infrastructure
BaseInstaller.h BaseInstaller.h
@ -90,16 +88,11 @@ set(CORE_SOURCES
MMCTime.cpp MMCTime.cpp
) )
add_unit_test(FileSystem ecm_add_test(FileSystem_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES FileSystem_test.cpp TEST_NAME FileSystem) # TODO: needs testdata
LIBS Launcher_logic
DATA testdata
)
add_unit_test(GZip ecm_add_test(GZip_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES GZip_test.cpp TEST_NAME GZip)
LIBS Launcher_logic
)
set(PATHMATCHER_SOURCES set(PATHMATCHER_SOURCES
# Path matchers # Path matchers
@ -168,16 +161,10 @@ if (Launcher_UPDATER_BASE)
updater/DownloadTask.cpp updater/DownloadTask.cpp
) )
add_unit_test(UpdateChecker ecm_add_test(updater/UpdateChecker_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES updater/UpdateChecker_test.cpp TEST_NAME UpdateChecker)
LIBS Launcher_logic ecm_add_test(updater/DownloadTask_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
DATA updater/testdata TEST_NAME DownloadTask)
)
add_unit_test(DownloadTask
SOURCES updater/DownloadTask_test.cpp
LIBS Launcher_logic
DATA updater/testdata
)
endif() endif()
# Backend for the news bar... there's usually no news. # Backend for the news bar... there's usually no news.
@ -359,10 +346,8 @@ set(MINECRAFT_SOURCES
mojang/PackageManifest.cpp mojang/PackageManifest.cpp
minecraft/Agent.h) minecraft/Agent.h)
add_unit_test(GradleSpecifier ecm_add_test(minecraft/GradleSpecifier_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES minecraft/GradleSpecifier_test.cpp TEST_NAME GradleSpecifier)
LIBS Launcher_logic
)
if(BUILD_TESTING) if(BUILD_TESTING)
add_executable(PackageManifest add_executable(PackageManifest
@ -382,28 +367,20 @@ if(BUILD_TESTING)
) )
endif() endif()
add_unit_test(MojangVersionFormat # TODO: needs minecraft/testdata
SOURCES minecraft/MojangVersionFormat_test.cpp ecm_add_test(minecraft/MojangVersionFormat_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
LIBS Launcher_logic TEST_NAME MojangVersionFormat)
DATA minecraft/testdata
)
add_unit_test(Library ecm_add_test(minecraft/Library_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES minecraft/Library_test.cpp TEST_NAME Library)
LIBS Launcher_logic
)
# FIXME: shares data with FileSystem test # FIXME: shares data with FileSystem test
add_unit_test(ModFolderModel # TODO: needs testdata
SOURCES minecraft/mod/ModFolderModel_test.cpp ecm_add_test(minecraft/mod/ModFolderModel_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
DATA testdata TEST_NAME ModFolderModel)
LIBS Launcher_logic
)
add_unit_test(ParseUtils ecm_add_test(minecraft/ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES minecraft/ParseUtils_test.cpp TEST_NAME ParseUtils)
LIBS Launcher_logic
)
# the screenshots feature # the screenshots feature
set(SCREENSHOTS_SOURCES set(SCREENSHOTS_SOURCES
@ -422,10 +399,8 @@ set(TASKS_SOURCES
tasks/SequentialTask.cpp tasks/SequentialTask.cpp
) )
add_unit_test(Task ecm_add_test(tasks/Task_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES tasks/Task_test.cpp TEST_NAME Task)
LIBS Launcher_logic
)
set(SETTINGS_SOURCES set(SETTINGS_SOURCES
# Settings # Settings
@ -443,10 +418,8 @@ set(SETTINGS_SOURCES
settings/SettingsObject.h settings/SettingsObject.h
) )
add_unit_test(INIFile ecm_add_test(settings/INIFile_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES settings/INIFile_test.cpp TEST_NAME INIFile)
LIBS Launcher_logic
)
set(JAVA_SOURCES set(JAVA_SOURCES
java/JavaChecker.h java/JavaChecker.h
@ -463,10 +436,8 @@ set(JAVA_SOURCES
java/JavaVersion.cpp java/JavaVersion.cpp
) )
add_unit_test(JavaVersion ecm_add_test(java/JavaVersion_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES java/JavaVersion_test.cpp TEST_NAME JavaVersion)
LIBS Launcher_logic
)
set(TRANSLATIONS_SOURCES set(TRANSLATIONS_SOURCES
translations/TranslationsModel.h translations/TranslationsModel.h
@ -558,11 +529,9 @@ set(PACKWIZ_SOURCES
modplatform/packwiz/Packwiz.cpp modplatform/packwiz/Packwiz.cpp
) )
add_unit_test(Packwiz # TODO: needs modplatform/packwiz/testdata
SOURCES modplatform/packwiz/Packwiz_test.cpp ecm_add_test(modplatform/packwiz/Packwiz_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
DATA modplatform/packwiz/testdata TEST_NAME Packwiz)
LIBS Launcher_logic
)
set(TECHNIC_SOURCES set(TECHNIC_SOURCES
modplatform/technic/SingleZipPackInstallTask.h modplatform/technic/SingleZipPackInstallTask.h
@ -586,10 +555,8 @@ set(ATLAUNCHER_SOURCES
modplatform/atlauncher/ATLShareCode.h modplatform/atlauncher/ATLShareCode.h
) )
add_unit_test(Index ecm_add_test(meta/Index_test.cpp LINK_LIBRARIES Launcher_logic Qt5::Test
SOURCES meta/Index_test.cpp TEST_NAME Index)
LIBS Launcher_logic
)
################################ COMPILE ################################ ################################ COMPILE ################################

View File

@ -120,11 +120,6 @@ bool checkProblemticPathJava(QDir folder);
// Get the Directory representing the User's Desktop // Get the Directory representing the User's Desktop
QString getDesktopDir(); QString getDesktopDir();
// Create a shortcut at *location*, pointing to *dest* called with the arguments *args*
// call it *name* and assign it the icon *icon*
// return true if operation succeeded
bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
// Overrides one folder with the contents of another, preserving items exclusive to the first folder // Overrides one folder with the contents of another, preserving items exclusive to the first folder
// Equivalent to doing QDir::rename, but allowing for overrides // Equivalent to doing QDir::rename, but allowing for overrides
bool overrideFolder(QString overwritten_path, QString override_path); bool overrideFolder(QString overwritten_path, QString override_path);

View File

@ -1,7 +1,6 @@
#include <QTest> #include <QTest>
#include <QTemporaryDir> #include <QTemporaryDir>
#include <QStandardPaths> #include <QStandardPaths>
#include "TestUtil.h"
#include "FileSystem.h" #include "FileSystem.h"
@ -81,7 +80,7 @@ slots:
void test_copy() void test_copy()
{ {
QString folder = QFINDTESTDATA("data/test_folder"); QString folder = QFINDTESTDATA("testdata/test_folder");
auto f = [&folder]() auto f = [&folder]()
{ {
QTemporaryDir tempDir; QTemporaryDir tempDir;
@ -116,47 +115,6 @@ slots:
{ {
QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
} }
// this is only valid on linux
// FIXME: implement on windows, OSX, then test.
#if defined(Q_OS_LINUX)
void test_createShortcut_data()
{
QTest::addColumn<QString>("location");
QTest::addColumn<QString>("dest");
QTest::addColumn<QStringList>("args");
QTest::addColumn<QString>("name");
QTest::addColumn<QString>("iconLocation");
QTest::addColumn<QByteArray>("result");
QTest::newRow("unix") << QDir::currentPath()
<< "asdfDest"
<< (QStringList() << "arg1" << "arg2")
<< "asdf"
<< QString()
#if defined(Q_OS_LINUX)
<< GET_TEST_FILE("data/FileSystem-test_createShortcut-unix")
#elif defined(Q_OS_WIN)
<< QByteArray()
#endif
;
}
void test_createShortcut()
{
QFETCH(QString, location);
QFETCH(QString, dest);
QFETCH(QStringList, args);
QFETCH(QString, name);
QFETCH(QString, iconLocation);
QFETCH(QByteArray, result);
QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
//QDir().remove(location);
}
#endif
}; };
QTEST_GUILESS_MAIN(FileSystemTest) QTEST_GUILESS_MAIN(FileSystemTest)

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "GZip.h" #include "GZip.h"
#include <random> #include <random>

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "java/JavaVersion.h" #include "java/JavaVersion.h"

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "meta/Index.h" #include "meta/Index.h"
#include "meta/VersionList.h" #include "meta/VersionList.h"

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "minecraft/GradleSpecifier.h" #include "minecraft/GradleSpecifier.h"

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "minecraft/MojangVersionFormat.h" #include "minecraft/MojangVersionFormat.h"
#include "minecraft/OneSixVersionFormat.h" #include "minecraft/OneSixVersionFormat.h"
@ -11,15 +10,14 @@ class LibraryTest : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
LibraryPtr readMojangJson(const char *file) LibraryPtr readMojangJson(const QString path)
{ {
auto path = QFINDTESTDATA(file);
QFile jsonFile(path); QFile jsonFile(path);
jsonFile.open(QIODevice::ReadOnly); jsonFile.open(QIODevice::ReadOnly);
auto data = jsonFile.readAll(); auto data = jsonFile.readAll();
jsonFile.close(); jsonFile.close();
ProblemContainer problems; ProblemContainer problems;
return MojangVersionFormat::libraryFromJson(problems, QJsonDocument::fromJson(data).object(), file); return MojangVersionFormat::libraryFromJson(problems, QJsonDocument::fromJson(data).object(), path);
} }
// get absolute path to expected storage, assuming default cache prefix // get absolute path to expected storage, assuming default cache prefix
QStringList getStorage(QString relative) QStringList getStorage(QString relative)
@ -32,7 +30,7 @@ slots:
{ {
cache.reset(new HttpMetaCache()); cache.reset(new HttpMetaCache());
cache->addBase("libraries", QDir("libraries").absolutePath()); cache->addBase("libraries", QDir("libraries").absolutePath());
dataDir = QDir("data").absolutePath(); dataDir = QDir(QFINDTESTDATA("testdata")).absolutePath();
} }
void test_legacy() void test_legacy()
{ {
@ -74,14 +72,14 @@ slots:
QCOMPARE(test.isNative(), false); QCOMPARE(test.isNative(), false);
QStringList failedFiles; QStringList failedFiles;
test.setHint("local"); test.setHint("local");
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString("data")); auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QFINDTESTDATA("testdata"));
QCOMPARE(downloads.size(), 0); QCOMPARE(downloads.size(), 0);
qDebug() << failedFiles; qDebug() << failedFiles;
QCOMPARE(failedFiles.size(), 0); QCOMPARE(failedFiles.size(), 0);
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test.getApplicableFiles(currentSystem, jar, native, native32, native64, QString("data")); test.getApplicableFiles(currentSystem, jar, native, native32, native64, QFINDTESTDATA("testdata"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()}); QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()});
QCOMPARE(native, {}); QCOMPARE(native, {});
QCOMPARE(native32, {}); QCOMPARE(native32, {});
QCOMPARE(native64, {}); QCOMPARE(native64, {});
@ -167,20 +165,20 @@ slots:
test.setRepositoryURL("file://foo/bar"); test.setRepositoryURL("file://foo/bar");
{ {
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString("data")); test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QFINDTESTDATA("testdata"));
QCOMPARE(jar, {}); QCOMPARE(jar, {});
QCOMPARE(native, {}); QCOMPARE(native, {});
QCOMPARE(native32, {QFileInfo("data/testname-testversion-linux-32.jar").absoluteFilePath()}); QCOMPARE(native32, {QFileInfo(QFINDTESTDATA("testdata/testname-testversion-linux-32.jar")).absoluteFilePath()});
QCOMPARE(native64, {QFileInfo("data/testname-testversion-linux-64.jar").absoluteFilePath()}); QCOMPARE(native64, {QFileInfo(QFINDTESTDATA("testdata") + "/testname-testversion-linux-64.jar").absoluteFilePath()});
QStringList failedFiles; QStringList failedFiles;
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString("data")); auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata"));
QCOMPARE(dls.size(), 0); QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {"data/testname-testversion-linux-64.jar"}); QCOMPARE(failedFiles, {QFileInfo(QFINDTESTDATA("testdata") + "/testname-testversion-linux-64.jar").absoluteFilePath()});
} }
} }
void test_onenine() void test_onenine()
{ {
auto test = readMojangJson("data/lib-simple.json"); auto test = readMojangJson(QFINDTESTDATA("testdata/lib-simple.json"));
{ {
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString());
@ -199,41 +197,41 @@ slots:
test->setHint("local"); test->setHint("local");
{ {
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString("data")); test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QFINDTESTDATA("testdata"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()}); QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()});
QCOMPARE(native, {}); QCOMPARE(native, {});
QCOMPARE(native32, {}); QCOMPARE(native32, {});
QCOMPARE(native64, {}); QCOMPARE(native64, {});
} }
{ {
QStringList failedFiles; QStringList failedFiles;
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString("data")); auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata"));
QCOMPARE(dls.size(), 0); QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {}); QCOMPARE(failedFiles, {});
} }
} }
void test_onenine_local_override() void test_onenine_local_override()
{ {
auto test = readMojangJson("data/lib-simple.json"); auto test = readMojangJson(QFINDTESTDATA("testdata/lib-simple.json"));
test->setHint("local"); test->setHint("local");
{ {
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString("data")); test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QFINDTESTDATA("testdata"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()}); QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()});
QCOMPARE(native, {}); QCOMPARE(native, {});
QCOMPARE(native32, {}); QCOMPARE(native32, {});
QCOMPARE(native64, {}); QCOMPARE(native64, {});
} }
{ {
QStringList failedFiles; QStringList failedFiles;
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString("data")); auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata"));
QCOMPARE(dls.size(), 0); QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {}); QCOMPARE(failedFiles, {});
} }
} }
void test_onenine_native() void test_onenine_native()
{ {
auto test = readMojangJson("data/lib-native.json"); auto test = readMojangJson(QFINDTESTDATA("testdata/lib-native.json"));
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString());
QCOMPARE(jar, QStringList()); QCOMPARE(jar, QStringList());
@ -248,7 +246,7 @@ slots:
} }
void test_onenine_native_arch() void test_onenine_native_arch()
{ {
auto test = readMojangJson("data/lib-native-arch.json"); auto test = readMojangJson(QFINDTESTDATA("testdata/lib-native-arch.json"));
QStringList jar, native, native32, native64; QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_Windows, jar, native, native32, native64, QString()); test->getApplicableFiles(Os_Windows, jar, native, native32, native64, QString());
QCOMPARE(jar, {}); QCOMPARE(jar, {});

View File

@ -1,6 +1,5 @@
#include <QTest> #include <QTest>
#include <QDebug> #include <QDebug>
#include "TestUtil.h"
#include "minecraft/MojangVersionFormat.h" #include "minecraft/MojangVersionFormat.h"
@ -8,9 +7,8 @@ class MojangVersionFormatTest : public QObject
{ {
Q_OBJECT Q_OBJECT
static QJsonDocument readJson(const char *file) static QJsonDocument readJson(const QString path)
{ {
auto path = QFINDTESTDATA(file);
QFile jsonFile(path); QFile jsonFile(path);
jsonFile.open(QIODevice::ReadOnly); jsonFile.open(QIODevice::ReadOnly);
auto data = jsonFile.readAll(); auto data = jsonFile.readAll();
@ -31,7 +29,7 @@ private
slots: slots:
void test_Through_Simple() void test_Through_Simple()
{ {
QJsonDocument doc = readJson("data/1.9-simple.json"); QJsonDocument doc = readJson(QFINDTESTDATA("testdata/1.9-simple.json"));
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9-simple.json"); auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9-simple.json");
auto doc2 = MojangVersionFormat::versionFileToJson(vfile); auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
writeJson("1.9-simple-passthorugh.json", doc2); writeJson("1.9-simple-passthorugh.json", doc2);
@ -41,7 +39,7 @@ slots:
void test_Through() void test_Through()
{ {
QJsonDocument doc = readJson("data/1.9.json"); QJsonDocument doc = readJson(QFINDTESTDATA("testdata/1.9.json"));
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9.json"); auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9.json");
auto doc2 = MojangVersionFormat::versionFileToJson(vfile); auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
writeJson("1.9-passthorugh.json", doc2); writeJson("1.9-passthorugh.json", doc2);

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "minecraft/ParseUtils.h" #include "minecraft/ParseUtils.h"
@ -42,4 +41,3 @@ slots:
QTEST_GUILESS_MAIN(ParseUtilsTest) QTEST_GUILESS_MAIN(ParseUtilsTest)
#include "ParseUtils_test.moc" #include "ParseUtils_test.moc"

View File

@ -35,7 +35,6 @@
#include <QTest> #include <QTest>
#include <QTemporaryDir> #include <QTemporaryDir>
#include "TestUtil.h"
#include "FileSystem.h" #include "FileSystem.h"
#include "minecraft/mod/ModFolderModel.h" #include "minecraft/mod/ModFolderModel.h"
@ -50,7 +49,7 @@ slots:
void test_1178() void test_1178()
{ {
// source // source
QString source = QFINDTESTDATA("data/test_folder"); QString source = QFINDTESTDATA("testdata/test_folder");
// sanity check // sanity check
QVERIFY(!source.endsWith('/')); QVERIFY(!source.endsWith('/'));

View File

@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 1,
"description": "Some resource pack maybe"
}
}

View File

@ -0,0 +1 @@

View File

@ -21,7 +21,6 @@
#include <QTest> #include <QTest>
#include "Packwiz.h" #include "Packwiz.h"
#include "TestUtil.h"
class PackwizTest : public QObject { class PackwizTest : public QObject {
Q_OBJECT Q_OBJECT

View File

@ -1,6 +1,5 @@
#include <QTest> #include <QTest>
#include <QDebug> #include <QDebug>
#include "TestUtil.h"
#include "mojang/PackageManifest.h" #include "mojang/PackageManifest.h"

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "settings/INIFile.h" #include "settings/INIFile.h"

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include "Task.h" #include "Task.h"

View File

@ -1,8 +1,6 @@
#include <QTest> #include <QTest>
#include <QSignalSpy> #include <QSignalSpy>
#include "TestUtil.h"
#include "updater/GoUpdate.h" #include "updater/GoUpdate.h"
#include "updater/DownloadTask.h" #include "updater/DownloadTask.h"
#include "updater/UpdateChecker.h" #include "updater/UpdateChecker.h"
@ -71,13 +69,23 @@ slots:
void test_parseVersionInfo_data() void test_parseVersionInfo_data()
{ {
QFile f1(QFINDTESTDATA("testdata/1.json"));
f1.open(QFile::ReadOnly);
QByteArray data1 = f1.readAll();
f1.close();
QFile f2(QFINDTESTDATA("testdata/2.json"));
f2.open(QFile::ReadOnly);
QByteArray data2 = f2.readAll();
f2.close();
QTest::addColumn<QByteArray>("data"); QTest::addColumn<QByteArray>("data");
QTest::addColumn<VersionFileList>("list"); QTest::addColumn<VersionFileList>("list");
QTest::addColumn<QString>("error"); QTest::addColumn<QString>("error");
QTest::addColumn<bool>("ret"); QTest::addColumn<bool>("ret");
QTest::newRow("one") QTest::newRow("one")
<< GET_TEST_FILE("data/1.json") << data1
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{"fileOne", << VersionFileEntry{"fileOne",
493, 493,
@ -93,7 +101,7 @@ slots:
"f12df554b21e320be6471d7154130e70"}) "f12df554b21e320be6471d7154130e70"})
<< QString() << true; << QString() << true;
QTest::newRow("two") QTest::newRow("two")
<< GET_TEST_FILE("data/2.json") << data2
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{"fileOne", << VersionFileEntry{"fileOne",
493, 493,
@ -133,42 +141,42 @@ slots:
QTest::newRow("test 1") QTest::newRow("test 1")
<< tempFolder << (VersionFileList() << tempFolder << (VersionFileList()
<< VersionFileEntry{ << VersionFileEntry{
"data/fileOne", 493, QFINDTESTDATA("testdata/fileOne"), 493,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileOne-1"), "http", "http://host/path/fileOne-1"),
"9eb84090956c484e32cb6c08455a667b"} "9eb84090956c484e32cb6c08455a667b"}
<< VersionFileEntry{ << VersionFileEntry{
"data/fileTwo", 644, QFINDTESTDATA("testdata/fileTwo"), 644,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileTwo-1"), "http", "http://host/path/fileTwo-1"),
"38f94f54fa3eb72b0ea836538c10b043"} "38f94f54fa3eb72b0ea836538c10b043"}
<< VersionFileEntry{ << VersionFileEntry{
"data/fileThree", 420, QFINDTESTDATA("testdata/fileThree"), 420,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileThree-1"), "http", "http://host/path/fileThree-1"),
"f12df554b21e320be6471d7154130e70"}) "f12df554b21e320be6471d7154130e70"})
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{ << VersionFileEntry{
"data/fileOne", 493, QFINDTESTDATA("testdata/fileOne"), 493,
FileSourceList() FileSourceList()
<< FileSource("http", << FileSource("http",
"http://host/path/fileOne-2"), "http://host/path/fileOne-2"),
"42915a71277c9016668cce7b82c6b577"} "42915a71277c9016668cce7b82c6b577"}
<< VersionFileEntry{ << VersionFileEntry{
"data/fileTwo", 644, QFINDTESTDATA("testdata/fileTwo"), 644,
FileSourceList() FileSourceList()
<< FileSource("http", << FileSource("http",
"http://host/path/fileTwo-2"), "http://host/path/fileTwo-2"),
"38f94f54fa3eb72b0ea836538c10b043"}) "38f94f54fa3eb72b0ea836538c10b043"})
<< (OperationList() << (OperationList()
<< Operation::DeleteOp("data/fileThree") << Operation::DeleteOp(QFINDTESTDATA("testdata/fileThree"))
<< Operation::CopyOp( << Operation::CopyOp(
FS::PathCombine(tempFolder, FS::PathCombine(tempFolder,
QString("data/fileOne").replace("/", "_")), QFINDTESTDATA("data/fileOne").replace("/", "_")),
"data/fileOne", 493)); QFINDTESTDATA("data/fileOne"), 493));
} }
void test_processFileLists() void test_processFileLists()
{ {

View File

@ -1,7 +1,6 @@
#include <QTest> #include <QTest>
#include <QSignalSpy> #include <QSignalSpy>
#include "TestUtil.h"
#include "updater/UpdateChecker.h" #include "updater/UpdateChecker.h"
Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry) Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry)
@ -50,36 +49,36 @@ slots:
QTest::newRow("garbage") QTest::newRow("garbage")
<< QString() << QString()
<< findTestDataUrl("data/garbageChannels.json") << findTestDataUrl("testdata/garbageChannels.json")
<< false << false
<< false << false
<< QList<UpdateChecker::ChannelListEntry>(); << QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("errors") QTest::newRow("errors")
<< QString() << QString()
<< findTestDataUrl("data/errorChannels.json") << findTestDataUrl("testdata/errorChannels.json")
<< false << false
<< true << true
<< QList<UpdateChecker::ChannelListEntry>(); << QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("no channels") QTest::newRow("no channels")
<< QString() << QString()
<< findTestDataUrl("data/noChannels.json") << findTestDataUrl("testdata/noChannels.json")
<< false << false
<< true << true
<< QList<UpdateChecker::ChannelListEntry>(); << QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("one channel") QTest::newRow("one channel")
<< QString("develop") << QString("develop")
<< findTestDataUrl("data/oneChannel.json") << findTestDataUrl("testdata/oneChannel.json")
<< true << true
<< true << true
<< (QList<UpdateChecker::ChannelListEntry>() << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"}); << (QList<UpdateChecker::ChannelListEntry>() << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"});
QTest::newRow("several channels") QTest::newRow("several channels")
<< QString("develop") << QString("develop")
<< findTestDataUrl("data/channels.json") << findTestDataUrl("testdata/channels.json")
<< true << true
<< true << true
<< (QList<UpdateChecker::ChannelListEntry>() << (QList<UpdateChecker::ChannelListEntry>()
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("data")} << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("testdata")}
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("data")} << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("testdata")}
<< UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"}); << 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() void tst_ChannelListParsing()
@ -117,7 +116,7 @@ slots:
void tst_UpdateChecking() void tst_UpdateChecking()
{ {
QString channel = "develop"; QString channel = "develop";
QString channelUrl = findTestDataUrl("data/channels.json"); QString channelUrl = findTestDataUrl("testdata/channels.json");
int currentBuild = 2; int currentBuild = 2;
shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager(); shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager();
@ -132,7 +131,7 @@ slots:
QVERIFY(channelListLoadedSpy.wait()); QVERIFY(channelListLoadedSpy.wait());
qDebug() << "CWD:" << QDir::current().absolutePath(); qDebug() << "CWD:" << QDir::current().absolutePath();
checker.m_channels[0].url = findTestDataUrl("data/"); checker.m_channels[0].url = findTestDataUrl("testdata/");
checker.checkForUpdate(channel, false); checker.checkForUpdate(channel, false);
QVERIFY(updateAvailableSpy.wait()); QVERIFY(updateAvailableSpy.wait());

View File

@ -22,8 +22,4 @@ add_library(systeminfo STATIC ${systeminfo_SOURCES})
target_link_libraries(systeminfo Qt5::Core Qt5::Gui Qt5::Network) target_link_libraries(systeminfo Qt5::Core Qt5::Gui Qt5::Network)
target_include_directories(systeminfo PUBLIC include) target_include_directories(systeminfo PUBLIC include)
include (UnitTest) ecm_add_test(src/sys_test.cpp LINK_LIBRARIES systeminfo Qt5::Test TEST_NAME sys)
add_unit_test(sys
SOURCES src/sys_test.cpp
LIBS systeminfo
)

View File

@ -1,5 +1,4 @@
#include <QTest> #include <QTest>
#include "TestUtil.h"
#include <sys.h> #include <sys.h>