summaryrefslogtreecommitdiffstats
path: root/tests/testqPrefGeocoding.cpp
blob: b0dbcbc6c4f34302c2288df5c9498d225cda52fb (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
// SPDX-License-Identifier: GPL-2.0
#include "testqPrefGeocoding.h"

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

#include <QTest>

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

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

	auto tst = qPrefGeocoding::instance();

	prefs.geocoding.category[0] = TC_NONE;
	prefs.geocoding.category[1] = TC_OCEAN;
	prefs.geocoding.category[2] = TC_ADMIN_L1;

	QCOMPARE(tst->first_taxonomy_category(), prefs.geocoding.category[0]);
	QCOMPARE(tst->second_taxonomy_category(), prefs.geocoding.category[1]);
	QCOMPARE(tst->third_taxonomy_category(), prefs.geocoding.category[2]);
}

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

	auto tst = qPrefGeocoding::instance();

	tst->set_first_taxonomy_category(TC_COUNTRY);
	tst->set_second_taxonomy_category(TC_ADMIN_L1);
	tst->set_third_taxonomy_category(TC_ADMIN_L2);

	QCOMPARE(prefs.geocoding.category[0], TC_COUNTRY);
	QCOMPARE(prefs.geocoding.category[1], TC_ADMIN_L1);
	QCOMPARE(prefs.geocoding.category[2], TC_ADMIN_L2);
}

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

	auto tst = qPrefGeocoding::instance();

	tst->set_first_taxonomy_category(TC_LOCALNAME);
	tst->set_second_taxonomy_category(TC_ADMIN_L3);
	tst->set_third_taxonomy_category(TC_NR_CATEGORIES);

	prefs.geocoding.category[0] = TC_NONE;
	prefs.geocoding.category[1] = TC_OCEAN;
	prefs.geocoding.category[2] = TC_ADMIN_L1;

	tst->load();
	QCOMPARE(prefs.geocoding.category[0], TC_LOCALNAME);
	QCOMPARE(prefs.geocoding.category[1], TC_ADMIN_L3);
	QCOMPARE(prefs.geocoding.category[2], TC_NR_CATEGORIES);
}

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

	auto tst = qPrefGeocoding::instance();

	prefs.geocoding.category[0] = TC_NONE;
	prefs.geocoding.category[1] = TC_OCEAN;
	prefs.geocoding.category[2] = TC_ADMIN_L1;

	tst->sync();
	prefs.geocoding.category[0] = TC_ADMIN_L2;
	prefs.geocoding.category[1] = TC_ADMIN_L2;
	prefs.geocoding.category[2] = TC_ADMIN_L2;

	tst->load();
	QCOMPARE(prefs.geocoding.category[0], TC_NONE);
	QCOMPARE(prefs.geocoding.category[1], TC_OCEAN);
	QCOMPARE(prefs.geocoding.category[2], TC_ADMIN_L1);
}

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

	prefs.geocoding.category[0] = TC_NONE;
	auto tst_direct = new qPrefGeocoding;

	prefs.geocoding.category[1] = TC_OCEAN;
	auto tst = qPrefGeocoding::instance();

	QCOMPARE(tst->first_taxonomy_category(), tst_direct->first_taxonomy_category());
	QCOMPARE(tst->second_taxonomy_category(), tst_direct->second_taxonomy_category());
	QCOMPARE(tst->first_taxonomy_category(), TC_NONE);
	QCOMPARE(tst->second_taxonomy_category(), TC_OCEAN);
}

QTEST_MAIN(TestQPrefGeocoding)