summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-12-26 02:44:33 +0100
committerPetr Mrázek <peterix@gmail.com>2015-12-26 02:44:33 +0100
commit243c5d1cfbff7ff014fe15e54a73a59dfde25988 (patch)
treeaa271e7b7d2f430830819dd1fd64151c2ea6e985 /tests
parent478ff1148599ce6dd650d310a7bb4140b640cb30 (diff)
downloadMultiMC-243c5d1cfbff7ff014fe15e54a73a59dfde25988.tar
MultiMC-243c5d1cfbff7ff014fe15e54a73a59dfde25988.tar.gz
MultiMC-243c5d1cfbff7ff014fe15e54a73a59dfde25988.tar.lz
MultiMC-243c5d1cfbff7ff014fe15e54a73a59dfde25988.tar.xz
MultiMC-243c5d1cfbff7ff014fe15e54a73a59dfde25988.zip
NOISSUE add a basic test for FS::copy
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/data_raw/test_folder/assets/minecraft/textures/blah.txt1
-rw-r--r--tests/data_raw/test_folder/pack.mcmeta6
-rw-r--r--tests/data_raw/test_folder/pack.nfo1
-rw-r--r--tests/tst_FileSystem.cpp (renamed from tests/tst_pathutils.cpp)61
5 files changed, 64 insertions, 10 deletions
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
index de5234b8..a9406d13 100644
--- a/tests/tst_pathutils.cpp
+++ b/tests/tst_FileSystem.cpp
@@ -1,19 +1,27 @@
#include <QTest>
#include "TestUtil.h"
-#include <FileSystem.h>
-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"