Changeset View
Changeset View
Standalone View
Standalone View
tests/configsavetest.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * | 2 | * | ||
3 | */ | 3 | */ | ||
4 | #include "configsavetest.h" | 4 | #include "configsavetest.h" | ||
5 | #include <appearancegtk2.h> | 5 | #include <appearancegtk2.h> | ||
6 | #include <appearancegtk3.h> | 6 | #include <appearancegtk3.h> | ||
7 | 7 | | |||
8 | #include <QtTest> | 8 | #include <QtTest> | ||
9 | 9 | | |||
10 | QTEST_GUILESS_MAIN(ConfigSaveTest); | 10 | QTEST_GUILESS_MAIN(ConfigSaveTest); | ||
11 | 11 | | |||
12 | ConfigSaveTest::ConfigSaveTest() | 12 | void ConfigSaveTest::fillValues(AbstractAppearance* a) | ||
13 | { | | |||
14 | QStandardPaths::setTestModeEnabled(true); | | |||
15 | } | | |||
16 | | ||||
17 | static void fillValues(QScopedPointer<AbstractAppearance>& a) | | |||
18 | { | 13 | { | ||
19 | a->setFont("a"); | 14 | a->setFont("a"); | ||
20 | a->setIcon("a"); | 15 | a->setIcon("a"); | ||
21 | a->setTheme("a"); | 16 | a->setTheme("a"); | ||
22 | a->setToolbarStyle("a"); | 17 | a->setToolbarStyle("a"); | ||
23 | a->setIconFallback("a"); | 18 | a->setIconFallback("a"); | ||
24 | a->setCursor("a"); | | |||
25 | a->setShowIconsInButtons(true); | 19 | a->setShowIconsInButtons(true); | ||
26 | a->setShowIconsInMenus(true); | 20 | a->setShowIconsInMenus(true); | ||
27 | a->setPrimaryButtonWarpsSlider(true); | 21 | a->setPrimaryButtonWarpsSlider(true); | ||
28 | 22 | | |||
29 | auto a3 = dynamic_cast<AppearanceGTK3*>(a.data()); | 23 | auto a3 = dynamic_cast<AppearanceGTK3*>(a); | ||
30 | if (a3) { | 24 | if (a3) { | ||
31 | a3->setApplicationPreferDarkTheme(false); | 25 | a3->setApplicationPreferDarkTheme(false); | ||
32 | } | 26 | } | ||
33 | } | 27 | } | ||
34 | 28 | | |||
35 | void compareAppearances(QScopedPointer<AbstractAppearance>& reloaded, QScopedPointer<AbstractAppearance>& instance) | 29 | bool compareAppearances(AbstractAppearance* a, AbstractAppearance* b) | ||
36 | { | 30 | { | ||
37 | QCOMPARE(reloaded->getFont(), instance->getFont()); | 31 | return a->getFont() == b->getFont() | ||
38 | QCOMPARE(reloaded->getIcon(), instance->getIcon()); | 32 | && a->getIcon() == b->getIcon() | ||
39 | QCOMPARE(reloaded->getTheme(), instance->getTheme()); | 33 | && a->getTheme() == b->getTheme() | ||
40 | QCOMPARE(reloaded->getCursor(), instance->getCursor()); | 34 | && a->getToolbarStyle() == b->getToolbarStyle() | ||
41 | QCOMPARE(reloaded->getToolbarStyle(), instance->getToolbarStyle()); | 35 | && a->getIconFallback() == b->getIconFallback() | ||
42 | QCOMPARE(reloaded->getIconFallback(), instance->getIconFallback()); | 36 | && a->getShowIconsInButtons() == b->getShowIconsInButtons() | ||
43 | QCOMPARE(reloaded->getShowIconsInButtons(), instance->getShowIconsInButtons()); | 37 | && a->getShowIconsInMenus() == b->getShowIconsInMenus() | ||
44 | QCOMPARE(reloaded->getShowIconsInMenus(), instance->getShowIconsInMenus()); | 38 | && a->getPrimaryButtonWarpsSlider() == b->getPrimaryButtonWarpsSlider(); | ||
45 | QCOMPARE(reloaded->getPrimaryButtonWarpsSlider(), instance->getPrimaryButtonWarpsSlider()); | | |||
46 | } | 39 | } | ||
47 | 40 | | |||
48 | QByteArray readFile(const QString& path) | 41 | QByteArray readFile(const QString& path) | ||
49 | { | 42 | { | ||
50 | QFile f(path); | 43 | QFile f(path); | ||
51 | if(!f.open(QFile::ReadOnly | QFile::Text)) | 44 | if(!f.open(QFile::ReadOnly | QFile::Text)) | ||
52 | return QByteArray(); | 45 | return QByteArray(); | ||
53 | return f.readAll(); | 46 | return f.readAll(); | ||
54 | } | 47 | } | ||
55 | 48 | | |||
56 | void ConfigSaveTest::testGtk2() | 49 | void ConfigSaveTest::testOpen() | ||
57 | { | | |||
58 | const QString pathA = QDir::current().absoluteFilePath("test-gtk2") | | |||
59 | , pathB = QDir::current().absoluteFilePath("testB-gtk2"); | | |||
60 | | ||||
61 | QScopedPointer<AbstractAppearance> instance(new AppearanceGTK2); | | |||
62 | fillValues(instance); | | |||
63 | QVERIFY(instance->saveSettings(pathA)); | | |||
64 | | ||||
65 | QScopedPointer<AbstractAppearance> reloaded(new AppearanceGTK2); | | |||
66 | QVERIFY(reloaded->loadSettings(pathA)); | | |||
67 | compareAppearances(reloaded, instance); | | |||
68 | QVERIFY(reloaded->saveSettings(pathB)); | | |||
69 | QCOMPARE(readFile(pathA), readFile(pathB)); | | |||
70 | } | | |||
71 | | ||||
72 | void ConfigSaveTest::testGtk3() | | |||
73 | { | 50 | { | ||
74 | QScopedPointer<AbstractAppearance> instance(new AppearanceGTK3); | 51 | QVector<AbstractAppearance*> instances; | ||
75 | fillValues(instance); | 52 | instances << new AppearanceGTK2 << new AppearanceGTK3; | ||
76 | const QString pathA = QDir::current().absoluteFilePath("test-gtk3") | 53 | fillValues(instances[0]); | ||
77 | , pathB = QDir::current().absoluteFilePath("testB-gtk3"); | 54 | fillValues(instances[1]); | ||
78 | QVERIFY(instance->saveSettings(pathA)); | 55 | QVERIFY(instances[0]->saveSettings("test-gtk2")); | ||
79 | 56 | QVERIFY(instances[1]->saveSettings("test-gtk3")); | |||
80 | QScopedPointer<AbstractAppearance> reloaded(new AppearanceGTK3); | 57 | | ||
81 | QVERIFY(QFile::exists(pathA)); | 58 | QVector<AbstractAppearance*> reloaded; | ||
82 | QVERIFY(reloaded->loadSettings(pathA)); | 59 | reloaded << new AppearanceGTK2 << new AppearanceGTK3; | ||
83 | compareAppearances(reloaded, instance); | 60 | QVERIFY(reloaded[0]->loadSettings("test-gtk2")); | ||
84 | QVERIFY(reloaded->saveSettings(pathB)); | 61 | QVERIFY(reloaded[1]->loadSettings("test-gtk3")); | ||
85 | 62 | QVERIFY(compareAppearances(reloaded[0], instances[0])); | |||
86 | QCOMPARE(readFile(pathA), readFile(pathB)); | 63 | QVERIFY(compareAppearances(reloaded[1], instances[1])); | ||
64 | QVERIFY(reloaded[0]->saveSettings("testB-gtk2")); | ||||
65 | QVERIFY(reloaded[1]->saveSettings("testB-gtk3")); | ||||
66 | QCOMPARE(readFile("test-gtk2"), readFile("testB-gtk2")); | ||||
67 | QCOMPARE(readFile("test-gtk3"), readFile("testB-gtk3")); | ||||
87 | } | 68 | } |