From 243c5d1cfbff7ff014fe15e54a73a59dfde25988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 26 Dec 2015 02:44:33 +0100 Subject: [PATCH] NOISSUE add a basic test for FS::copy --- logic/minecraft/ModList.cpp | 2 +- tests/CMakeLists.txt | 5 +- .../assets/minecraft/textures/blah.txt | 1 + tests/data_raw/test_folder/pack.mcmeta | 6 ++ tests/data_raw/test_folder/pack.nfo | 1 + .../{tst_pathutils.cpp => tst_FileSystem.cpp} | 61 ++++++++++++++++--- 6 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 tests/data_raw/test_folder/assets/minecraft/textures/blah.txt create mode 100644 tests/data_raw/test_folder/pack.mcmeta create mode 100644 tests/data_raw/test_folder/pack.nfo rename tests/{tst_pathutils.cpp => tst_FileSystem.cpp} (55%) diff --git a/logic/minecraft/ModList.cpp b/logic/minecraft/ModList.cpp index 07affb72..43499612 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 a09eb66a..15b542e8 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 00000000..8d1c8b69 --- /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 00000000..67ee0434 --- /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 00000000..8d1c8b69 --- /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 de5234b8..a9406d13 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"