aboutsummaryrefslogtreecommitdiff
path: root/tests/INIFile_test.cpp
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-13 21:07:05 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-13 21:07:05 +0300
commitb77fb059083ba04a3ccbc1b6e9ce4f5353b200ad (patch)
treeed10137727c1fa29b493cb4fecb0f2f59ccbac8a /tests/INIFile_test.cpp
parent703f7698c1f7b2ae7f6d1db4e9a5aa30b859afbd (diff)
downloadPrismLauncher-b77fb059083ba04a3ccbc1b6e9ce4f5353b200ad.tar.gz
PrismLauncher-b77fb059083ba04a3ccbc1b6e9ce4f5353b200ad.tar.bz2
PrismLauncher-b77fb059083ba04a3ccbc1b6e9ce4f5353b200ad.zip
Added back the INIFile read function
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
Diffstat (limited to 'tests/INIFile_test.cpp')
-rw-r--r--tests/INIFile_test.cpp56
1 files changed, 38 insertions, 18 deletions
diff --git a/tests/INIFile_test.cpp b/tests/INIFile_test.cpp
index 4be8133c..2f49e573 100644
--- a/tests/INIFile_test.cpp
+++ b/tests/INIFile_test.cpp
@@ -1,24 +1,16 @@
#include <QTest>
+#include <settings/INIFile.h>
#include <QList>
#include <QVariant>
-#include <settings/INIFile.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 +39,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 +64,41 @@ 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_SaveAleardyExistingFile()
+ {
+ 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
+)";
+ QFile file(fileName);
+
+ if (file.open(QFile::WriteOnly | QFile::Text)) {
+ 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");
+ 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");
+ }
};
QTEST_GUILESS_MAIN(IniFileTest)