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
155
156
|
// SPDX-License-Identifier: GPL-2.0
#include "testqPrefDiveComputer.h"
#include "core/pref.h"
#include "core/qthelper.h"
#include "core/settings/qPref.h"
#include <QTest>
void TestQPrefDiveComputer::initTestCase()
{
QCoreApplication::setOrganizationName("Subsurface");
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
QCoreApplication::setApplicationName("SubsurfaceTestQPrefDiveComputer");
}
void TestQPrefDiveComputer::test_struct_get()
{
// Test struct pref -> get func.
auto tst = qPrefDiveComputer::instance();
prefs.dive_computer.device = copy_qstring("my device");
prefs.dive_computer.device_name = copy_qstring("my device name");
prefs.dive_computer.download_mode = 17;
prefs.dive_computer.product = copy_qstring("my product");
prefs.dive_computer.vendor = copy_qstring("my vendor");
QCOMPARE(tst->device(), QString(prefs.dive_computer.device));
QCOMPARE(tst->device_name(), QString(prefs.dive_computer.device_name));
QCOMPARE(tst->download_mode(), prefs.dive_computer.download_mode);
QCOMPARE(tst->product(), QString(prefs.dive_computer.product));
QCOMPARE(tst->vendor(), QString(prefs.dive_computer.vendor));
}
void TestQPrefDiveComputer::test_set_struct()
{
// Test set func -> struct pref
auto tst = qPrefDiveComputer::instance();
tst->set_device("t2 device");
tst->set_device_name("t2 device name");
tst->set_download_mode(27);
tst->set_product("t2 product");
tst->set_vendor("t2 vendor");
QCOMPARE(QString(prefs.dive_computer.device), QString("t2 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t2 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 27);
QCOMPARE(QString(prefs.dive_computer.product), QString("t2 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t2 vendor"));
}
void TestQPrefDiveComputer::test_set_load_struct()
{
// test set func -> load -> struct pref
auto tst = qPrefDiveComputer::instance();
tst->set_device("t3 device");
tst->set_device_name("t3 device name");
tst->set_download_mode(37);
tst->set_product("t3 product");
tst->set_vendor("t3 vendor");
prefs.dive_computer.device = copy_qstring("error1");
prefs.dive_computer.device_name = copy_qstring("error2");
prefs.dive_computer.download_mode = 38;
prefs.dive_computer.product = copy_qstring("error3");
prefs.dive_computer.vendor = copy_qstring("error4");
tst->load();
QCOMPARE(QString(prefs.dive_computer.device), QString("t3 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t3 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 37);
QCOMPARE(QString(prefs.dive_computer.product), QString("t3 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t3 vendor"));
}
void TestQPrefDiveComputer::test_struct_disk()
{
// test struct prefs -> disk
auto tst = qPrefDiveComputer::instance();
prefs.dive_computer.device = copy_qstring("t4 device");
prefs.dive_computer.device_name = copy_qstring("t4 device name");
prefs.dive_computer.download_mode = 47;
prefs.dive_computer.product = copy_qstring("t4 product");
prefs.dive_computer.vendor = copy_qstring("t4 vendor");
tst->sync();
prefs.dive_computer.device = copy_qstring("error");
prefs.dive_computer.device_name = copy_qstring("error");
prefs.dive_computer.download_mode = 48;
prefs.dive_computer.product = copy_qstring("error");
prefs.dive_computer.vendor = copy_qstring("error");
tst->load();
QCOMPARE(QString(prefs.dive_computer.device), QString("t4 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t4 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 47);
QCOMPARE(QString(prefs.dive_computer.product), QString("t4 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t4 vendor"));
}
void TestQPrefDiveComputer::test_multiple()
{
// test multiple instances have the same information
auto tst_direct = new qPrefDiveComputer;
prefs.dive_computer.download_mode = 57;
auto tst = qPrefDiveComputer::instance();
prefs.dive_computer.device = copy_qstring("mine");
QCOMPARE(tst->device(), tst_direct->device());
QCOMPARE(tst->device(), QString("mine"));
QCOMPARE(tst->download_mode(), tst_direct->download_mode());
QCOMPARE(tst->download_mode(), 57);
}
#define TEST(METHOD, VALUE) \
QCOMPARE(METHOD, VALUE); \
dc->sync(); \
dc->load(); \
QCOMPARE(METHOD, VALUE);
void TestQPrefDiveComputer::test_oldPreferences()
{
auto dc = qPrefDiveComputer::instance();
dc->set_device("TomazComputer");
TEST(dc->device(), QStringLiteral("TomazComputer"));
dc->set_device("Deepwater");
TEST(dc->device(), QStringLiteral("Deepwater"));
dc->set_download_mode(0);
TEST(dc->download_mode(), 0);
dc->set_download_mode(1);
TEST(dc->download_mode(), 1);
dc->set_product("Thingy1");
TEST(dc->product(), QStringLiteral("Thingy1"));
dc->set_product("Thingy2");
TEST(dc->product(), QStringLiteral("Thingy2"));
dc->set_vendor("Sharewater");
TEST(dc->vendor(), QStringLiteral("Sharewater"));
dc->set_vendor("OSTS");
TEST(dc->vendor(), QStringLiteral("OSTS"));
}
QTEST_MAIN(TestQPrefDiveComputer)
|