summaryrefslogtreecommitdiffstats
path: root/api/logic/settings/INIFile_test.cpp
blob: b3ae7375a65ae78f8c13e7c72adf1b5f32e210b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <QTest>
#include "TestUtil.h"

#include "settings/INIFile.h"

class IniFileTest : public QObject
{
	Q_OBJECT
private
slots:
	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\"";
	}
	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";
		QString b = "a\nb\t\n\\\\\\C:\\Program files\\terrible\\name\\of something\\";
		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);
		QCOMPARE(a, f2.get("a","NOT SET").toString());
		QCOMPARE(b, f2.get("b","NOT SET").toString());
	}
};

QTEST_GUILESS_MAIN(IniFileTest)

#include "INIFile_test.moc"