NOISSUE reorganize unit tests to be placed next to the code they test. Nuke more dead tests.

This commit is contained in:
Petr Mrázek 2016-04-14 01:23:54 +02:00
parent e8ba5dafc6
commit 771dd6f9ab
45 changed files with 291 additions and 329 deletions

1
.gitattributes vendored
View File

@ -1 +1,2 @@
*.pem -crlf *.pem -crlf
**/testdata/** -text -diff

View File

@ -20,12 +20,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
######## Set module path ######## ######## Set module path ########
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
# Output all executables and shared libs in the main build folder, not in subfolders.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
if(UNIX)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars) set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
######## Set compiler flags ######## ######## Set compiler flags ########
@ -103,8 +97,6 @@ add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
############################### Built Artifacts ############################### ############################### Built Artifacts ###############################
add_subdirectory(tests)
add_subdirectory(api/logic) add_subdirectory(api/logic)
add_subdirectory(api/gui) add_subdirectory(api/gui)

View File

@ -1,4 +1,4 @@
project(MultiMC_logic) project(MultiMC_gui LANGUAGES CXX)
set(GUI_SOURCES set(GUI_SOURCES
DesktopServices.h DesktopServices.h

View File

@ -1,6 +1,8 @@
project(MultiMC_logic) project(MultiMC_logic)
set(LOGIC_SOURCES include (UnitTest)
set(CORE_SOURCES
# LOGIC - Base classes and infrastructure # LOGIC - Base classes and infrastructure
BaseInstaller.h BaseInstaller.h
BaseInstaller.cpp BaseInstaller.cpp
@ -42,12 +44,6 @@ set(LOGIC_SOURCES
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms # a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
QObjectPtr.h QObjectPtr.h
# Path matchers
pathmatcher/FSTreeMatcher.h
pathmatcher/IPathMatcher.h
pathmatcher/MultiMatcher.h
pathmatcher/RegexpMatcher.h
# Compression support # Compression support
GZip.h GZip.h
GZip.cpp GZip.cpp
@ -60,6 +56,31 @@ set(LOGIC_SOURCES
Version.h Version.h
Version.cpp Version.cpp
# A Recursive file system watcher
RecursiveFileSystemWatcher.h
RecursiveFileSystemWatcher.cpp
)
add_unit_test(FileSystem
SOURCES FileSystem_test.cpp
LIBS MultiMC_logic
DATA testdata
)
add_unit_test(GZip
SOURCES GZip_test.cpp
LIBS MultiMC_logic
)
set(PATHMATCHER_SOURCES
# Path matchers
pathmatcher/FSTreeMatcher.h
pathmatcher/IPathMatcher.h
pathmatcher/MultiMatcher.h
pathmatcher/RegexpMatcher.h
)
set(NET_SOURCES
# network stuffs # network stuffs
net/NetAction.h net/NetAction.h
net/MD5EtagDownload.h net/MD5EtagDownload.h
@ -76,24 +97,10 @@ set(LOGIC_SOURCES
net/PasteUpload.cpp net/PasteUpload.cpp
net/URLConstants.h net/URLConstants.h
net/URLConstants.cpp net/URLConstants.cpp
)
# Yggdrasil login stuff # Game launch logic
minecraft/auth/AuthSession.h set(LAUNCH_SOURCES
minecraft/auth/AuthSession.cpp
minecraft/auth/MojangAccountList.h
minecraft/auth/MojangAccountList.cpp
minecraft/auth/MojangAccount.h
minecraft/auth/MojangAccount.cpp
minecraft/auth/YggdrasilTask.h
minecraft/auth/YggdrasilTask.cpp
minecraft/auth/flows/AuthenticateTask.h
minecraft/auth/flows/AuthenticateTask.cpp
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/ValidateTask.h
minecraft/auth/flows/ValidateTask.cpp
# Game launch logic
launch/steps/PostLaunchCommand.cpp launch/steps/PostLaunchCommand.cpp
launch/steps/PostLaunchCommand.h launch/steps/PostLaunchCommand.h
launch/steps/PreLaunchCommand.cpp launch/steps/PreLaunchCommand.cpp
@ -110,30 +117,70 @@ set(LOGIC_SOURCES
launch/LoggedProcess.h launch/LoggedProcess.h
launch/MessageLevel.cpp launch/MessageLevel.cpp
launch/MessageLevel.h launch/MessageLevel.h
)
# Update system # Old update system
set(UPDATE_SOURCES
updater/GoUpdate.h updater/GoUpdate.h
updater/GoUpdate.cpp updater/GoUpdate.cpp
updater/UpdateChecker.h updater/UpdateChecker.h
updater/UpdateChecker.cpp updater/UpdateChecker.cpp
updater/DownloadTask.h updater/DownloadTask.h
updater/DownloadTask.cpp updater/DownloadTask.cpp
)
add_unit_test(UpdateChecker
SOURCES updater/UpdateChecker_test.cpp
LIBS MultiMC_logic
DATA updater/testdata
)
add_unit_test(DownloadTask
SOURCES updater/DownloadTask_test.cpp
LIBS MultiMC_logic
DATA updater/testdata
)
# Rarely used notifications
set(NOTIFICATIONS_SOURCES
# Notifications - short warning messages # Notifications - short warning messages
notifications/NotificationChecker.h notifications/NotificationChecker.h
notifications/NotificationChecker.cpp notifications/NotificationChecker.cpp
)
# Backend for the news bar... there's usually no news.
set(NEWS_SOURCES
# News System # News System
news/NewsChecker.h news/NewsChecker.h
news/NewsChecker.cpp news/NewsChecker.cpp
news/NewsEntry.h news/NewsEntry.h
news/NewsEntry.cpp news/NewsEntry.cpp
)
# Minecraft services status checker
set(STATUS_SOURCES
# Status system # Status system
status/StatusChecker.h status/StatusChecker.h
status/StatusChecker.cpp status/StatusChecker.cpp
)
# Support for Minecraft instances and launch
set(MINECRAFT_SOURCES
# Minecraft support # Minecraft support
minecraft/auth/AuthSession.h
minecraft/auth/AuthSession.cpp
minecraft/auth/MojangAccountList.h
minecraft/auth/MojangAccountList.cpp
minecraft/auth/MojangAccount.h
minecraft/auth/MojangAccount.cpp
minecraft/auth/YggdrasilTask.h
minecraft/auth/YggdrasilTask.cpp
minecraft/auth/flows/AuthenticateTask.h
minecraft/auth/flows/AuthenticateTask.cpp
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/ValidateTask.h
minecraft/auth/flows/ValidateTask.cpp
minecraft/onesix/OneSixUpdate.h minecraft/onesix/OneSixUpdate.h
minecraft/onesix/OneSixUpdate.cpp minecraft/onesix/OneSixUpdate.cpp
minecraft/onesix/OneSixInstance.h minecraft/onesix/OneSixInstance.h
@ -201,55 +248,6 @@ set(LOGIC_SOURCES
minecraft/ftb/FTBPlugin.h minecraft/ftb/FTBPlugin.h
minecraft/ftb/FTBPlugin.cpp minecraft/ftb/FTBPlugin.cpp
# A Recursive file system watcher
RecursiveFileSystemWatcher.h
RecursiveFileSystemWatcher.cpp
# the screenshots feature
screenshots/Screenshot.h
screenshots/ImgurUpload.h
screenshots/ImgurUpload.cpp
screenshots/ImgurAlbumCreation.h
screenshots/ImgurAlbumCreation.cpp
# Tasks
tasks/Task.h
tasks/Task.cpp
tasks/ThreadTask.h
tasks/ThreadTask.cpp
tasks/SequentialTask.h
tasks/SequentialTask.cpp
# Settings
settings/INIFile.cpp
settings/INIFile.h
settings/INISettingsObject.cpp
settings/INISettingsObject.h
settings/OverrideSetting.cpp
settings/OverrideSetting.h
settings/PassthroughSetting.cpp
settings/PassthroughSetting.h
settings/Setting.cpp
settings/Setting.h
settings/SettingsObject.cpp
settings/SettingsObject.h
# Java related code
java/launch/CheckJava.cpp
java/launch/CheckJava.h
java/JavaChecker.h
java/JavaChecker.cpp
java/JavaCheckerJob.h
java/JavaCheckerJob.cpp
java/JavaInstall.h
java/JavaInstall.cpp
java/JavaInstallList.h
java/JavaInstallList.cpp
java/JavaUtils.h
java/JavaUtils.cpp
java/JavaVersion.h
java/JavaVersion.cpp
# Assets # Assets
minecraft/AssetsUtils.h minecraft/AssetsUtils.h
minecraft/AssetsUtils.cpp minecraft/AssetsUtils.cpp
@ -271,11 +269,106 @@ set(LOGIC_SOURCES
minecraft/liteloader/LiteLoaderInstaller.cpp minecraft/liteloader/LiteLoaderInstaller.cpp
minecraft/liteloader/LiteLoaderVersionList.h minecraft/liteloader/LiteLoaderVersionList.h
minecraft/liteloader/LiteLoaderVersionList.cpp minecraft/liteloader/LiteLoaderVersionList.cpp
)
add_unit_test(GradleSpecifier
SOURCES minecraft/GradleSpecifier_test.cpp
LIBS MultiMC_logic
)
add_unit_test(MojangVersionFormat
SOURCES minecraft/MojangVersionFormat_test.cpp
LIBS MultiMC_logic
DATA minecraft/testdata
)
add_unit_test(Library
SOURCES minecraft/Library_test.cpp
LIBS MultiMC_logic
)
# FIXME: shares data with FileSystem test
add_unit_test(ModList
SOURCES minecraft/ModList_test.cpp
DATA testdata
LIBS MultiMC_logic
)
add_unit_test(ParseUtils
SOURCES minecraft/ParseUtils_test.cpp
LIBS MultiMC_logic
)
# the screenshots feature
set(SCREENSHOTS_SOURCES
screenshots/Screenshot.h
screenshots/ImgurUpload.h
screenshots/ImgurUpload.cpp
screenshots/ImgurAlbumCreation.h
screenshots/ImgurAlbumCreation.cpp
)
set(TASKS_SOURCES
# Tasks
tasks/Task.h
tasks/Task.cpp
tasks/ThreadTask.h
tasks/ThreadTask.cpp
tasks/SequentialTask.h
tasks/SequentialTask.cpp
)
set(SETTINGS_SOURCES
# Settings
settings/INIFile.cpp
settings/INIFile.h
settings/INISettingsObject.cpp
settings/INISettingsObject.h
settings/OverrideSetting.cpp
settings/OverrideSetting.h
settings/PassthroughSetting.cpp
settings/PassthroughSetting.h
settings/Setting.cpp
settings/Setting.h
settings/SettingsObject.cpp
settings/SettingsObject.h
)
add_unit_test(INIFile
SOURCES settings/INIFile_test.cpp
LIBS MultiMC_logic
)
set(JAVA_SOURCES
# Java related code
java/launch/CheckJava.cpp
java/launch/CheckJava.h
java/JavaChecker.h
java/JavaChecker.cpp
java/JavaCheckerJob.h
java/JavaCheckerJob.cpp
java/JavaInstall.h
java/JavaInstall.cpp
java/JavaInstallList.h
java/JavaInstallList.cpp
java/JavaUtils.h
java/JavaUtils.cpp
java/JavaVersion.h
java/JavaVersion.cpp
)
add_unit_test(JavaVersion
SOURCES java/JavaVersion_test.cpp
LIBS MultiMC_logic
)
set(TRANSLATIONS_SOURCES
# Translations # Translations
trans/TranslationDownloader.h trans/TranslationDownloader.h
trans/TranslationDownloader.cpp trans/TranslationDownloader.cpp
)
set(TOOLS_SOURCES
# Tools # Tools
tools/BaseExternalTool.cpp tools/BaseExternalTool.cpp
tools/BaseExternalTool.h tools/BaseExternalTool.h
@ -287,7 +380,9 @@ set(LOGIC_SOURCES
tools/JVisualVM.h tools/JVisualVM.h
tools/MCEditTool.cpp tools/MCEditTool.cpp
tools/MCEditTool.h tools/MCEditTool.h
)
set(WONKO_SOURCES
# Wonko # Wonko
wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp
wonko/tasks/BaseWonkoEntityRemoteLoadTask.h wonko/tasks/BaseWonkoEntityRemoteLoadTask.h
@ -310,11 +405,36 @@ set(LOGIC_SOURCES
wonko/WonkoReference.cpp wonko/WonkoReference.cpp
wonko/WonkoReference.h wonko/WonkoReference.h
) )
add_unit_test(WonkoIndex
SOURCES wonko/WonkoIndex_test.cpp
LIBS MultiMC_logic
)
################################ COMPILE ################################ ################################ COMPILE ################################
# we need zlib # we need zlib
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
set(LOGIC_SOURCES
${CORE_SOURCES}
${PATHMATCHER_SOURCES}
${NET_SOURCES}
${LAUNCH_SOURCES}
${UPDATE_SOURCES}
${NOTIFICATIONS_SOURCES}
${NEWS_SOURCES}
${STATUS_SOURCES}
${MINECRAFT_SOURCES}
${SCREENSHOTS_SOURCES}
${TASKS_SOURCES}
${SETTINGS_SOURCES}
${JAVA_SOURCES}
${TRANSLATIONS_SOURCES}
${TOOLS_SOURCES}
${WONKO_SOURCES}
)
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES}) add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)

View File

@ -1,5 +1,6 @@
#include <QTest> #include <QTest>
#include <QTemporaryDir> #include <QTemporaryDir>
#include <QStandardPaths>
#include "TestUtil.h" #include "TestUtil.h"
#include "FileSystem.h" #include "FileSystem.h"
@ -80,7 +81,7 @@ slots:
void test_copy() void test_copy()
{ {
QString folder = QFINDTESTDATA("tests/data/test_folder"); QString folder = QFINDTESTDATA("data/test_folder");
auto f = [&folder]() auto f = [&folder]()
{ {
QTemporaryDir tempDir; QTemporaryDir tempDir;
@ -110,8 +111,54 @@ slots:
QVERIFY(folder.endsWith('/')); QVERIFY(folder.endsWith('/'));
f(); f();
} }
void test_getDesktop()
{
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)
<< MULTIMC_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)
#include "tst_FileSystem.moc" #include "FileSystem_test.moc"

View File

@ -54,4 +54,4 @@ slots:
QTEST_GUILESS_MAIN(GZipTest) QTEST_GUILESS_MAIN(GZipTest)
#include "tst_GZip.moc" #include "GZip_test.moc"

View File

@ -120,4 +120,4 @@ private slots:
QTEST_GUILESS_MAIN(ModUtilsTest) QTEST_GUILESS_MAIN(ModUtilsTest)
#include "tst_modutils.moc" #include "Version_test.moc"

View File

@ -113,8 +113,4 @@ slots:
QTEST_GUILESS_MAIN(JavaVersionTest) QTEST_GUILESS_MAIN(JavaVersionTest)
#include "tst_JavaVersion.moc" #include "JavaVersion_test.moc"
// manual testing fakery

View File

@ -74,4 +74,4 @@ slots:
QTEST_GUILESS_MAIN(GradleSpecifierTest) QTEST_GUILESS_MAIN(GradleSpecifierTest)
#include "tst_gradlespecifier.moc" #include "GradleSpecifier_test.moc"

View File

@ -192,4 +192,4 @@ private:
QTEST_GUILESS_MAIN(LibraryTest) QTEST_GUILESS_MAIN(LibraryTest)
#include "tst_Library.moc" #include "Library_test.moc"

View File

@ -16,7 +16,7 @@ slots:
void test_1178() void test_1178()
{ {
// source // source
QString source = QFINDTESTDATA("tests/data/test_folder"); QString source = QFINDTESTDATA("data/test_folder");
// sanity check // sanity check
QVERIFY(!source.endsWith('/')); QVERIFY(!source.endsWith('/'));
@ -50,4 +50,4 @@ slots:
QTEST_GUILESS_MAIN(ModListTest) QTEST_GUILESS_MAIN(ModListTest)
#include "tst_ModList.moc" #include "ModList_test.moc"

View File

@ -31,7 +31,7 @@ slots:
void test_Through_Simple() void test_Through_Simple()
{ {
QJsonDocument doc = readJson("tests/data/1.9-simple.json"); QJsonDocument doc = readJson("data/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 +41,7 @@ slots:
void test_Through() void test_Through()
{ {
QJsonDocument doc = readJson("tests/data/1.9.json"); QJsonDocument doc = readJson("data/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);
@ -51,5 +51,5 @@ slots:
QTEST_GUILESS_MAIN(MojangVersionFormatTest) QTEST_GUILESS_MAIN(MojangVersionFormatTest)
#include "tst_MojangVersionFormat.moc" #include "MojangVersionFormat_test.moc"

View File

@ -41,5 +41,5 @@ slots:
QTEST_GUILESS_MAIN(ParseUtilsTest) QTEST_GUILESS_MAIN(ParseUtilsTest)
#include "tst_ParseUtils.moc" #include "ParseUtils_test.moc"

View File

@ -59,4 +59,4 @@ slots:
QTEST_GUILESS_MAIN(IniFileTest) QTEST_GUILESS_MAIN(IniFileTest)
#include "tst_inifile.moc" #include "INIFile_test.moc"

View File

@ -77,31 +77,31 @@ slots:
QTest::addColumn<bool>("ret"); QTest::addColumn<bool>("ret");
QTest::newRow("one") QTest::newRow("one")
<< MULTIMC_GET_TEST_FILE("tests/data/1.json") << MULTIMC_GET_TEST_FILE("data/1.json")
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{"fileOne", << VersionFileEntry{"fileOne",
493, 493,
encodeBaseFile("/tests/data/fileOneA"), encodeBaseFile("/data/fileOneA"),
"9eb84090956c484e32cb6c08455a667b"} "9eb84090956c484e32cb6c08455a667b"}
<< VersionFileEntry{"fileTwo", << VersionFileEntry{"fileTwo",
644, 644,
encodeBaseFile("/tests/data/fileTwo"), encodeBaseFile("/data/fileTwo"),
"38f94f54fa3eb72b0ea836538c10b043"} "38f94f54fa3eb72b0ea836538c10b043"}
<< VersionFileEntry{"fileThree", << VersionFileEntry{"fileThree",
750, 750,
encodeBaseFile("/tests/data/fileThree"), encodeBaseFile("/data/fileThree"),
"f12df554b21e320be6471d7154130e70"}) "f12df554b21e320be6471d7154130e70"})
<< QString() << true; << QString() << true;
QTest::newRow("two") QTest::newRow("two")
<< MULTIMC_GET_TEST_FILE("tests/data/2.json") << MULTIMC_GET_TEST_FILE("data/2.json")
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{"fileOne", << VersionFileEntry{"fileOne",
493, 493,
encodeBaseFile("/tests/data/fileOneB"), encodeBaseFile("/data/fileOneB"),
"42915a71277c9016668cce7b82c6b577"} "42915a71277c9016668cce7b82c6b577"}
<< VersionFileEntry{"fileTwo", << VersionFileEntry{"fileTwo",
644, 644,
encodeBaseFile("/tests/data/fileTwo"), encodeBaseFile("/data/fileTwo"),
"38f94f54fa3eb72b0ea836538c10b043"}) "38f94f54fa3eb72b0ea836538c10b043"})
<< QString() << true; << QString() << true;
} }
@ -133,42 +133,42 @@ slots:
QTest::newRow("test 1") QTest::newRow("test 1")
<< tempFolder << (VersionFileList() << tempFolder << (VersionFileList()
<< VersionFileEntry{ << VersionFileEntry{
"tests/data/fileOne", 493, "data/fileOne", 493,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileOne-1"), "http", "http://host/path/fileOne-1"),
"9eb84090956c484e32cb6c08455a667b"} "9eb84090956c484e32cb6c08455a667b"}
<< VersionFileEntry{ << VersionFileEntry{
"tests/data/fileTwo", 644, "data/fileTwo", 644,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileTwo-1"), "http", "http://host/path/fileTwo-1"),
"38f94f54fa3eb72b0ea836538c10b043"} "38f94f54fa3eb72b0ea836538c10b043"}
<< VersionFileEntry{ << VersionFileEntry{
"tests/data/fileThree", 420, "data/fileThree", 420,
FileSourceList() FileSourceList()
<< FileSource( << FileSource(
"http", "http://host/path/fileThree-1"), "http", "http://host/path/fileThree-1"),
"f12df554b21e320be6471d7154130e70"}) "f12df554b21e320be6471d7154130e70"})
<< (VersionFileList() << (VersionFileList()
<< VersionFileEntry{ << VersionFileEntry{
"tests/data/fileOne", 493, "data/fileOne", 493,
FileSourceList() FileSourceList()
<< FileSource("http", << FileSource("http",
"http://host/path/fileOne-2"), "http://host/path/fileOne-2"),
"42915a71277c9016668cce7b82c6b577"} "42915a71277c9016668cce7b82c6b577"}
<< VersionFileEntry{ << VersionFileEntry{
"tests/data/fileTwo", 644, "data/fileTwo", 644,
FileSourceList() FileSourceList()
<< FileSource("http", << FileSource("http",
"http://host/path/fileTwo-2"), "http://host/path/fileTwo-2"),
"38f94f54fa3eb72b0ea836538c10b043"}) "38f94f54fa3eb72b0ea836538c10b043"})
<< (OperationList() << (OperationList()
<< Operation::DeleteOp("tests/data/fileThree") << Operation::DeleteOp("data/fileThree")
<< Operation::CopyOp( << Operation::CopyOp(
FS::PathCombine(tempFolder, FS::PathCombine(tempFolder,
QString("tests/data/fileOne").replace("/", "_")), QString("data/fileOne").replace("/", "_")),
"tests/data/fileOne", 493)); "data/fileOne", 493));
} }
void test_processFileLists() void test_processFileLists()
{ {
@ -211,4 +211,4 @@ extern "C"
QTEST_GUILESS_MAIN(DownloadTaskTest) QTEST_GUILESS_MAIN(DownloadTaskTest)
} }
#include "tst_DownloadTask.moc" #include "DownloadTask_test.moc"

View File

@ -49,36 +49,36 @@ slots:
QTest::newRow("garbage") QTest::newRow("garbage")
<< QString() << QString()
<< findTestDataUrl("tests/data/garbageChannels.json") << findTestDataUrl("data/garbageChannels.json")
<< false << false
<< false << false
<< QList<UpdateChecker::ChannelListEntry>(); << QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("errors") QTest::newRow("errors")
<< QString() << QString()
<< findTestDataUrl("tests/data/errorChannels.json") << findTestDataUrl("data/errorChannels.json")
<< false << false
<< true << true
<< QList<UpdateChecker::ChannelListEntry>(); << QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("no channels") QTest::newRow("no channels")
<< QString() << QString()
<< findTestDataUrl("tests/data/noChannels.json") << findTestDataUrl("data/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("tests/data/oneChannel.json") << findTestDataUrl("data/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("tests/data/channels.json") << findTestDataUrl("data/channels.json")
<< true << true
<< true << true
<< (QList<UpdateChecker::ChannelListEntry>() << (QList<UpdateChecker::ChannelListEntry>()
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("tests/data")} << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("data")}
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("tests/data")} << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("data")}
<< 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()
@ -115,7 +115,7 @@ slots:
void tst_UpdateChecking() void tst_UpdateChecking()
{ {
QString channel = "develop"; QString channel = "develop";
QString channelUrl = findTestDataUrl("tests/data/channels.json"); QString channelUrl = findTestDataUrl("data/channels.json");
int currentBuild = 2; int currentBuild = 2;
UpdateChecker checker(channelUrl, channel, currentBuild); UpdateChecker checker(channelUrl, channel, currentBuild);
@ -129,7 +129,7 @@ slots:
QVERIFY(channelListLoadedSpy.wait()); QVERIFY(channelListLoadedSpy.wait());
qDebug() << "CWD:" << QDir::current().absolutePath(); qDebug() << "CWD:" << QDir::current().absolutePath();
checker.m_channels[0].url = findTestDataUrl("tests/data/"); checker.m_channels[0].url = findTestDataUrl("data/");
checker.checkForUpdate(channel, false); checker.checkForUpdate(channel, false);
QVERIFY(updateAvailableSpy.wait()); QVERIFY(updateAvailableSpy.wait());
@ -143,4 +143,4 @@ slots:
QTEST_GUILESS_MAIN(UpdateCheckerTest) QTEST_GUILESS_MAIN(UpdateCheckerTest)
#include "tst_UpdateChecker.moc" #include "UpdateChecker_test.moc"

View File

@ -47,4 +47,4 @@ slots:
QTEST_GUILESS_MAIN(WonkoIndexTest) QTEST_GUILESS_MAIN(WonkoIndexTest)
#include "tst_WonkoIndex.moc" #include "WonkoIndex_test.moc"

View File

@ -12,9 +12,9 @@ function(add_unit_test name)
cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if(WIN32) if(WIN32)
add_executable(tst_${name} ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc) add_executable(${name}_test ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc)
else() else()
add_executable(tst_${name} ${OPT_SOURCES}) add_executable(${name}_test ${OPT_SOURCES})
endif() endif()
if(NOT "${OPT_DATA}" STREQUAL "") if(NOT "${OPT_DATA}" STREQUAL "")
@ -31,7 +31,7 @@ function(add_unit_test name)
endif() endif()
if(NOT TARGET "${DATA_TARGET_NAME}") if(NOT TARGET "${DATA_TARGET_NAME}")
add_custom_target(${DATA_TARGET_NAME}) add_custom_target(${DATA_TARGET_NAME})
add_dependencies(tst_${name} ${DATA_TARGET_NAME}) add_dependencies(${name}_test ${DATA_TARGET_NAME})
add_custom_command( add_custom_command(
TARGET ${DATA_TARGET_NAME} 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 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
@ -40,10 +40,10 @@ function(add_unit_test name)
endif() endif()
endif() endif()
target_link_libraries(tst_${name} ${OPT_LIBS}) target_link_libraries(${name}_test ${OPT_LIBS})
qt5_use_modules(tst_${name} Test ${OPT_QT}) qt5_use_modules(${name}_test Test ${OPT_QT})
target_include_directories(tst_${name} PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/") target_include_directories(${name}_test PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/")
add_test(NAME ${name} COMMAND tst_${name}) add_test(NAME ${name} COMMAND ${name}_test)
endfunction() endfunction()

View File

@ -2,14 +2,12 @@
# variables. Create destination directory if it does not exist. # variables. Create destination directory if it does not exist.
function(configure_files srcDir destDir) function(configure_files srcDir destDir)
message(STATUS "Configuring directory ${destDir} from ${srcDir}")
make_directory(${destDir}) make_directory(${destDir})
file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*) file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
foreach(templateFile ${templateFiles}) foreach(templateFile ${templateFiles})
set(srcTemplatePath ${srcDir}/${templateFile}) set(srcTemplatePath ${srcDir}/${templateFile})
if(NOT IS_DIRECTORY ${srcTemplatePath}) if(NOT IS_DIRECTORY ${srcTemplatePath})
message(STATUS "Configuring file ${templateFile}")
configure_file( configure_file(
${srcTemplatePath} ${srcTemplatePath}
${destDir}/${templateFile} ${destDir}/${templateFile}
@ -17,7 +15,6 @@ function(configure_files srcDir destDir)
NEWLINE_STYLE LF NEWLINE_STYLE LF
) )
else() else()
message(STATUS "Recursing? ${srcTemplatePath}")
configure_files("${srcTemplatePath}" "${destDir}/${templateFile}") configure_files("${srcTemplatePath}" "${destDir}/${templateFile}")
endif() endif()
endforeach() endforeach()

View File

@ -1,82 +0,0 @@
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
)

View File

@ -1,2 +0,0 @@
* -text -diff

View File

@ -1,37 +0,0 @@
#include <QTest>
#include "TestUtil.h"
class IniFileTest : public QObject
{
Q_OBJECT
private
slots:
void test_FSTree()
{
/*
QTest::addColumn<QString>("through");
QTest::newRow("unix path") << "/abc/def/ghi/jkl";
QTest::newRow("windows path") << "C:\\Program files\\terrible\\name\\of something\\";
QTest::newRow("Plain text") << "Lorem ipsum dolor sit amet.";
QTest::newRow("Escape sequences") << "Lorem\n\t\n\\n\\tAAZ\nipsum dolor\n\nsit amet.";
QTest::newRow("Escape sequences 2") << "\"\n\n\"";
*/
}
void test_Regexp()
{
/*
QFETCH(QString, through);
QString there = INIFile::escape(through);
QString back = INIFile::unescape(there);
QCOMPARE(back, through);
*/
}
};
QTEST_GUILESS_MAIN(IniFileTest)
#include "tst_filematchers.moc"

View File

@ -1,70 +0,0 @@
#include <QTest>
#include <QStandardPaths>
#include "TestUtil.h"
#include <FileSystem.h>
class UserUtilsTest : public QObject
{
Q_OBJECT
private
slots:
void initTestCase()
{
}
void cleanupTestCase()
{
}
void test_getDesktop()
{
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)
<< MULTIMC_GET_TEST_FILE("data/tst_userutils-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(UserUtilsTest)
#include "tst_userutils.moc"