2014-03-29 20:16:54 +00:00
|
|
|
#include <QTest>
|
|
|
|
|
2023-02-16 05:01:27 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QVariant>
|
2022-09-11 21:25:18 +01:00
|
|
|
#include <settings/INIFile.h>
|
2014-03-29 20:16:54 +00:00
|
|
|
|
2023-02-16 05:01:27 +00:00
|
|
|
|
2014-03-29 20:16:54 +00:00
|
|
|
class IniFileTest : public QObject
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_OBJECT
|
2014-03-29 20:16:54 +00:00
|
|
|
private
|
|
|
|
slots:
|
2018-07-15 13:51:05 +01:00
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void cleanupTestCase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_Escape_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("through");
|
|
|
|
|
|
|
|
QTest::newRow("unix path") << "/abc/def/ghi/jkl";
|
|
|
|
QTest::newRow("windows path") << "C:\\Program files\\terrible\\name\\of something\\";
|
|
|
|
QTest::newRow("Plain text") << "Lorem ipsum dolor sit amet.";
|
|
|
|
QTest::newRow("Escape sequences") << "Lorem\n\t\n\\n\\tAAZ\nipsum dolor\n\nsit amet.";
|
|
|
|
QTest::newRow("Escape sequences 2") << "\"\n\n\"";
|
2019-06-18 12:18:51 +01:00
|
|
|
QTest::newRow("Hashtags") << "some data#something";
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
void test_Escape()
|
|
|
|
{
|
|
|
|
QFETCH(QString, through);
|
|
|
|
|
|
|
|
QString there = INIFile::escape(through);
|
|
|
|
QString back = INIFile::unescape(there);
|
|
|
|
|
|
|
|
QCOMPARE(back, through);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_SaveLoad()
|
|
|
|
{
|
|
|
|
QString a = "a";
|
2019-06-18 12:18:51 +01:00
|
|
|
QString b = "a\nb\t\n\\\\\\C:\\Program files\\terrible\\name\\of something\\#thisIsNotAComment";
|
2018-07-15 13:51:05 +01:00
|
|
|
QString filename = "test_SaveLoad.ini";
|
|
|
|
|
|
|
|
// save
|
|
|
|
INIFile f;
|
|
|
|
f.set("a", a);
|
|
|
|
f.set("b", b);
|
|
|
|
f.saveFile(filename);
|
|
|
|
|
|
|
|
// load
|
|
|
|
INIFile f2;
|
|
|
|
f2.loadFile(filename);
|
2023-02-16 05:01:27 +00:00
|
|
|
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"};
|
|
|
|
|
|
|
|
QString slist_numbers = "[1,2,3,10]";
|
|
|
|
QList<int> list_numbers = {1, 2, 3, 10};
|
|
|
|
|
|
|
|
QString filename = "test_SaveLoadLists.ini";
|
|
|
|
|
|
|
|
INIFile f;
|
|
|
|
f.setList("list_strings", list_strings);
|
|
|
|
f.setList("list_numbers", list_numbers);
|
|
|
|
f.saveFile(filename);
|
|
|
|
|
|
|
|
// load
|
|
|
|
INIFile f2;
|
|
|
|
f2.loadFile(filename);
|
|
|
|
|
|
|
|
QStringList out_list_strings = f2.getList<QString>("list_strings", QStringList());
|
|
|
|
qDebug() << "OutStringList" << out_list_strings;
|
|
|
|
|
|
|
|
QList<int> out_list_numbers = f2.getList<int>("list_numbers", QList<int>());
|
|
|
|
qDebug() << "OutNumbersList" << out_list_numbers;
|
|
|
|
|
|
|
|
QCOMPARE(f2.get("list_strings","NOT SET").toString(), slist_strings);
|
|
|
|
QCOMPARE(out_list_strings, list_strings);
|
|
|
|
QCOMPARE(f2.get("list_numbers","NOT SET").toString(), slist_numbers);
|
|
|
|
QCOMPARE(out_list_numbers, list_numbers);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2014-03-29 20:16:54 +00:00
|
|
|
};
|
|
|
|
|
2015-01-31 18:21:47 +00:00
|
|
|
QTEST_GUILESS_MAIN(IniFileTest)
|
2014-03-29 20:16:54 +00:00
|
|
|
|
2016-04-14 00:23:54 +01:00
|
|
|
#include "INIFile_test.moc"
|