summaryrefslogtreecommitdiffstats
path: root/tests/testqPrefLanguage.cpp
blob: d2cea59e83081daaa65819c25c7022d6bf80ffd1 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// SPDX-License-Identifier: GPL-2.0
#include "testqPrefLanguage.h"

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

#include <QTest>

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

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

	auto tst = qPrefLanguage::instance();

	prefs.date_format = copy_qstring("new date format");
	prefs.date_format_override = true;
	prefs.date_format_short = copy_qstring("new short format");
	prefs.locale.language = copy_qstring("new lang format");
	prefs.locale.lang_locale = copy_qstring("new loc lang format");
	prefs.time_format = copy_qstring("new time format");
	prefs.time_format_override = true;
	prefs.locale.use_system_language = true;

	QCOMPARE(tst->date_format(), QString(prefs.date_format));
	QCOMPARE(tst->date_format_override(), prefs.date_format_override);
	QCOMPARE(tst->date_format_short(), QString(prefs.date_format_short));
	QCOMPARE(tst->language(), QString(prefs.locale.language));
	QCOMPARE(tst->lang_locale(), QString(prefs.locale.lang_locale));
	QCOMPARE(tst->time_format(), QString(prefs.time_format));
	QCOMPARE(tst->time_format_override(), prefs.time_format_override);
	QCOMPARE(tst->use_system_language(), prefs.locale.use_system_language);
}

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

	auto tst = qPrefLanguage::instance();

	tst->set_date_format("new date2");
	tst->set_date_format_override(false);
	tst->set_date_format_short("new short2");
	tst->set_language("new lang format");
	tst->set_lang_locale("new loc lang2");
	tst->set_time_format("new time2");
	tst->set_time_format_override(false);
	tst->set_use_system_language(false);

	QCOMPARE(tst->date_format(), QString("new date2"));
	QCOMPARE(tst->date_format_override(), false);
	QCOMPARE(tst->date_format_short(), QString("new short2"));
	QCOMPARE(tst->language(), QString("new lang format"));
	QCOMPARE(tst->lang_locale(), QString("new loc lang2"));
	QCOMPARE(tst->time_format(), QString("new time2"));
	QCOMPARE(tst->time_format_override(), false);
	QCOMPARE(tst->use_system_language(), false);
}

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

	auto tst = qPrefLanguage::instance();

	tst->set_date_format("new date3");
	tst->set_date_format_override(true);
	tst->set_date_format_short("new short3");
	tst->set_language("new lang format3");
	tst->set_lang_locale("new loc lang3");
	tst->set_time_format("new time3");
	tst->set_time_format_override(true);
	tst->set_use_system_language(true);

	prefs.date_format = copy_qstring("error3");
	prefs.date_format_override = false;
	prefs.date_format_short = copy_qstring("error3");
	prefs.locale.language = copy_qstring("error3");
	prefs.locale.lang_locale = copy_qstring("error3");
	prefs.time_format = copy_qstring("error3");
	prefs.time_format_override = false;
	prefs.locale.use_system_language = false;

	tst->load();
	QCOMPARE(QString(prefs.date_format), QString("new date3"));
	QCOMPARE(prefs.date_format_override, true);
	QCOMPARE(QString(prefs.date_format_short), QString("new short3"));
	QCOMPARE(QString(prefs.locale.language), QString("new lang format3"));
	QCOMPARE(QString(prefs.locale.lang_locale), QString("new loc lang3"));
	QCOMPARE(QString(prefs.time_format), QString("new time3"));
	QCOMPARE(prefs.time_format_override, true);
	QCOMPARE(prefs.locale.use_system_language, true);
}

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

	auto tst = qPrefLanguage::instance();

	prefs.date_format = copy_qstring("new date format");
	prefs.date_format_override = true;
	prefs.date_format_short = copy_qstring("new short format");
	prefs.locale.language = copy_qstring("new lang format");
	prefs.locale.lang_locale = copy_qstring("new loc lang format");
	prefs.time_format = copy_qstring("new time format");
	prefs.time_format_override = true;
	prefs.locale.use_system_language = true;

	tst->sync();
	prefs.date_format = copy_qstring("error3");
	prefs.date_format_override = false;
	prefs.date_format_short = copy_qstring("error3");
	prefs.locale.language = copy_qstring("error3");
	prefs.locale.lang_locale = copy_qstring("error3");
	prefs.time_format = copy_qstring("error3");
	prefs.time_format_override = false;
	prefs.locale.use_system_language = false;

	tst->load();
	QCOMPARE(QString(prefs.date_format), QString("new date format"));
	QCOMPARE(prefs.date_format_override, true);
	QCOMPARE(QString(prefs.date_format_short), QString("new short format"));
	QCOMPARE(QString(prefs.locale.language), QString("new lang format"));
	QCOMPARE(QString(prefs.locale.lang_locale), QString("new loc lang format"));
	QCOMPARE(QString(prefs.time_format), QString("new time format"));
	QCOMPARE(prefs.time_format_override, true);
	QCOMPARE(prefs.locale.use_system_language, true);
}

void TestQPrefLanguage::test_multiple()
{
	// test multiple instances have the same information

	prefs.locale.use_system_language = false;
	auto tst_direct = new qPrefLanguage;

	prefs.time_format_override = true;
	auto tst = qPrefLanguage::instance();

	QCOMPARE(tst->use_system_language(), tst_direct->use_system_language());
	QCOMPARE(tst->time_format_override(), tst_direct->time_format_override());
	QCOMPARE(tst_direct->use_system_language(), false);
	QCOMPARE(tst_direct->time_format_override(), true);
}

QTEST_MAIN(TestQPrefLanguage)