aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-19 00:06:44 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-19 00:06:44 +0300
commit319ce8c19f801a4bec920c6778cf140e9f92ee32 (patch)
tree6322b81bf4146ba98b5894ebbb8201a37cc8c044 /tests
parent182e19eae3e2aa9f50dde140d10db858b5bf6076 (diff)
parent12cd8a7bea991c2a8d4b59b1cfc9f7c246819fc9 (diff)
downloadPrismLauncher-319ce8c19f801a4bec920c6778cf140e9f92ee32.tar.gz
PrismLauncher-319ce8c19f801a4bec920c6778cf140e9f92ee32.tar.bz2
PrismLauncher-319ce8c19f801a4bec920c6778cf140e9f92ee32.zip
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into develop
Diffstat (limited to 'tests')
-rw-r--r--tests/INIFile_test.cpp111
1 files changed, 101 insertions, 10 deletions
diff --git a/tests/INIFile_test.cpp b/tests/INIFile_test.cpp
index 2f49e573..95730e24 100644
--- a/tests/INIFile_test.cpp
+++ b/tests/INIFile_test.cpp
@@ -2,7 +2,10 @@
#include <settings/INIFile.h>
#include <QList>
+#include <QSettings>
+#include <QTemporaryFile>
#include <QVariant>
+#include "FileSystem.h"
#include <QVariantUtils.h>
@@ -72,32 +75,120 @@ class IniFileTest : public QObject {
QCOMPARE(out_list_numbers, list_numbers);
}
- void test_SaveAleardyExistingFile()
+ void test_SaveAlreadyExistingFile()
{
- QString fileName = "test_SaveAleardyExistingFile.ini";
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);
-
- if (file.open(QFile::WriteOnly | QFile::Text)) {
- QTextStream stream(&file);
- stream << fileContent;
- file.close();
- }
+ 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("ConfigVersion", "NOT SET").toString(), "1.1");
+ 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
}
};