aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/INIFile_test.cpp56
-rw-r--r--tests/ResourceFolderModel_test.cpp17
-rw-r--r--tests/ResourceModel_test.cpp6
-rw-r--r--tests/Task_test.cpp9
4 files changed, 51 insertions, 37 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)
diff --git a/tests/ResourceFolderModel_test.cpp b/tests/ResourceFolderModel_test.cpp
index 054d81c4..962d89f1 100644
--- a/tests/ResourceFolderModel_test.cpp
+++ b/tests/ResourceFolderModel_test.cpp
@@ -90,9 +90,7 @@ slots:
QEventLoop loop;
- InstancePtr instance;
-
- ModFolderModel m(tempDir.path(), instance, true);
+ ModFolderModel m(tempDir.path(), nullptr, true);
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
@@ -116,8 +114,7 @@ slots:
QString folder = source + '/';
QTemporaryDir tempDir;
QEventLoop loop;
- InstancePtr instance;
- ModFolderModel m(tempDir.path(), instance, true);
+ ModFolderModel m(tempDir.path(), nullptr, true);
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
@@ -140,8 +137,7 @@ slots:
void test_addFromWatch()
{
QString source = QFINDTESTDATA("testdata/ResourceFolderModel");
- InstancePtr instance;
- ModFolderModel model(source, instance);
+ ModFolderModel model(source, nullptr);
QCOMPARE(model.size(), 0);
@@ -161,9 +157,7 @@ slots:
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
QTemporaryDir tmp;
- InstancePtr instance;
-
- ResourceFolderModel model(QDir(tmp.path()), instance);
+ ResourceFolderModel model(QDir(tmp.path()), nullptr);
QCOMPARE(model.size(), 0);
@@ -214,8 +208,7 @@ slots:
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
QTemporaryDir tmp;
- InstancePtr instance;
- ResourceFolderModel model(tmp.path(), instance);
+ ResourceFolderModel model(tmp.path(), nullptr);
QCOMPARE(model.size(), 0);
diff --git a/tests/ResourceModel_test.cpp b/tests/ResourceModel_test.cpp
index 716bf853..c0d9cd95 100644
--- a/tests/ResourceModel_test.cpp
+++ b/tests/ResourceModel_test.cpp
@@ -75,9 +75,9 @@ class ResourceModelTest : public QObject {
auto search_json = DummyResourceAPI::searchRequestResult();
auto processed_response = model->documentToArray(search_json).first().toObject();
- QVERIFY(processed_pack.addonId.toString() == Json::requireString(processed_response, "project_id"));
- QVERIFY(processed_pack.description == Json::requireString(processed_response, "description"));
- QVERIFY(processed_pack.authors.first().name == Json::requireString(processed_response, "author"));
+ QVERIFY(processed_pack->addonId.toString() == Json::requireString(processed_response, "project_id"));
+ QVERIFY(processed_pack->description == Json::requireString(processed_response, "description"));
+ QVERIFY(processed_pack->authors.first().name == Json::requireString(processed_response, "author"));
}
};
diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp
index 95eb4a30..dabe5da2 100644
--- a/tests/Task_test.cpp
+++ b/tests/Task_test.cpp
@@ -69,8 +69,9 @@ class BigConcurrentTaskThread : public QThread {
auto sub_tasks = new BasicTask::Ptr[s_num_tasks];
for (unsigned i = 0; i < s_num_tasks; i++) {
- sub_tasks[i] = makeShared<BasicTask>(false);
- big_task.addTask(sub_tasks[i]);
+ auto sub_task = makeShared<BasicTask>(false);
+ sub_tasks[i] = sub_task;
+ big_task.addTask(sub_task);
}
big_task.run();
@@ -99,7 +100,7 @@ class TaskTest : public QObject {
t.setStatus(status);
QCOMPARE(t.getStatus(), status);
- QCOMPARE(t.getStepStatus(), status);
+ QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
}
void test_SetStatus_MultiStep(){
@@ -111,7 +112,7 @@ class TaskTest : public QObject {
QCOMPARE(t.getStatus(), status);
// Even though it is multi step, it does not override the getStepStatus method,
// so it should remain the same.
- QCOMPARE(t.getStepStatus(), status);
+ QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
}
void test_SetProgress(){