File: configtest.cpp

package info (click to toggle)
kshutdown 6.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,992 kB
  • sloc: cpp: 8,349; sh: 477; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download
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

#include "config.h"

#include <QTemporaryFile>
#include <QTest>

class ConfigTest: public QObject {
	Q_OBJECT
private slots:
	void initTestCase();
	void cleanupTestCase();

	void desktopEntryTest();
};

// private slots:

void ConfigTest::initTestCase() {
	Config::init();
}

void ConfigTest::cleanupTestCase() {
	Config::shutDown();
}

void ConfigTest::desktopEntryTest() {
	QString expectedExec = "test-exec";
	QString expectedKeywords = "test-keywords";

	QTemporaryFile desktopEntryFile(QApplication::applicationDirPath() + "/configtest-XXXXXX.desktop");
	desktopEntryFile.open();

	UPath desktopEntryPath = desktopEntryFile.fileName().toStdString();

	std::shared_ptr<QSettings> writer(Config::createDesktopEntry(desktopEntryPath));
	writer->setValue("Exec", expectedExec);
	writer->setValue("Keywords", expectedKeywords);
	writer->endGroup();

	writer->beginGroup("X-Test Group");
	writer->setValue("Foo", "Bar");
	writer->setValue("Unicode", "Żółw");
	writer->endGroup();

	writer->sync();

	std::shared_ptr<QSettings> reader(Config::openDesktopEntry(desktopEntryPath));
	QCOMPARE(reader->value("Exec", ""), expectedExec);
	QCOMPARE(reader->value("Keywords", ""), expectedKeywords);
	reader->endGroup();

	reader->beginGroup("X-Test Group");
	QCOMPARE(reader->value("Foo", ""), "Bar");
	QCOMPARE(reader->value("Unicode", ""), "Żółw");
	reader->endGroup();
}

QTEST_MAIN(ConfigTest)
#include "configtest.moc"