summaryrefslogtreecommitdiffstats
path: root/tests/testqPrefDisplay.cpp
blob: 0f534c0dabaaa13db2ad15efd915947d7dd53fee (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// SPDX-License-Identifier: GPL-2.0
#include "testqPrefDisplay.h"

#include "core/pref.h"
#include "core/qthelper.h"
#include "core/settings/qPref.h"

#include <QDate>
#include <QTest>

void TestQPrefDisplay::initTestCase()
{
	QCoreApplication::setOrganizationName("Subsurface");
	QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
	QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay");
}

void TestQPrefDisplay::test_struct_get()
{
	// Test struct pref -> get func.

	auto display = qPrefDisplay::instance();

	prefs.display_invalid_dives = true;
	prefs.divelist_font = copy_qstring("comic");
	prefs.font_size = 12.0;
	prefs.show_developer = false;
	prefs.theme = copy_qstring("myTheme");

	QCOMPARE(display->display_invalid_dives(), prefs.display_invalid_dives);
	QCOMPARE(display->divelist_font(), QString(prefs.divelist_font));
	QCOMPARE(display->font_size(), prefs.font_size);
	QCOMPARE(display->show_developer(), prefs.show_developer);
	QCOMPARE(display->theme(), QString(prefs.theme));
}

void TestQPrefDisplay::test_set_struct()
{
	// Test set func -> struct pref

	auto display = qPrefDisplay::instance();

	display->set_display_invalid_dives(true);
	display->set_divelist_font("doNotCareAtAll");
	display->set_font_size(12.0);
	display->set_show_developer(false);
	display->set_theme("myTheme");

	QCOMPARE(prefs.display_invalid_dives, true);
	QCOMPARE(prefs.divelist_font, "doNotCareAtAll");
	QCOMPARE(prefs.font_size, 12.0);
	QCOMPARE(prefs.show_developer, false);
	QCOMPARE(prefs.theme, "myTheme");
}

void TestQPrefDisplay::test_set_load_struct()
{
	// test set func -> load -> struct pref

	auto display = qPrefDisplay::instance();

	display->set_display_invalid_dives(false);
	display->set_divelist_font("doNotCareString");
	display->set_font_size(15.0);
	display->set_show_developer(true);
	display->set_theme("myTheme2");

	prefs.display_invalid_dives = true;
	prefs.divelist_font = copy_qstring("doNotCareAtAll");
	prefs.font_size = 12.0;
	prefs.show_developer = false;
	prefs.theme = copy_qstring("myTheme");

	display->load();
	QCOMPARE(prefs.display_invalid_dives, false);
	QCOMPARE(prefs.divelist_font, "doNotCareString");
	QCOMPARE(prefs.font_size, 15.0);
	QCOMPARE(prefs.show_developer, true);
	QCOMPARE(prefs.theme, "myTheme2");
}

void TestQPrefDisplay::test_struct_disk()
{
	// test struct prefs -> disk

	auto display = qPrefDisplay::instance();

	prefs.display_invalid_dives = true;
	prefs.divelist_font = copy_qstring("doNotCareAtAll");
	prefs.font_size = 17.0;
	prefs.show_developer = false;
	prefs.theme = copy_qstring("myTheme3");

	display->sync();
	prefs.display_invalid_dives = false;
	prefs.divelist_font = copy_qstring("noString");
	prefs.font_size = 11.0;
	prefs.show_developer = true;
	prefs.theme = copy_qstring("myTheme");

	display->load();
	QCOMPARE(prefs.display_invalid_dives, true);
	QCOMPARE(prefs.divelist_font, "doNotCareAtAll");
	QCOMPARE(prefs.font_size, 17.0);
	QCOMPARE(prefs.show_developer, false);
	QCOMPARE(prefs.theme, "myTheme3");
}

void TestQPrefDisplay::test_multiple()
{
	// test multiple instances have the same information
	auto display_direct = qPrefDisplay::instance();
	prefs.divelist_font = copy_qstring("comic");

	auto display = qPrefDisplay::instance();
	prefs.font_size = 15.0;

	QCOMPARE(display->divelist_font(), display_direct->divelist_font());
	QCOMPARE(display->divelist_font(), QString("comic"));
	QCOMPARE(display->font_size(), display_direct->font_size());
	QCOMPARE(display->font_size(), 15.0);
}

QTEST_MAIN(TestQPrefDisplay)