From 4c7d3a103ca9cfd3af0b3acf2877561150c5ac60 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 11 Sep 2022 22:25:18 +0200 Subject: refactor: restructure tests Signed-off-by: Sefa Eyeoglu --- launcher/CMakeLists.txt | 62 +-- launcher/FileSystem_test.cpp | 122 ----- launcher/GZip_test.cpp | 56 --- launcher/Version_test.cpp | 85 ---- launcher/java/JavaVersion_test.cpp | 115 ----- launcher/meta/Index_test.cpp | 36 -- launcher/minecraft/GradleSpecifier_test.cpp | 77 --- launcher/minecraft/Library_test.cpp | 270 ----------- launcher/minecraft/MojangVersionFormat_test.cpp | 53 --- launcher/minecraft/ParseUtils_test.cpp | 43 -- .../minecraft/mod/ResourceFolderModel_test.cpp | 261 ---------- launcher/minecraft/mod/ResourcePackParse_test.cpp | 73 --- .../mod/testdata/another_test_folder/pack.mcmeta | 6 - launcher/minecraft/mod/testdata/supercoolmod.jar | 1 - .../test_folder/assets/minecraft/textures/blah.txt | 1 - .../minecraft/mod/testdata/test_folder/pack.mcmeta | 6 - .../minecraft/mod/testdata/test_folder/pack.nfo | 1 - .../mod/testdata/test_resource_pack_idk.zip | Bin 322 -> 0 bytes launcher/minecraft/testdata/1.9-simple.json | 198 -------- launcher/minecraft/testdata/1.9.json | 529 --------------------- launcher/minecraft/testdata/codecwav-20101023.jar | 1 - launcher/minecraft/testdata/lib-native-arch.json | 46 -- launcher/minecraft/testdata/lib-native.json | 52 -- launcher/minecraft/testdata/lib-simple.json | 11 - .../testdata/testname-testversion-linux-32.jar | 1 - launcher/modplatform/packwiz/Packwiz_test.cpp | 87 ---- .../packwiz/testdata/borderless-mining.pw.toml | 13 - .../screenshot-to-clipboard-fabric.pw.toml | 13 - launcher/mojang/PackageManifest_test.cpp | 343 ------------- launcher/mojang/testdata/1.8.0_202-x64.json | 1 - launcher/mojang/testdata/inspect/a/b.txt | 0 launcher/mojang/testdata/inspect/a/b/b.txt | 1 - launcher/mojang/testdata/inspect_win/a/b.txt | 0 launcher/mojang/testdata/inspect_win/a/b/b.txt | 0 launcher/settings/INIFile_test.cpp | 62 --- launcher/tasks/Task_test.cpp | 190 -------- .../testdata/FileSystem-test_createShortcut-unix | 6 - .../test_folder/assets/minecraft/textures/blah.txt | 1 - launcher/testdata/test_folder/pack.mcmeta | 6 - launcher/testdata/test_folder/pack.nfo | 1 - 40 files changed, 1 insertion(+), 2829 deletions(-) delete mode 100644 launcher/FileSystem_test.cpp delete mode 100644 launcher/GZip_test.cpp delete mode 100644 launcher/Version_test.cpp delete mode 100644 launcher/java/JavaVersion_test.cpp delete mode 100644 launcher/meta/Index_test.cpp delete mode 100644 launcher/minecraft/GradleSpecifier_test.cpp delete mode 100644 launcher/minecraft/Library_test.cpp delete mode 100644 launcher/minecraft/MojangVersionFormat_test.cpp delete mode 100644 launcher/minecraft/ParseUtils_test.cpp delete mode 100644 launcher/minecraft/mod/ResourceFolderModel_test.cpp delete mode 100644 launcher/minecraft/mod/ResourcePackParse_test.cpp delete mode 100644 launcher/minecraft/mod/testdata/another_test_folder/pack.mcmeta delete mode 100644 launcher/minecraft/mod/testdata/supercoolmod.jar delete mode 100644 launcher/minecraft/mod/testdata/test_folder/assets/minecraft/textures/blah.txt delete mode 100644 launcher/minecraft/mod/testdata/test_folder/pack.mcmeta delete mode 100644 launcher/minecraft/mod/testdata/test_folder/pack.nfo delete mode 100644 launcher/minecraft/mod/testdata/test_resource_pack_idk.zip delete mode 100644 launcher/minecraft/testdata/1.9-simple.json delete mode 100644 launcher/minecraft/testdata/1.9.json delete mode 100644 launcher/minecraft/testdata/codecwav-20101023.jar delete mode 100644 launcher/minecraft/testdata/lib-native-arch.json delete mode 100644 launcher/minecraft/testdata/lib-native.json delete mode 100644 launcher/minecraft/testdata/lib-simple.json delete mode 100644 launcher/minecraft/testdata/testname-testversion-linux-32.jar delete mode 100644 launcher/modplatform/packwiz/Packwiz_test.cpp delete mode 100644 launcher/modplatform/packwiz/testdata/borderless-mining.pw.toml delete mode 100644 launcher/modplatform/packwiz/testdata/screenshot-to-clipboard-fabric.pw.toml delete mode 100644 launcher/mojang/PackageManifest_test.cpp delete mode 100644 launcher/mojang/testdata/1.8.0_202-x64.json delete mode 100755 launcher/mojang/testdata/inspect/a/b.txt delete mode 120000 launcher/mojang/testdata/inspect/a/b/b.txt delete mode 100644 launcher/mojang/testdata/inspect_win/a/b.txt delete mode 100644 launcher/mojang/testdata/inspect_win/a/b/b.txt delete mode 100644 launcher/settings/INIFile_test.cpp delete mode 100644 launcher/tasks/Task_test.cpp delete mode 100755 launcher/testdata/FileSystem-test_createShortcut-unix delete mode 100644 launcher/testdata/test_folder/assets/minecraft/textures/blah.txt delete mode 100644 launcher/testdata/test_folder/pack.mcmeta delete mode 100644 launcher/testdata/test_folder/pack.nfo (limited to 'launcher') diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index a5303e94..6e93b530 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -88,12 +88,6 @@ set(CORE_SOURCES MMCTime.cpp ) -ecm_add_test(FileSystem_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME FileSystem) # TODO: needs testdata - -ecm_add_test(GZip_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME GZip) - set(PATHMATCHER_SOURCES # Path matchers pathmatcher/FSTreeMatcher.h @@ -355,46 +349,6 @@ set(MINECRAFT_SOURCES mojang/PackageManifest.cpp minecraft/Agent.h) -ecm_add_test(minecraft/GradleSpecifier_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME GradleSpecifier) - -if(BUILD_TESTING) - add_executable(PackageManifest - mojang/PackageManifest_test.cpp - ) - target_link_libraries(PackageManifest - Launcher_logic - Qt${QT_VERSION_MAJOR}::Test - ) - target_include_directories(PackageManifest - PRIVATE ../cmake/UnitTest/ - ) - add_test( - NAME PackageManifest - COMMAND PackageManifest - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) -endif() - -# TODO: needs minecraft/testdata -ecm_add_test(minecraft/MojangVersionFormat_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME MojangVersionFormat) - -ecm_add_test(minecraft/Library_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME Library) - -# FIXME: shares data with FileSystem test -# TODO: needs testdata -ecm_add_test(minecraft/mod/ResourceFolderModel_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME ResourceFolderModel) - -ecm_add_test(minecraft/mod/ResourcePackParse_test.cpp - LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME ResourcePackParse) - -ecm_add_test(minecraft/ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME ParseUtils) - # the screenshots feature set(SCREENSHOTS_SOURCES screenshots/Screenshot.h @@ -416,9 +370,6 @@ set(TASKS_SOURCES tasks/MultipleOptionsTask.cpp ) -ecm_add_test(tasks/Task_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME Task) - set(SETTINGS_SOURCES # Settings settings/INIFile.cpp @@ -435,9 +386,6 @@ set(SETTINGS_SOURCES settings/SettingsObject.h ) -ecm_add_test(settings/INIFile_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME INIFile) - set(JAVA_SOURCES java/JavaChecker.h java/JavaChecker.cpp @@ -453,9 +401,6 @@ set(JAVA_SOURCES java/JavaVersion.cpp ) -ecm_add_test(java/JavaVersion_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME JavaVersion) - set(TRANSLATIONS_SOURCES translations/TranslationsModel.h translations/TranslationsModel.cpp @@ -558,9 +503,6 @@ set(PACKWIZ_SOURCES modplatform/packwiz/Packwiz.cpp ) -# TODO: needs modplatform/packwiz/testdata -ecm_add_test(modplatform/packwiz/Packwiz_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME Packwiz) set(TECHNIC_SOURCES modplatform/technic/SingleZipPackInstallTask.h @@ -584,9 +526,6 @@ set(ATLAUNCHER_SOURCES modplatform/atlauncher/ATLShareCode.h ) -ecm_add_test(meta/Index_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test - TEST_NAME Index) - ################################ COMPILE ################################ # we need zlib @@ -1005,6 +944,7 @@ endif() # Add executable add_library(Launcher_logic STATIC ${LOGIC_SOURCES} ${LAUNCHER_SOURCES} ${LAUNCHER_UI} ${LAUNCHER_RESOURCES}) +target_include_directories(Launcher_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(Launcher_logic systeminfo Launcher_classparser diff --git a/launcher/FileSystem_test.cpp b/launcher/FileSystem_test.cpp deleted file mode 100644 index 99ae9269..00000000 --- a/launcher/FileSystem_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include - -#include "FileSystem.h" - -class FileSystemTest : public QObject -{ - Q_OBJECT - - const QString bothSlash = "/foo/"; - const QString trailingSlash = "foo/"; - const QString leadingSlash = "/foo"; - -private -slots: - void test_pathCombine() - { - QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash)); - QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash)); - QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash)); - - QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash)); - QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash)); - QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash)); - } - - void test_PathCombine1_data() - { - QTest::addColumn("result"); - QTest::addColumn("path1"); - QTest::addColumn("path2"); - - QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl"; - QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl"; -#if defined(Q_OS_WIN) - QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc"; - QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl"; - QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl"; -#endif - } - - void test_PathCombine1() - { - QFETCH(QString, result); - QFETCH(QString, path1); - QFETCH(QString, path2); - - QCOMPARE(FS::PathCombine(path1, path2), result); - } - - void test_PathCombine2_data() - { - QTest::addColumn("result"); - QTest::addColumn("path1"); - QTest::addColumn("path2"); - QTest::addColumn("path3"); - - QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl"; - QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl"; - QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl"; - QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl"; -#if defined(Q_OS_WIN) - QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl"; - QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl"; - QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl"; - QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl"; -#endif - } - - void test_PathCombine2() - { - QFETCH(QString, result); - QFETCH(QString, path1); - QFETCH(QString, path2); - QFETCH(QString, path3); - - QCOMPARE(FS::PathCombine(path1, path2, path3), result); - } - - void test_copy() - { - QString folder = QFINDTESTDATA("testdata/test_folder"); - auto f = [&folder]() - { - QTemporaryDir tempDir; - tempDir.setAutoRemove(true); - qDebug() << "From:" << folder << "To:" << tempDir.path(); - - QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder")); - qDebug() << tempDir.path(); - qDebug() << target_dir.path(); - FS::copy c(folder, target_dir.path()); - c(); - - for(auto entry: target_dir.entryList()) - { - qDebug() << entry; - } - QVERIFY(target_dir.entryList().contains("pack.mcmeta")); - QVERIFY(target_dir.entryList().contains("assets")); - }; - - // first try variant without trailing / - QVERIFY(!folder.endsWith('/')); - f(); - - // then variant with trailing / - folder.append('/'); - QVERIFY(folder.endsWith('/')); - f(); - } - - void test_getDesktop() - { - QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); - } -}; - -QTEST_GUILESS_MAIN(FileSystemTest) - -#include "FileSystem_test.moc" diff --git a/launcher/GZip_test.cpp b/launcher/GZip_test.cpp deleted file mode 100644 index 73859fbc..00000000 --- a/launcher/GZip_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include - -#include "GZip.h" -#include - -void fib(int &prev, int &cur) -{ - auto ret = prev + cur; - prev = cur; - cur = ret; -} - -class GZipTest : public QObject -{ - Q_OBJECT -private -slots: - - void test_Through() - { - // test up to 10 MB - static const int size = 10 * 1024 * 1024; - QByteArray random; - QByteArray compressed; - QByteArray decompressed; - std::default_random_engine eng((std::random_device())()); - std::uniform_int_distribution idis(0, std::numeric_limits::max()); - - // initialize random buffer - for(int i = 0; i < size; i++) - { - random.append((char)idis(eng)); - } - - // initialize fibonacci - int prev = 1; - int cur = 1; - - // test if fibonacci long random buffers pass through GZip - do - { - QByteArray copy = random; - copy.resize(cur); - compressed.clear(); - decompressed.clear(); - QVERIFY(GZip::zip(copy, compressed)); - QVERIFY(GZip::unzip(compressed, decompressed)); - QCOMPARE(decompressed, copy); - fib(prev, cur); - } while (cur < size); - } -}; - -QTEST_GUILESS_MAIN(GZipTest) - -#include "GZip_test.moc" diff --git a/launcher/Version_test.cpp b/launcher/Version_test.cpp deleted file mode 100644 index b2d657a6..00000000 --- a/launcher/Version_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "TestUtil.h" -#include - -class ModUtilsTest : public QObject -{ - Q_OBJECT - void setupVersions() - { - QTest::addColumn("first"); - QTest::addColumn("second"); - QTest::addColumn("lessThan"); - QTest::addColumn("equal"); - - QTest::newRow("equal, explicit") << "1.2.0" << "1.2.0" << false << true; - QTest::newRow("equal, implicit 1") << "1.2" << "1.2.0" << false << true; - QTest::newRow("equal, implicit 2") << "1.2.0" << "1.2" << false << true; - QTest::newRow("equal, two-digit") << "1.42" << "1.42" << false << true; - - QTest::newRow("lessThan, explicit 1") << "1.2.0" << "1.2.1" << true << false; - QTest::newRow("lessThan, explicit 2") << "1.2.0" << "1.3.0" << true << false; - QTest::newRow("lessThan, explicit 3") << "1.2.0" << "2.2.0" << true << false; - QTest::newRow("lessThan, implicit 1") << "1.2" << "1.2.1" << true << false; - QTest::newRow("lessThan, implicit 2") << "1.2" << "1.3.0" << true << false; - QTest::newRow("lessThan, implicit 3") << "1.2" << "2.2.0" << true << false; - QTest::newRow("lessThan, two-digit") << "1.41" << "1.42" << true << false; - - QTest::newRow("greaterThan, explicit 1") << "1.2.1" << "1.2.0" << false << false; - QTest::newRow("greaterThan, explicit 2") << "1.3.0" << "1.2.0" << false << false; - QTest::newRow("greaterThan, explicit 3") << "2.2.0" << "1.2.0" << false << false; - QTest::newRow("greaterThan, implicit 1") << "1.2.1" << "1.2" << false << false; - QTest::newRow("greaterThan, implicit 2") << "1.3.0" << "1.2" << false << false; - QTest::newRow("greaterThan, implicit 3") << "2.2.0" << "1.2" << false << false; - QTest::newRow("greaterThan, two-digit") << "1.42" << "1.41" << false << false; - } - -private slots: - void initTestCase() - { - - } - void cleanupTestCase() - { - - } - - void test_versionCompare_data() - { - setupVersions(); - } - void test_versionCompare() - { - QFETCH(QString, first); - QFETCH(QString, second); - QFETCH(bool, lessThan); - QFETCH(bool, equal); - - const auto v1 = Version(first); - const auto v2 = Version(second); - - QCOMPARE(v1 < v2, lessThan); - QCOMPARE(v1 > v2, !lessThan && !equal); - QCOMPARE(v1 == v2, equal); - } -}; - -QTEST_GUILESS_MAIN(ModUtilsTest) - -#include "Version_test.moc" diff --git a/launcher/java/JavaVersion_test.cpp b/launcher/java/JavaVersion_test.cpp deleted file mode 100644 index 545947ef..00000000 --- a/launcher/java/JavaVersion_test.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include - -#include "java/JavaVersion.h" - -class JavaVersionTest : public QObject -{ - Q_OBJECT -private -slots: - void test_Parse_data() - { - QTest::addColumn("string"); - QTest::addColumn("major"); - QTest::addColumn("minor"); - QTest::addColumn("security"); - QTest::addColumn("prerelease"); - - QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString(); - QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea"; - - QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString(); - QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString(); - QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString(); - QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea"; - QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea"; - } - void test_Parse() - { - QFETCH(QString, string); - QFETCH(int, major); - QFETCH(int, minor); - QFETCH(int, security); - QFETCH(QString, prerelease); - - JavaVersion test(string); - QCOMPARE(test.m_string, string); - QCOMPARE(test.toString(), string); - QCOMPARE(test.m_major, major); - QCOMPARE(test.m_minor, minor); - QCOMPARE(test.m_security, security); - QCOMPARE(test.m_prerelease, prerelease); - } - - void test_Sort_data() - { - QTest::addColumn("lhs"); - QTest::addColumn("rhs"); - QTest::addColumn("smaller"); - QTest::addColumn("equal"); - QTest::addColumn("bigger"); - - // old format and new format equivalence - QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false; - // old format major version - QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false; - // new format - first release vs first security patch - QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false; - QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true; - // new format - first minor vs first release/security patch - QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" << false << false << true; - QTest::newRow("9.0.1 < 9.1") << "9.0.1" << "9.1" << true << false << false; - QTest::newRow("9.1 > 9") << "9.1" << "9" << false << false << true; - QTest::newRow("9 > 9.1") << "9" << "9.1" << true << false << false; - // new format - omitted numbers - QTest::newRow("9 == 9.0") << "9" << "9.0" << false << true << false; - QTest::newRow("9 == 9.0.0") << "9" << "9.0.0" << false << true << false; - QTest::newRow("9.0 == 9.0.0") << "9.0" << "9.0.0" << false << true << false; - // early access and prereleases compared to final release - QTest::newRow("9-ea < 9") << "9-ea" << "9" << true << false << false; - QTest::newRow("9 < 9.0.1-ea") << "9" << "9.0.1-ea" << true << false << false; - QTest::newRow("9.0.1-ea > 9") << "9.0.1-ea" << "9" << false << false << true; - // prerelease difference only testing - QTest::newRow("9-1 == 9-1") << "9-1" << "9-1" << false << true << false; - QTest::newRow("9-1 < 9-2") << "9-1" << "9-2" << true << false << false; - QTest::newRow("9-5 < 9-20") << "9-5" << "9-20" << true << false << false; - QTest::newRow("9-rc1 < 9-rc2") << "9-rc1" << "9-rc2" << true << false << false; - QTest::newRow("9-rc5 < 9-rc20") << "9-rc5" << "9-rc20" << true << false << false; - QTest::newRow("9-rc < 9-rc2") << "9-rc" << "9-rc2" << true << false << false; - QTest::newRow("9-ea < 9-rc") << "9-ea" << "9-rc" << true << false << false; - } - void test_Sort() - { - QFETCH(QString, lhs); - QFETCH(QString, rhs); - QFETCH(bool, smaller); - QFETCH(bool, equal); - QFETCH(bool, bigger); - JavaVersion lver(lhs); - JavaVersion rver(rhs); - QCOMPARE(lver < rver, smaller); - QCOMPARE(lver == rver, equal); - QCOMPARE(lver > rver, bigger); - } - void test_PermGen_data() - { - QTest::addColumn("version"); - QTest::addColumn("needs_permgen"); - QTest::newRow("1.6.0_33") << "1.6.0_33" << true; - QTest::newRow("1.7.0_60") << "1.7.0_60" << true; - QTest::newRow("1.8.0_22") << "1.8.0_22" << false; - QTest::newRow("9-ea") << "9-ea" << false; - QTest::newRow("9.2.4") << "9.2.4" << false; - } - void test_PermGen() - { - QFETCH(QString, version); - QFETCH(bool, needs_permgen); - JavaVersion v(version); - QCOMPARE(needs_permgen, v.requiresPermGen()); - } -}; - -QTEST_GUILESS_MAIN(JavaVersionTest) - -#include "JavaVersion_test.moc" diff --git a/launcher/meta/Index_test.cpp b/launcher/meta/Index_test.cpp deleted file mode 100644 index 261858c4..00000000 --- a/launcher/meta/Index_test.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#include "meta/Index.h" -#include "meta/VersionList.h" - -class IndexTest : public QObject -{ - Q_OBJECT -private -slots: - void test_hasUid_and_getList() - { - Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); - QVERIFY(windex.hasUid("list1")); - QVERIFY(!windex.hasUid("asdf")); - QVERIFY(windex.get("list2") != nullptr); - QCOMPARE(windex.get("list2")->uid(), QString("list2")); - QVERIFY(windex.get("adsf") != nullptr); - } - - void test_merge() - { - Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}))); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list4"), std::make_shared("list2"), std::make_shared("list5")}))); - QCOMPARE(windex.lists().size(), 5); - windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list6")}))); - QCOMPARE(windex.lists().size(), 6); - } -}; - -QTEST_GUILESS_MAIN(IndexTest) - -#include "Index_test.moc" diff --git a/launcher/minecraft/GradleSpecifier_test.cpp b/launcher/minecraft/GradleSpecifier_test.cpp deleted file mode 100644 index a062dfac..00000000 --- a/launcher/minecraft/GradleSpecifier_test.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include - -#include "minecraft/GradleSpecifier.h" - -class GradleSpecifierTest : public QObject -{ - Q_OBJECT -private -slots: - void initTestCase() - { - - } - void cleanupTestCase() - { - - } - - void test_Positive_data() - { - QTest::addColumn("through"); - - QTest::newRow("3 parter") << "org.gradle.test.classifiers:service:1.0"; - QTest::newRow("classifier") << "org.gradle.test.classifiers:service:1.0:jdk15"; - QTest::newRow("jarextension") << "org.gradle.test.classifiers:service:1.0@jar"; - QTest::newRow("jarboth") << "org.gradle.test.classifiers:service:1.0:jdk15@jar"; - QTest::newRow("packxz") << "org.gradle.test.classifiers:service:1.0:jdk15@jar.pack.xz"; - } - void test_Positive() - { - QFETCH(QString, through); - - QString converted = GradleSpecifier(through).serialize(); - - QCOMPARE(converted, through); - } - - void test_Path_data() - { - QTest::addColumn("spec"); - QTest::addColumn("expected"); - - QTest::newRow("3 parter") << "group.id:artifact:1.0" << "group/id/artifact/1.0/artifact-1.0.jar"; - QTest::newRow("doom") << "id.software:doom:1.666:demons@wad" << "id/software/doom/1.666/doom-1.666-demons.wad"; - } - void test_Path() - { - QFETCH(QString, spec); - QFETCH(QString, expected); - - QString converted = GradleSpecifier(spec).toPath(); - - QCOMPARE(converted, expected); - } - void test_Negative_data() - { - QTest::addColumn("input"); - - QTest::newRow("too many :") << "org:gradle.test:class:::ifiers:service:1.0::"; - QTest::newRow("nonsense") << "I like turtles"; - QTest::newRow("empty string") << ""; - QTest::newRow("missing version") << "herp.derp:artifact"; - } - void test_Negative() - { - QFETCH(QString, input); - - GradleSpecifier spec(input); - QVERIFY(!spec.valid()); - QCOMPARE(spec.serialize(), input); - QCOMPARE(spec.toPath(), QString()); - } -}; - -QTEST_GUILESS_MAIN(GradleSpecifierTest) - -#include "GradleSpecifier_test.moc" diff --git a/launcher/minecraft/Library_test.cpp b/launcher/minecraft/Library_test.cpp deleted file mode 100644 index 834dd558..00000000 --- a/launcher/minecraft/Library_test.cpp +++ /dev/null @@ -1,270 +0,0 @@ -#include - -#include "minecraft/MojangVersionFormat.h" -#include "minecraft/OneSixVersionFormat.h" -#include "minecraft/Library.h" -#include "net/HttpMetaCache.h" -#include "FileSystem.h" - -class LibraryTest : public QObject -{ - Q_OBJECT -private: - LibraryPtr readMojangJson(const QString path) - { - QFile jsonFile(path); - jsonFile.open(QIODevice::ReadOnly); - auto data = jsonFile.readAll(); - jsonFile.close(); - ProblemContainer problems; - return MojangVersionFormat::libraryFromJson(problems, QJsonDocument::fromJson(data).object(), path); - } - // get absolute path to expected storage, assuming default cache prefix - QStringList getStorage(QString relative) - { - return {FS::PathCombine(cache->getBasePath("libraries"), relative)}; - } -private -slots: - void initTestCase() - { - cache.reset(new HttpMetaCache()); - cache->addBase("libraries", QDir("libraries").absolutePath()); - dataDir = QDir(QFINDTESTDATA("testdata")).absolutePath(); - } - void test_legacy() - { - Library test("test.package:testname:testversion"); - QCOMPARE(test.artifactPrefix(), QString("test.package:testname")); - QCOMPARE(test.isNative(), false); - - QStringList jar, native, native32, native64; - test.getApplicableFiles(currentSystem, jar, native, native32, native64, QString()); - QCOMPARE(jar, getStorage("test/package/testname/testversion/testname-testversion.jar")); - QCOMPARE(native, {}); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - } - void test_legacy_url() - { - QStringList failedFiles; - Library test("test.package:testname:testversion"); - test.setRepositoryURL("file://foo/bar"); - auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString()); - QCOMPARE(downloads.size(), 1); - QCOMPARE(failedFiles, {}); - NetAction::Ptr dl = downloads[0]; - QCOMPARE(dl->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion.jar")); - } - void test_legacy_url_local_broken() - { - Library test("test.package:testname:testversion"); - QCOMPARE(test.isNative(), false); - QStringList failedFiles; - test.setHint("local"); - auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString()); - QCOMPARE(downloads.size(), 0); - QCOMPARE(failedFiles, {"testname-testversion.jar"}); - } - void test_legacy_url_local_override() - { - Library test("com.paulscode:codecwav:20101023"); - QCOMPARE(test.isNative(), false); - QStringList failedFiles; - test.setHint("local"); - auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QFINDTESTDATA("testdata")); - QCOMPARE(downloads.size(), 0); - qDebug() << failedFiles; - QCOMPARE(failedFiles.size(), 0); - - QStringList jar, native, native32, native64; - test.getApplicableFiles(currentSystem, jar, native, native32, native64, QFINDTESTDATA("testdata")); - QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()}); - QCOMPARE(native, {}); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - } - void test_legacy_native() - { - Library test("test.package:testname:testversion"); - test.m_nativeClassifiers[OpSys::Os_Linux]="linux"; - QCOMPARE(test.isNative(), true); - test.setRepositoryURL("file://foo/bar"); - { - QStringList jar, native, native32, native64; - test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString()); - QCOMPARE(jar, {}); - QCOMPARE(native, getStorage("test/package/testname/testversion/testname-testversion-linux.jar")); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - QStringList failedFiles; - auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 1); - QCOMPARE(failedFiles, {}); - auto dl = dls[0]; - QCOMPARE(dl->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux.jar")); - } - } - void test_legacy_native_arch() - { - Library test("test.package:testname:testversion"); - test.m_nativeClassifiers[OpSys::Os_Linux]="linux-${arch}"; - test.m_nativeClassifiers[OpSys::Os_OSX]="osx-${arch}"; - test.m_nativeClassifiers[OpSys::Os_Windows]="windows-${arch}"; - QCOMPARE(test.isNative(), true); - test.setRepositoryURL("file://foo/bar"); - { - QStringList jar, native, native32, native64; - test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString()); - QCOMPARE(jar, {}); - QCOMPARE(native, {}); - QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-linux-32.jar")); - QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-linux-64.jar")); - QStringList failedFiles; - auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 2); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-32.jar")); - QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-64.jar")); - } - { - QStringList jar, native, native32, native64; - test.getApplicableFiles(Os_Windows, jar, native, native32, native64, QString()); - QCOMPARE(jar, {}); - QCOMPARE(native, {}); - QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-windows-32.jar")); - QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-windows-64.jar")); - QStringList failedFiles; - auto dls = test.getDownloads(Os_Windows, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 2); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-32.jar")); - QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-64.jar")); - } - { - QStringList jar, native, native32, native64; - test.getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); - QCOMPARE(jar, {}); - QCOMPARE(native, {}); - QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-osx-32.jar")); - QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-osx-64.jar")); - QStringList failedFiles; - auto dls = test.getDownloads(Os_OSX, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 2); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-32.jar")); - QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-64.jar")); - } - } - void test_legacy_native_arch_local_override() - { - Library test("test.package:testname:testversion"); - test.m_nativeClassifiers[OpSys::Os_Linux]="linux-${arch}"; - test.setHint("local"); - QCOMPARE(test.isNative(), true); - test.setRepositoryURL("file://foo/bar"); - { - QStringList jar, native, native32, native64; - test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QFINDTESTDATA("testdata")); - QCOMPARE(jar, {}); - QCOMPARE(native, {}); - QCOMPARE(native32, {QFileInfo(QFINDTESTDATA("testdata/testname-testversion-linux-32.jar")).absoluteFilePath()}); - QCOMPARE(native64, {QFileInfo(QFINDTESTDATA("testdata") + "/testname-testversion-linux-64.jar").absoluteFilePath()}); - QStringList failedFiles; - auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata")); - QCOMPARE(dls.size(), 0); - QCOMPARE(failedFiles, {QFileInfo(QFINDTESTDATA("testdata") + "/testname-testversion-linux-64.jar").absoluteFilePath()}); - } - } - void test_onenine() - { - auto test = readMojangJson(QFINDTESTDATA("testdata/lib-simple.json")); - { - QStringList jar, native, native32, native64; - test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); - QCOMPARE(jar, getStorage("com/paulscode/codecwav/20101023/codecwav-20101023.jar")); - QCOMPARE(native, {}); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - } - { - QStringList failedFiles; - auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 1); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar")); - } - test->setHint("local"); - { - QStringList jar, native, native32, native64; - test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QFINDTESTDATA("testdata")); - QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()}); - QCOMPARE(native, {}); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - } - { - QStringList failedFiles; - auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata")); - QCOMPARE(dls.size(), 0); - QCOMPARE(failedFiles, {}); - } - } - void test_onenine_local_override() - { - auto test = readMojangJson(QFINDTESTDATA("testdata/lib-simple.json")); - test->setHint("local"); - { - QStringList jar, native, native32, native64; - test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QFINDTESTDATA("testdata")); - QCOMPARE(jar, {QFileInfo(QFINDTESTDATA("testdata/codecwav-20101023.jar")).absoluteFilePath()}); - QCOMPARE(native, {}); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - } - { - QStringList failedFiles; - auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QFINDTESTDATA("testdata")); - QCOMPARE(dls.size(), 0); - QCOMPARE(failedFiles, {}); - } - } - void test_onenine_native() - { - auto test = readMojangJson(QFINDTESTDATA("testdata/lib-native.json")); - QStringList jar, native, native32, native64; - test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); - QCOMPARE(jar, QStringList()); - QCOMPARE(native, getStorage("org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar")); - QCOMPARE(native32, {}); - QCOMPARE(native64, {}); - QStringList failedFiles; - auto dls = test->getDownloads(Os_OSX, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 1); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar")); - } - void test_onenine_native_arch() - { - auto test = readMojangJson(QFINDTESTDATA("testdata/lib-native-arch.json")); - QStringList jar, native, native32, native64; - test->getApplicableFiles(Os_Windows, jar, native, native32, native64, QString()); - QCOMPARE(jar, {}); - QCOMPARE(native, {}); - QCOMPARE(native32, getStorage("tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-32.jar")); - QCOMPARE(native64, getStorage("tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-64.jar")); - QStringList failedFiles; - auto dls = test->getDownloads(Os_Windows, cache.get(), failedFiles, QString()); - QCOMPARE(dls.size(), 2); - QCOMPARE(failedFiles, {}); - QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-32.jar")); - QCOMPARE(dls[1]->m_url, QUrl("https://libraries.minecraft.net/tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-64.jar")); - } -private: - std::unique_ptr cache; - QString dataDir; -}; - -QTEST_GUILESS_MAIN(LibraryTest) - -#include "Library_test.moc" diff --git a/launcher/minecraft/MojangVersionFormat_test.cpp b/launcher/minecraft/MojangVersionFormat_test.cpp deleted file mode 100644 index 71df784b..00000000 --- a/launcher/minecraft/MojangVersionFormat_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include - -#include "minecraft/MojangVersionFormat.h" - -class MojangVersionFormatTest : public QObject -{ - Q_OBJECT - - static QJsonDocument readJson(const QString path) - { - QFile jsonFile(path); - jsonFile.open(QIODevice::ReadOnly); - auto data = jsonFile.readAll(); - jsonFile.close(); - return QJsonDocument::fromJson(data); - } - static void writeJson(const char *file, QJsonDocument doc) - { - QFile jsonFile(file); - jsonFile.open(QIODevice::WriteOnly | QIODevice::Text); - auto data = doc.toJson(QJsonDocument::Indented); - qDebug() << QString::fromUtf8(data); - jsonFile.write(data); - jsonFile.close(); - } - -private -slots: - void test_Through_Simple() - { - QJsonDocument doc = readJson(QFINDTESTDATA("testdata/1.9-simple.json")); - auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9-simple.json"); - auto doc2 = MojangVersionFormat::versionFileToJson(vfile); - writeJson("1.9-simple-passthorugh.json", doc2); - - QCOMPARE(doc.toJson(), doc2.toJson()); - } - - void test_Through() - { - QJsonDocument doc = readJson(QFINDTESTDATA("testdata/1.9.json")); - auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9.json"); - auto doc2 = MojangVersionFormat::versionFileToJson(vfile); - writeJson("1.9-passthorugh.json", doc2); - QCOMPARE(doc.toJson(), doc2.toJson()); - } -}; - -QTEST_GUILESS_MAIN(MojangVersionFormatTest) - -#include "MojangVersionFormat_test.moc" - diff --git a/launcher/minecraft/ParseUtils_test.cpp b/launcher/minecraft/ParseUtils_test.cpp deleted file mode 100644 index 7721a46d..00000000 --- a/launcher/minecraft/ParseUtils_test.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#include "minecraft/ParseUtils.h" - -class ParseUtilsTest : public QObject -{ - Q_OBJECT -private -slots: - void test_Through_data() - { - QTest::addColumn("timestamp"); - const char * timestamps[] = - { - "2016-02-29T13:49:54+01:00", - "2016-02-26T15:21:11+00:01", - "2016-02-24T15:52:36+01:13", - "2016-02-18T17:41:00+00:00", - "2016-02-17T15:23:19+00:00", - "2016-02-16T15:22:39+09:22", - "2016-02-10T15:06:41+00:00", - "2016-02-04T15:28:02-05:33" - }; - for(unsigned i = 0; i < (sizeof(timestamps) / sizeof(const char *)); i++) - { - QTest::newRow(timestamps[i]) << QString(timestamps[i]); - } - } - void test_Through() - { - QFETCH(QString, timestamp); - - auto time_parsed = timeFromS3Time(timestamp); - auto time_serialized = timeToS3Time(time_parsed); - - QCOMPARE(time_serialized, timestamp); - } - -}; - -QTEST_GUILESS_MAIN(ParseUtilsTest) - -#include "ParseUtils_test.moc" diff --git a/launcher/minecraft/mod/ResourceFolderModel_test.cpp b/launcher/minecraft/mod/ResourceFolderModel_test.cpp deleted file mode 100644 index aa78e502..00000000 --- a/launcher/minecraft/mod/ResourceFolderModel_test.cpp +++ /dev/null @@ -1,261 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* -* PolyMC - Minecraft Launcher -* Copyright (C) 2022 Sefa Eyeoglu -* -* This program is free 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, version 3. -* -* This program 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 this program. If not, see . -* -* This file incorporates work covered by the following copyright and -* permission notice: -* -* Copyright 2013-2021 MultiMC Contributors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include -#include - -#include "FileSystem.h" - -#include "minecraft/mod/ModFolderModel.h" -#include "minecraft/mod/ResourceFolderModel.h" - -#define EXEC_UPDATE_TASK(EXEC, VERIFY) \ - QEventLoop loop; \ - \ - connect(&model, &ResourceFolderModel::updateFinished, &loop, &QEventLoop::quit); \ - \ - QTimer expire_timer; \ - expire_timer.callOnTimeout(&loop, &QEventLoop::quit); \ - expire_timer.setSingleShot(true); \ - expire_timer.start(4000); \ - \ - VERIFY(EXEC); \ - loop.exec(); \ - \ - QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished."); \ - expire_timer.stop(); \ - \ - disconnect(&model, nullptr, &loop, nullptr); - -class ResourceFolderModelTest : public QObject -{ - Q_OBJECT - -private -slots: - // test for GH-1178 - install a folder with files to a mod list - void test_1178() - { - // source - QString source = QFINDTESTDATA("testdata/test_folder"); - - // sanity check - QVERIFY(!source.endsWith('/')); - - auto verify = [](QString path) - { - QDir target_dir(FS::PathCombine(path, "test_folder")); - QVERIFY(target_dir.entryList().contains("pack.mcmeta")); - QVERIFY(target_dir.entryList().contains("assets")); - }; - - // 1. test with no trailing / - { - QString folder = source; - QTemporaryDir tempDir; - - QEventLoop loop; - - ModFolderModel m(tempDir.path(), true); - - connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit); - - QTimer expire_timer; - expire_timer.callOnTimeout(&loop, &QEventLoop::quit); - expire_timer.setSingleShot(true); - expire_timer.start(4000); - - m.installMod(folder); - - loop.exec(); - - QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished."); - expire_timer.stop(); - - verify(tempDir.path()); - } - - // 2. test with trailing / - { - QString folder = source + '/'; - QTemporaryDir tempDir; - QEventLoop loop; - ModFolderModel m(tempDir.path(), true); - - connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit); - - QTimer expire_timer; - expire_timer.callOnTimeout(&loop, &QEventLoop::quit); - expire_timer.setSingleShot(true); - expire_timer.start(4000); - - m.installMod(folder); - - loop.exec(); - - QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished."); - expire_timer.stop(); - - verify(tempDir.path()); - } - } - - void test_addFromWatch() - { - QString source = QFINDTESTDATA("testdata"); - - ModFolderModel model(source); - - QCOMPARE(model.size(), 0); - - EXEC_UPDATE_TASK(model.startWatching(), ) - - for (auto mod : model.allMods()) - qDebug() << mod->name(); - - // FIXME: It considers every file in the directory as a mod, but we should probably filter that out somehow. - QCOMPARE(model.size(), 4); - - model.stopWatching(); - } - - void test_removeResource() - { - QString folder_resource = QFINDTESTDATA("testdata/test_folder"); - QString file_mod = QFINDTESTDATA("testdata/supercoolmod.jar"); - - QTemporaryDir tmp; - - ResourceFolderModel model(QDir(tmp.path())); - - QCOMPARE(model.size(), 0); - - { - EXEC_UPDATE_TASK(model.installResource(file_mod), QVERIFY) - } - - QCOMPARE(model.size(), 1); - qDebug() << "Added first mod."; - - { - EXEC_UPDATE_TASK(model.startWatching(), ) - } - - QCOMPARE(model.size(), 1); - qDebug() << "Started watching the temp folder."; - - { - EXEC_UPDATE_TASK(model.installResource(folder_resource), QVERIFY) - } - - QCOMPARE(model.size(), 2); - qDebug() << "Added second mod."; - - { - EXEC_UPDATE_TASK(model.uninstallResource("supercoolmod.jar"), QVERIFY); - } - - QCOMPARE(model.size(), 1); - qDebug() << "Removed first mod."; - - QString mod_file_name {model.at(0).fileinfo().fileName()}; - QVERIFY(!mod_file_name.isEmpty()); - - { - EXEC_UPDATE_TASK(model.uninstallResource(mod_file_name), QVERIFY); - } - - QCOMPARE(model.size(), 0); - qDebug() << "Removed second mod."; - - model.stopWatching(); - } - - void test_enable_disable() - { - QString folder_resource = QFINDTESTDATA("testdata/test_folder"); - QString file_mod = QFINDTESTDATA("testdata/supercoolmod.jar"); - - QTemporaryDir tmp; - ResourceFolderModel model(tmp.path()); - - QCOMPARE(model.size(), 0); - - { - EXEC_UPDATE_TASK(model.installResource(folder_resource), QVERIFY) - } - { - EXEC_UPDATE_TASK(model.installResource(file_mod), QVERIFY) - } - - for (auto res : model.all()) - qDebug() << res->name(); - - QCOMPARE(model.size(), 2); - - auto& res_1 = model.at(0).type() != ResourceType::FOLDER ? model.at(0) : model.at(1); - auto& res_2 = model.at(0).type() == ResourceType::FOLDER ? model.at(0) : model.at(1); - auto id_1 = res_1.internal_id(); - auto id_2 = res_2.internal_id(); - bool initial_enabled_res_2 = res_2.enabled(); - bool initial_enabled_res_1 = res_1.enabled(); - - QVERIFY(res_1.type() != ResourceType::FOLDER && res_1.type() != ResourceType::UNKNOWN); - qDebug() << "res_1 is of the correct type."; - QVERIFY(res_1.enabled()); - qDebug() << "res_1 is initially enabled."; - - QVERIFY(res_1.enable(EnableAction::TOGGLE)); - - QVERIFY(res_1.enabled() == !initial_enabled_res_1); - qDebug() << "res_1 got successfully toggled."; - - QVERIFY(res_1.enable(EnableAction::TOGGLE)); - qDebug() << "res_1 got successfully toggled again."; - - QVERIFY(res_1.enabled() == initial_enabled_res_1); - QVERIFY(res_1.internal_id() == id_1); - qDebug() << "res_1 got back to its initial state."; - - QVERIFY(!res_2.enable(initial_enabled_res_2 ? EnableAction::ENABLE : EnableAction::DISABLE)); - QVERIFY(res_2.enabled() == initial_enabled_res_2); - QVERIFY(res_2.internal_id() == id_2); - } -}; - -QTEST_GUILESS_MAIN(ResourceFolderModelTest) - -#include "ResourceFolderModel_test.moc" diff --git a/launcher/minecraft/mod/ResourcePackParse_test.cpp b/launcher/minecraft/mod/ResourcePackParse_test.cpp deleted file mode 100644 index a49582d6..00000000 --- a/launcher/minecraft/mod/ResourcePackParse_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (c) 2022 flowln - * - * This program is free 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, version 3. - * - * This program 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 this program. If not, see . - */ - -#include -#include - -#include "FileSystem.h" - -#include "ResourcePack.h" -#include "tasks/LocalResourcePackParseTask.h" - -class ResourcePackParseTest : public QObject { - Q_OBJECT - - private slots: - void test_parseZIP() - { - QString source = QFINDTESTDATA("testdata"); - - QString zip_rp = FS::PathCombine(source, "test_resource_pack_idk.zip"); - ResourcePack pack { QFileInfo(zip_rp) }; - - ResourcePackUtils::processZIP(pack); - - QVERIFY(pack.packFormat() == 3); - QVERIFY(pack.description() == "um dois, feijão com arroz, três quatro, feijão no prato, cinco seis, café inglês, sete oito, comer biscoito, nove dez comer pastéis!!"); - } - - void test_parseFolder() - { - QString source = QFINDTESTDATA("testdata"); - - QString folder_rp = FS::PathCombine(source, "test_folder"); - ResourcePack pack { QFileInfo(folder_rp) }; - - ResourcePackUtils::processFolder(pack); - - QVERIFY(pack.packFormat() == 1); - QVERIFY(pack.description() == "Some resource pack maybe"); - } - - void test_parseFolder2() - { - QString source = QFINDTESTDATA("testdata"); - - QString folder_rp = FS::PathCombine(source, "another_test_folder"); - ResourcePack pack { QFileInfo(folder_rp) }; - - ResourcePackUtils::process(pack); - - QVERIFY(pack.packFormat() == 6); - QVERIFY(pack.description() == "o quartel pegou fogo, policia deu sinal, acode acode acode a bandeira nacional"); - } -}; - -QTEST_GUILESS_MAIN(ResourcePackParseTest) - -#include "ResourcePackParse_test.moc" diff --git a/launcher/minecraft/mod/testdata/another_test_folder/pack.mcmeta b/launcher/minecraft/mod/testdata/another_test_folder/pack.mcmeta deleted file mode 100644 index d33a0e5d..00000000 --- a/launcher/minecraft/mod/testdata/another_test_folder/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "pack_format": 6, - "description": "o quartel pegou fogo, policia deu sinal, acode acode acode a bandeira nacional" - } -} diff --git a/launcher/minecraft/mod/testdata/supercoolmod.jar b/launcher/minecraft/mod/testdata/supercoolmod.jar deleted file mode 100644 index d8cf9860..00000000 --- a/launcher/minecraft/mod/testdata/supercoolmod.jar +++ /dev/null @@ -1 +0,0 @@ -the best mod. diff --git a/launcher/minecraft/mod/testdata/test_folder/assets/minecraft/textures/blah.txt b/launcher/minecraft/mod/testdata/test_folder/assets/minecraft/textures/blah.txt deleted file mode 100644 index 8d1c8b69..00000000 --- a/launcher/minecraft/mod/testdata/test_folder/assets/minecraft/textures/blah.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/launcher/minecraft/mod/testdata/test_folder/pack.mcmeta b/launcher/minecraft/mod/testdata/test_folder/pack.mcmeta deleted file mode 100644 index 67ee0434..00000000 --- a/launcher/minecraft/mod/testdata/test_folder/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "pack_format": 1, - "description": "Some resource pack maybe" - } -} diff --git a/launcher/minecraft/mod/testdata/test_folder/pack.nfo b/launcher/minecraft/mod/testdata/test_folder/pack.nfo deleted file mode 100644 index 8d1c8b69..00000000 --- a/launcher/minecraft/mod/testdata/test_folder/pack.nfo +++ /dev/null @@ -1 +0,0 @@ - diff --git a/launcher/minecraft/mod/testdata/test_resource_pack_idk.zip b/launcher/minecraft/mod/testdata/test_resource_pack_idk.zip deleted file mode 100644 index 52b91cdc..00000000 Binary files a/launcher/minecraft/mod/testdata/test_resource_pack_idk.zip and /dev/null differ diff --git a/launcher/minecraft/testdata/1.9-simple.json b/launcher/minecraft/testdata/1.9-simple.json deleted file mode 100644 index 574c5b06..00000000 --- a/launcher/minecraft/testdata/1.9-simple.json +++ /dev/null @@ -1,198 +0,0 @@ -{ - "assets": "1.9", - "id": "1.9", - "libraries": [ - { - "name": "oshi-project:oshi-core:1.1" - }, - { - "name": "net.java.dev.jna:jna:3.4.0" - }, - { - "name": "net.java.dev.jna:platform:3.4.0" - }, - { - "name": "com.ibm.icu:icu4j-core-mojang:51.2" - }, - { - "name": "net.sf.jopt-simple:jopt-simple:4.6" - }, - { - "name": "com.paulscode:codecjorbis:20101023" - }, - { - "name": "com.paulscode:codecwav:20101023" - }, - { - "name": "com.paulscode:libraryjavasound:20101123" - }, - { - "name": "com.paulscode:librarylwjglopenal:20100824" - }, - { - "name": "com.paulscode:soundsystem:20120107" - }, - { - "name": "io.netty:netty-all:4.0.23.Final" - }, - { - "name": "com.google.guava:guava:17.0" - }, - { - "name": "org.apache.commons:commons-lang3:3.3.2" - }, - { - "name": "commons-io:commons-io:2.4" - }, - { - "name": "commons-codec:commons-codec:1.9" - }, - { - "name": "net.java.jinput:jinput:2.0.5" - }, - { - "name": "net.java.jutils:jutils:1.0.0" - }, - { - "name": "com.google.code.gson:gson:2.2.4" - }, - { - "name": "com.mojang:authlib:1.5.22" - }, - { - "name": "com.mojang:realms:1.8.4" - }, - { - "name": "org.apache.commons:commons-compress:1.8.1" - }, - { - "name": "org.apache.httpcomponents:httpclient:4.3.3" - }, - { - "name": "commons-logging:commons-logging:1.1.3" - }, - { - "name": "org.apache.httpcomponents:httpcore:4.3.2" - }, - { - "name": "org.apache.logging.log4j:log4j-api:2.0-beta9" - }, - { - "name": "org.apache.logging.log4j:log4j-core:2.0-beta9" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209", - "rules": [ - { - "action": "allow" - }, - { - "action": "disallow", - "os": { - "name": "osx" - } - } - ] - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209", - "rules": [ - { - "action": "allow" - }, - { - "action": "disallow", - "os": { - "name": "osx" - } - } - ] - }, - { - "extract": { - "exclude": [ - "META-INF/" - ] - }, - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209", - "natives": { - "linux": "natives-linux", - "osx": "natives-osx", - "windows": "natives-windows" - }, - "rules": [ - { - "action": "allow" - }, - { - "action": "disallow", - "os": { - "name": "osx" - } - } - ] - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822", - "rules": [ - { - "action": "allow", - "os": { - "name": "osx" - } - } - ] - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822", - "rules": [ - { - "action": "allow", - "os": { - "name": "osx" - } - } - ] - }, - { - "extract": { - "exclude": [ - "META-INF/" - ] - }, - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822", - "natives": { - "linux": "natives-linux", - "osx": "natives-osx", - "windows": "natives-windows" - }, - "rules": [ - { - "action": "allow", - "os": { - "name": "osx" - } - } - ] - }, - { - "extract": { - "exclude": [ - "META-INF/" - ] - }, - "name": "net.java.jinput:jinput-platform:2.0.5", - "natives": { - "linux": "natives-linux", - "osx": "natives-osx", - "windows": "natives-windows" - } - } - ], - "mainClass": "net.minecraft.client.main.Main", - "minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}", - "minimumLauncherVersion": 18, - "releaseTime": "2016-02-29T13:49:54+00:00", - "time": "2016-03-01T13:14:53+00:00", - "type": "release" -} diff --git a/launcher/minecraft/testdata/1.9.json b/launcher/minecraft/testdata/1.9.json deleted file mode 100644 index 697c6059..00000000 --- a/launcher/minecraft/testdata/1.9.json +++ /dev/null @@ -1,529 +0,0 @@ -{ - "assetIndex": { - "id": "1.9", - "sha1": "cde65b47a43f638653ab1da3848b53f8a7477b16", - "size": 136916, - "totalSize": 119917473, - "url": "https://launchermeta.mojang.com/mc-staging/assets/1.9/cde65b47a43f638653ab1da3848b53f8a7477b16/1.9.json" - }, - "assets": "1.9", - "downloads": { - "client": { - "sha1": "2f67d