NOISSUE add a basic test for FS::copy
This commit is contained in:
parent
478ff11485
commit
243c5d1cfb
@ -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())
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -0,0 +1 @@
|
||||
|
6
tests/data_raw/test_folder/pack.mcmeta
Normal file
6
tests/data_raw/test_folder/pack.mcmeta
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 1,
|
||||
"description": "Some resource pack maybe"
|
||||
}
|
||||
}
|
1
tests/data_raw/test_folder/pack.nfo
Normal file
1
tests/data_raw/test_folder/pack.nfo
Normal file
@ -0,0 +1 @@
|
||||
|
@ -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"
|
Loading…
Reference in New Issue
Block a user