2014-03-30 01:46:54 +05:30
|
|
|
#include <QTest>
|
|
|
|
|
2023-02-16 10:31:27 +05:30
|
|
|
#include <QList>
|
|
|
|
#include <QVariant>
|
2022-09-12 01:55:18 +05:30
|
|
|
#include <settings/INIFile.h>
|
2014-03-30 01:46:54 +05:30
|
|
|
|
2023-04-30 06:35:48 +05:30
|
|
|
#include <QVariantUtils.h>
|
2023-02-16 10:31:27 +05:30
|
|
|
|
2014-03-30 01:46:54 +05:30
|
|
|
class IniFileTest : public QObject
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_OBJECT
|
2014-03-30 01:46:54 +05:30
|
|
|
private
|
|
|
|
slots:
|
2018-07-15 18:21:05 +05:30
|
|
|
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 16:48:51 +05:30
|
|
|
QTest::newRow("Hashtags") << "some data#something";
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void test_SaveLoad()
|
|
|
|
{
|
|
|
|
QString a = "a";
|
2019-06-18 16:48:51 +05:30
|
|
|
QString b = "a\nb\t\n\\\\\\C:\\Program files\\terrible\\name\\of something\\#thisIsNotAComment";
|
2018-07-15 18:21:05 +05:30
|
|
|
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 10:31:27 +05:30
|
|
|
QCOMPARE(f2.get("a","NOT SET").toString(), a);
|
|
|
|
QCOMPARE(f2.get("b","NOT SET").toString(), b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_SaveLoadLists()
|
|
|
|
{
|
2023-04-30 06:35:48 +05:30
|
|
|
QString slist_strings = "(\"a\",\"b\",\"c\")";
|
2023-02-16 10:31:27 +05:30
|
|
|
QStringList list_strings = {"a", "b", "c"};
|
|
|
|
|
2023-04-30 06:35:48 +05:30
|
|
|
QString slist_numbers = "(1,2,3,10)";
|
2023-02-16 10:31:27 +05:30
|
|
|
QList<int> list_numbers = {1, 2, 3, 10};
|
|
|
|
|
|
|
|
QString filename = "test_SaveLoadLists.ini";
|
|
|
|
|
|
|
|
INIFile f;
|
2023-04-30 06:35:48 +05:30
|
|
|
f.set("list_strings", list_strings);
|
|
|
|
f.set("list_numbers", QVariantUtils::fromList(list_numbers));
|
2023-02-16 10:31:27 +05:30
|
|
|
f.saveFile(filename);
|
|
|
|
|
|
|
|
// load
|
|
|
|
INIFile f2;
|
|
|
|
f2.loadFile(filename);
|
|
|
|
|
2023-04-30 06:35:48 +05:30
|
|
|
QStringList out_list_strings = f2.get("list_strings", QStringList()).toStringList();
|
2023-02-16 10:31:27 +05:30
|
|
|
qDebug() << "OutStringList" << out_list_strings;
|
|
|
|
|
2023-04-30 06:35:48 +05:30
|
|
|
QList<int> out_list_numbers = QVariantUtils::toList<int>(f2.get("list_numbers", QVariantUtils::fromList(QList<int>())));
|
2023-02-16 10:31:27 +05:30
|
|
|
qDebug() << "OutNumbersList" << out_list_numbers;
|
|
|
|
|
|
|
|
QCOMPARE(out_list_strings, list_strings);
|
|
|
|
QCOMPARE(out_list_numbers, list_numbers);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2014-03-30 01:46:54 +05:30
|
|
|
};
|
|
|
|
|
2015-01-31 23:51:47 +05:30
|
|
|
QTEST_GUILESS_MAIN(IniFileTest)
|
2014-03-30 01:46:54 +05:30
|
|
|
|
2016-04-14 04:53:54 +05:30
|
|
|
#include "INIFile_test.moc"
|