From 0331f5a1eb3e9fa21e89fc7fd56fdd4e87f29e44 Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 30 Aug 2022 14:55:37 -0300 Subject: [PATCH] feat(tests): add tests for resource pack parsing Signed-off-by: flow --- launcher/CMakeLists.txt | 4 + .../mod/ResourceFolderModel_test.cpp | 3 +- .../minecraft/mod/ResourcePackParse_test.cpp | 73 ++++++++++++++++++ .../testdata/another_test_folder/pack.mcmeta | Bin 0 -> 151 bytes .../mod/testdata/test_resource_pack_idk.zip | Bin 0 -> 322 bytes 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 launcher/minecraft/mod/ResourcePackParse_test.cpp create mode 100644 launcher/minecraft/mod/testdata/another_test_folder/pack.mcmeta create mode 100644 launcher/minecraft/mod/testdata/test_resource_pack_idk.zip diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index ef8ec681..234ff454 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -388,6 +388,10 @@ ecm_add_test(minecraft/Library_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VER 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) diff --git a/launcher/minecraft/mod/ResourceFolderModel_test.cpp b/launcher/minecraft/mod/ResourceFolderModel_test.cpp index fe98552e..8fe93c2a 100644 --- a/launcher/minecraft/mod/ResourceFolderModel_test.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel_test.cpp @@ -146,7 +146,8 @@ slots: for (auto mod : model.allMods()) qDebug() << mod->name(); - QCOMPARE(model.size(), 2); + // 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(); diff --git a/launcher/minecraft/mod/ResourcePackParse_test.cpp b/launcher/minecraft/mod/ResourcePackParse_test.cpp new file mode 100644 index 00000000..a49582d6 --- /dev/null +++ b/launcher/minecraft/mod/ResourcePackParse_test.cpp @@ -0,0 +1,73 @@ +// 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 new file mode 100644 index 0000000000000000000000000000000000000000..d33a0e5dba992dbc1066080c0e98a90ae4c79501 GIT binary patch literal 151 zcmY+7u?hk)5JdZf`-dTQY72ix*3I6r7_%{#RN|Le_(}ePdtxID1M?VW-p|*4o`6t^ zFX4!9_{Gy=?MmJ0A?_W=Nj7d;yIOG^47Wk8OGcH|1{PZ_qFPo~LXv?^3*`u6OY-kH TQ%RzYP>6kxa@bEE^W^#fD}OJ< literal 0 HcmV?d00001 diff --git a/launcher/minecraft/mod/testdata/test_resource_pack_idk.zip b/launcher/minecraft/mod/testdata/test_resource_pack_idk.zip new file mode 100644 index 0000000000000000000000000000000000000000..52b91cdcfc6e2dbb0ecb76c5cb33d07b0184487d GIT binary patch literal 322 zcmWIWW@Zs#U|`^2FfNk|z0d8=Jq^e^4aD3GG7JTY$=Q0j$+@W|iJ>8!49pvS`I14n zw1S&~k>w>b0|S_F?K9*%WWeK^uJx5K?^#Yx3|p&-E1M9zb!x`Z%o(Rliwu3bTfVga zpZ|Zl&GxhBQl77W#<2O9t_=I57hRk7#wN-iF@DxGMP!ztlfQ;oTf_8UN*_cH8eUFW zSWwG-$31+;zgCwCH$_$DCaX{QFt^(L3ai1~{9PNlycrH{bu~1Y6Yyu6ur1S<#9y+T zCI^X6S!ev~{^r~e`2cT5COKwYo|6E2k%55`h?g{iSSVg)g?JUsn*rXeY#^nKKo|(5 IZ-Y1t0BR&