diff --git a/logic/minecraft/ModList.cpp b/logic/minecraft/ModList.cpp index 07affb720..43499612a 100644 --- a/logic/minecraft/ModList.cpp +++ b/logic/minecraft/ModList.cpp @@ -575,8 +575,8 @@ bool ModList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row if (!url.isLocalFile()) continue; QString filename = url.toLocalFile(); - installMod(filename, row); qDebug() << "installing: " << filename; + installMod(filename, row); // if there is no ordering, re-sort the list if (m_list_file.isEmpty()) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a09eb66a9..15b542e8a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,11 +19,11 @@ endmacro() # Tests START # -add_unit_test(pathutils tst_pathutils.cpp) add_unit_test(gradlespecifier tst_gradlespecifier.cpp) add_unit_test(userutils tst_userutils.cpp) add_unit_test(modutils tst_modutils.cpp) add_unit_test(inifile tst_inifile.cpp) +add_unit_test(FileSystem tst_FileSystem.cpp) add_unit_test(UpdateChecker tst_UpdateChecker.cpp) add_unit_test(DownloadTask tst_DownloadTask.cpp) add_unit_test(filematchers tst_filematchers.cpp) @@ -108,4 +108,7 @@ foreach(data_file ${data_files}) ) endforeach() +file(GLOB raw_data_files "data_raw/*") +file(COPY ${raw_data_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/) + configure_file(test_config.h.in test_config.h @ONLY) diff --git a/tests/data_raw/test_folder/assets/minecraft/textures/blah.txt b/tests/data_raw/test_folder/assets/minecraft/textures/blah.txt new file mode 100644 index 000000000..8d1c8b69c --- /dev/null +++ b/tests/data_raw/test_folder/assets/minecraft/textures/blah.txt @@ -0,0 +1 @@ + diff --git a/tests/data_raw/test_folder/pack.mcmeta b/tests/data_raw/test_folder/pack.mcmeta new file mode 100644 index 000000000..67ee04348 --- /dev/null +++ b/tests/data_raw/test_folder/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 1, + "description": "Some resource pack maybe" + } +} diff --git a/tests/data_raw/test_folder/pack.nfo b/tests/data_raw/test_folder/pack.nfo new file mode 100644 index 000000000..8d1c8b69c --- /dev/null +++ b/tests/data_raw/test_folder/pack.nfo @@ -0,0 +1 @@ + diff --git a/tests/tst_pathutils.cpp b/tests/tst_FileSystem.cpp similarity index 55% rename from tests/tst_pathutils.cpp rename to tests/tst_FileSystem.cpp index de5234b81..a9406d13c 100644 --- a/tests/tst_pathutils.cpp +++ b/tests/tst_FileSystem.cpp @@ -1,19 +1,27 @@ #include #include "TestUtil.h" -#include -class PathUtilsTest : public QObject +#include "FileSystem.h" + +class FileSystemTest : public QObject { Q_OBJECT + + const QString bothSlash = "/foo/"; + const QString trailingSlash = "foo/"; + const QString leadingSlash = "/foo"; + private slots: - void initTestCase() - { - - } - void cleanupTestCase() + 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() @@ -30,6 +38,7 @@ slots: QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl"; #endif } + void test_PathCombine1() { QFETCH(QString, result); @@ -57,6 +66,7 @@ slots: QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl"; #endif } + void test_PathCombine2() { QFETCH(QString, result); @@ -66,8 +76,41 @@ slots: QCOMPARE(FS::PathCombine(path1, path2, path3), result); } + + void test_copy() + { + QString folder = QFINDTESTDATA("tests/data/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(); + } }; -QTEST_GUILESS_MAIN(PathUtilsTest) +QTEST_GUILESS_MAIN(FileSystemTest) -#include "tst_pathutils.moc" +#include "tst_FileSystem.moc"