Merge branch 'develop' into chore/add-compiler-warnings
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
@ -9,9 +9,6 @@ ecm_add_test(GZip_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::
|
||||
ecm_add_test(GradleSpecifier_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME GradleSpecifier)
|
||||
|
||||
ecm_add_test(PackageManifest_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME PackageManifest)
|
||||
|
||||
ecm_add_test(MojangVersionFormat_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME MojangVersionFormat)
|
||||
|
||||
|
@ -1,24 +1,19 @@
|
||||
#include <QTest>
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <settings/INIFile.h>
|
||||
#include <QList>
|
||||
#include <QSettings>
|
||||
#include <QTemporaryFile>
|
||||
#include <QVariant>
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include <QVariantUtils.h>
|
||||
|
||||
class IniFileTest : public QObject
|
||||
{
|
||||
class IniFileTest : public QObject {
|
||||
Q_OBJECT
|
||||
private
|
||||
slots:
|
||||
void initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
void cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
private slots:
|
||||
void initTestCase() {}
|
||||
void cleanupTestCase() {}
|
||||
|
||||
void test_Escape_data()
|
||||
{
|
||||
@ -47,17 +42,17 @@ slots:
|
||||
// load
|
||||
INIFile f2;
|
||||
f2.loadFile(filename);
|
||||
QCOMPARE(f2.get("a","NOT SET").toString(), a);
|
||||
QCOMPARE(f2.get("b","NOT SET").toString(), b);
|
||||
QCOMPARE(f2.get("a", "NOT SET").toString(), a);
|
||||
QCOMPARE(f2.get("b", "NOT SET").toString(), b);
|
||||
}
|
||||
|
||||
void test_SaveLoadLists()
|
||||
{
|
||||
QString slist_strings = "(\"a\",\"b\",\"c\")";
|
||||
QStringList list_strings = {"a", "b", "c"};
|
||||
QStringList list_strings = { "a", "b", "c" };
|
||||
|
||||
QString slist_numbers = "(1,2,3,10)";
|
||||
QList<int> list_numbers = {1, 2, 3, 10};
|
||||
QList<int> list_numbers = { 1, 2, 3, 10 };
|
||||
|
||||
QString filename = "test_SaveLoadLists.ini";
|
||||
|
||||
@ -72,13 +67,129 @@ slots:
|
||||
|
||||
QStringList out_list_strings = f2.get("list_strings", QStringList()).toStringList();
|
||||
qDebug() << "OutStringList" << out_list_strings;
|
||||
|
||||
|
||||
QList<int> out_list_numbers = QVariantUtils::toList<int>(f2.get("list_numbers", QVariantUtils::fromList(QList<int>())));
|
||||
qDebug() << "OutNumbersList" << out_list_numbers;
|
||||
|
||||
QCOMPARE(out_list_strings, list_strings);
|
||||
QCOMPARE(out_list_numbers, list_numbers);
|
||||
}
|
||||
|
||||
void test_SaveAlreadyExistingFile()
|
||||
{
|
||||
QString fileContent = R"(InstanceType=OneSix
|
||||
iconKey=vanillia_icon
|
||||
name=Minecraft Vanillia
|
||||
OverrideCommands=true
|
||||
PreLaunchCommand="$INST_JAVA" -jar packwiz-installer-bootstrap.jar link
|
||||
Wrapperommand=)";
|
||||
fileContent += "\"";
|
||||
fileContent += +R"(\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =)";
|
||||
fileContent += "\"\n";
|
||||
#if defined(Q_OS_WIN)
|
||||
QString fileName = "test_SaveAlreadyExistingFile.ini";
|
||||
QFile file(fileName);
|
||||
QCOMPARE(file.open(QFile::WriteOnly | QFile::Text), true);
|
||||
#else
|
||||
QTemporaryFile file;
|
||||
QCOMPARE(file.open(), true);
|
||||
QCOMPARE(file.fileName().isEmpty(), false);
|
||||
QString fileName = file.fileName();
|
||||
#endif
|
||||
QTextStream stream(&file);
|
||||
stream << fileContent;
|
||||
file.close();
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
QCOMPARE(f1.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
QCOMPARE(f1.get("Wrapperommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =");
|
||||
f1.saveFile(fileName);
|
||||
INIFile f2;
|
||||
f2.loadFile(fileName);
|
||||
QCOMPARE(f2.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
QCOMPARE(f2.get("Wrapperommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =");
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
#if defined(Q_OS_WIN)
|
||||
FS::deletePath(fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_SaveAlreadyExistingFileWithSpecialChars()
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
QString fileName = "test_SaveAlreadyExistingFileWithSpecialChars.ini";
|
||||
#else
|
||||
QTemporaryFile file;
|
||||
QCOMPARE(file.open(), true);
|
||||
QCOMPARE(file.fileName().isEmpty(), false);
|
||||
QString fileName = file.fileName();
|
||||
file.close();
|
||||
#endif
|
||||
QSettings settings{ fileName, QSettings::Format::IniFormat };
|
||||
settings.setFallbacksEnabled(false);
|
||||
|
||||
settings.setValue("simple", "value1");
|
||||
settings.setValue("withQuotes", R"("value2" with quotes)");
|
||||
settings.setValue("withSpecialCharacters", "env mesa=true");
|
||||
settings.setValue("withSpecialCharacters2", "1,2,3,4");
|
||||
settings.setValue("withSpecialCharacters2", "1;2;3;4");
|
||||
settings.setValue("withAll", "val=\"$INST_JAVA\" -jar; ls ");
|
||||
|
||||
settings.sync();
|
||||
|
||||
QCOMPARE(settings.status(), QSettings::Status::NoError);
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
for (auto key : settings.allKeys())
|
||||
QCOMPARE(f1.get(key, "NOT SET").toString(), settings.value(key).toString());
|
||||
f1.saveFile(fileName);
|
||||
INIFile f2;
|
||||
f2.loadFile(fileName);
|
||||
for (auto key : settings.allKeys())
|
||||
QCOMPARE(f2.get(key, "NOT SET").toString(), settings.value(key).toString());
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
#if defined(Q_OS_WIN)
|
||||
FS::deletePath(fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_SaveAlreadyExistingFileWithSpecialCharsV1()
|
||||
{
|
||||
QString fileContent = R"(InstanceType=OneSix
|
||||
ConfigVersion=1.1
|
||||
iconKey=vanillia_icon
|
||||
name=Minecraft Vanillia
|
||||
OverrideCommands=true
|
||||
PreLaunchCommand=)";
|
||||
fileContent += "\"\\\"env mesa=true\\\"\"\n";
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
QString fileName = "test_SaveAlreadyExistingFileWithSpecialCharsV1.ini";
|
||||
QFile file(fileName);
|
||||
QCOMPARE(file.open(QFile::WriteOnly | QFile::Text), true);
|
||||
#else
|
||||
QTemporaryFile file;
|
||||
QCOMPARE(file.open(), true);
|
||||
QCOMPARE(file.fileName().isEmpty(), false);
|
||||
QString fileName = file.fileName();
|
||||
#endif
|
||||
QTextStream stream(&file);
|
||||
stream << fileContent;
|
||||
file.close();
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
QCOMPARE(f1.get("PreLaunchCommand", "NOT SET").toString(), "env mesa=true");
|
||||
QCOMPARE(f1.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
#if defined(Q_OS_WIN)
|
||||
FS::deletePath(fileName);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(IniFileTest)
|
||||
|
@ -1,343 +0,0 @@
|
||||
#include <QTest>
|
||||
#include <QDebug>
|
||||
|
||||
#include <mojang/PackageManifest.h>
|
||||
|
||||
using namespace mojang_files;
|
||||
|
||||
QDebug operator<<(QDebug debug, const Path &path)
|
||||
{
|
||||
debug << path.toString();
|
||||
return debug;
|
||||
}
|
||||
|
||||
class PackageManifestTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void test_parse();
|
||||
void test_parse_file();
|
||||
void test_inspect();
|
||||
#ifndef Q_OS_WIN32
|
||||
void test_inspect_symlinks();
|
||||
#endif
|
||||
void mkdir_deep();
|
||||
void rmdir_deep();
|
||||
|
||||
void identical_file();
|
||||
void changed_file();
|
||||
void added_file();
|
||||
void removed_file();
|
||||
};
|
||||
|
||||
namespace {
|
||||
QByteArray basic_manifest = R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b.txt": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/b.txt",
|
||||
"sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||
"size": 0
|
||||
}
|
||||
},
|
||||
"executable": true
|
||||
},
|
||||
"a/b/c": {
|
||||
"type": "directory"
|
||||
},
|
||||
"a/b/c.txt": {
|
||||
"type": "link",
|
||||
"target": "../b.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
)END";
|
||||
}
|
||||
|
||||
void PackageManifestTest::test_parse()
|
||||
{
|
||||
auto manifest = Package::fromManifestContents(basic_manifest);
|
||||
QVERIFY(manifest.valid == true);
|
||||
QVERIFY(manifest.files.size() == 1);
|
||||
QVERIFY(manifest.files.count(Path("a/b.txt")));
|
||||
auto &file = manifest.files[Path("a/b.txt")];
|
||||
QVERIFY(file.executable == true);
|
||||
QVERIFY(file.hash == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
QVERIFY(file.size == 0);
|
||||
QVERIFY(manifest.folders.size() == 4);
|
||||
QVERIFY(manifest.folders.count(Path(".")));
|
||||
QVERIFY(manifest.folders.count(Path("a")));
|
||||
QVERIFY(manifest.folders.count(Path("a/b")));
|
||||
QVERIFY(manifest.folders.count(Path("a/b/c")));
|
||||
QVERIFY(manifest.symlinks.size() == 1);
|
||||
auto symlinkPath = Path("a/b/c.txt");
|
||||
QVERIFY(manifest.symlinks.count(symlinkPath));
|
||||
auto &symlink = manifest.symlinks[symlinkPath];
|
||||
QVERIFY(symlink == Path("../b.txt"));
|
||||
QVERIFY(manifest.sources.size() == 1);
|
||||
}
|
||||
|
||||
void PackageManifestTest::test_parse_file() {
|
||||
auto path = QFINDTESTDATA("testdata/PackageManifest/1.8.0_202-x64.json");
|
||||
auto manifest = Package::fromManifestFile(path);
|
||||
QVERIFY(manifest.valid == true);
|
||||
}
|
||||
|
||||
|
||||
void PackageManifestTest::test_inspect() {
|
||||
auto path = QFINDTESTDATA("testdata/PackageManifest/inspect_win/");
|
||||
auto manifest = Package::fromInspectedFolder(path);
|
||||
QVERIFY(manifest.valid == true);
|
||||
QVERIFY(manifest.files.size() == 2);
|
||||
QVERIFY(manifest.files.count(Path("a/b.txt")));
|
||||
auto &file1 = manifest.files[Path("a/b.txt")];
|
||||
QVERIFY(file1.executable == false);
|
||||
QVERIFY(file1.hash == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
QVERIFY(file1.size == 0);
|
||||
QVERIFY(manifest.files.count(Path("a/b/b.txt")));
|
||||
auto &file2 = manifest.files[Path("a/b/b.txt")];
|
||||
QVERIFY(file2.executable == false);
|
||||
QVERIFY(file2.hash == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
QVERIFY(file2.size == 0);
|
||||
QVERIFY(manifest.folders.size() == 3);
|
||||
QVERIFY(manifest.folders.count(Path(".")));
|
||||
QVERIFY(manifest.folders.count(Path("a")));
|
||||
QVERIFY(manifest.folders.count(Path("a/b")));
|
||||
QVERIFY(manifest.symlinks.size() == 0);
|
||||
}
|
||||
|
||||
#ifndef Q_OS_WIN32
|
||||
void PackageManifestTest::test_inspect_symlinks() {
|
||||
auto path = QFINDTESTDATA("testdata/PackageManifest/inspect/");
|
||||
auto manifest = Package::fromInspectedFolder(path);
|
||||
QVERIFY(manifest.valid == true);
|
||||
QVERIFY(manifest.files.size() == 1);
|
||||
QVERIFY(manifest.files.count(Path("a/b.txt")));
|
||||
auto &file = manifest.files[Path("a/b.txt")];
|
||||
QVERIFY(file.executable == true);
|
||||
QVERIFY(file.hash == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
QVERIFY(file.size == 0);
|
||||
QVERIFY(manifest.folders.size() == 3);
|
||||
QVERIFY(manifest.folders.count(Path(".")));
|
||||
QVERIFY(manifest.folders.count(Path("a")));
|
||||
QVERIFY(manifest.folders.count(Path("a/b")));
|
||||
QVERIFY(manifest.symlinks.size() == 1);
|
||||
QVERIFY(manifest.symlinks.count(Path("a/b/b.txt")));
|
||||
qDebug() << manifest.symlinks[Path("a/b/b.txt")];
|
||||
QVERIFY(manifest.symlinks[Path("a/b/b.txt")] == Path("../b.txt"));
|
||||
}
|
||||
#endif
|
||||
|
||||
void PackageManifestTest::mkdir_deep() {
|
||||
|
||||
Package from;
|
||||
auto to = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/e": {
|
||||
"type": "directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 0);
|
||||
QVERIFY(operations.rmdirs.size() == 0);
|
||||
|
||||
QVERIFY(operations.mkdirs.size() == 6);
|
||||
QVERIFY(operations.mkdirs[0] == Path("."));
|
||||
QVERIFY(operations.mkdirs[1] == Path("a"));
|
||||
QVERIFY(operations.mkdirs[2] == Path("a/b"));
|
||||
QVERIFY(operations.mkdirs[3] == Path("a/b/c"));
|
||||
QVERIFY(operations.mkdirs[4] == Path("a/b/c/d"));
|
||||
QVERIFY(operations.mkdirs[5] == Path("a/b/c/d/e"));
|
||||
|
||||
QVERIFY(operations.downloads.size() == 0);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
void PackageManifestTest::rmdir_deep() {
|
||||
|
||||
Package to;
|
||||
auto from = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/e": {
|
||||
"type": "directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 0);
|
||||
|
||||
QVERIFY(operations.rmdirs.size() == 6);
|
||||
QVERIFY(operations.rmdirs[0] == Path("a/b/c/d/e"));
|
||||
QVERIFY(operations.rmdirs[1] == Path("a/b/c/d"));
|
||||
QVERIFY(operations.rmdirs[2] == Path("a/b/c"));
|
||||
QVERIFY(operations.rmdirs[3] == Path("a/b"));
|
||||
QVERIFY(operations.rmdirs[4] == Path("a"));
|
||||
QVERIFY(operations.rmdirs[5] == Path("."));
|
||||
|
||||
QVERIFY(operations.mkdirs.size() == 0);
|
||||
QVERIFY(operations.downloads.size() == 0);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
void PackageManifestTest::identical_file() {
|
||||
QByteArray manifest = R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/empty.txt": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/empty.txt",
|
||||
"sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||
"size": 0
|
||||
}
|
||||
},
|
||||
"executable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
)END";
|
||||
auto from = Package::fromManifestContents(manifest);
|
||||
auto to = Package::fromManifestContents(manifest);
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 0);
|
||||
QVERIFY(operations.rmdirs.size() == 0);
|
||||
QVERIFY(operations.mkdirs.size() == 0);
|
||||
QVERIFY(operations.downloads.size() == 0);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
void PackageManifestTest::changed_file() {
|
||||
auto from = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/file": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/empty.txt",
|
||||
"sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||
"size": 0
|
||||
}
|
||||
},
|
||||
"executable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto to = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/file": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/space.txt",
|
||||
"sha1": "dd122581c8cd44d0227f9c305581ffcb4b6f1b46",
|
||||
"size": 1
|
||||
}
|
||||
},
|
||||
"executable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 1);
|
||||
QCOMPARE(operations.deletes[0], Path("a/b/c/d/file"));
|
||||
QVERIFY(operations.rmdirs.size() == 0);
|
||||
QVERIFY(operations.mkdirs.size() == 0);
|
||||
QVERIFY(operations.downloads.size() == 1);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
void PackageManifestTest::added_file() {
|
||||
auto from = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d": {
|
||||
"type": "directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto to = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/file": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/space.txt",
|
||||
"sha1": "dd122581c8cd44d0227f9c305581ffcb4b6f1b46",
|
||||
"size": 1
|
||||
}
|
||||
},
|
||||
"executable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 0);
|
||||
QVERIFY(operations.rmdirs.size() == 0);
|
||||
QVERIFY(operations.mkdirs.size() == 0);
|
||||
QVERIFY(operations.downloads.size() == 1);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
void PackageManifestTest::removed_file() {
|
||||
auto from = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d/file": {
|
||||
"type": "file",
|
||||
"downloads": {
|
||||
"raw": {
|
||||
"url": "http://dethware.org/space.txt",
|
||||
"sha1": "dd122581c8cd44d0227f9c305581ffcb4b6f1b46",
|
||||
"size": 1
|
||||
}
|
||||
},
|
||||
"executable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto to = Package::fromManifestContents(R"END(
|
||||
{
|
||||
"files": {
|
||||
"a/b/c/d": {
|
||||
"type": "directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
)END");
|
||||
auto operations = UpdateOperations::resolve(from, to);
|
||||
QVERIFY(operations.deletes.size() == 1);
|
||||
QCOMPARE(operations.deletes[0], Path("a/b/c/d/file"));
|
||||
QVERIFY(operations.rmdirs.size() == 0);
|
||||
QVERIFY(operations.mkdirs.size() == 0);
|
||||
QVERIFY(operations.downloads.size() == 0);
|
||||
QVERIFY(operations.mklinks.size() == 0);
|
||||
QVERIFY(operations.executable_fixes.size() == 0);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(PackageManifestTest)
|
||||
|
||||
#include "PackageManifest_test.moc"
|
||||
|
Reference in New Issue
Block a user