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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/*
SPDX-FileCopyrightText: 2010 Martin Blumenstingl <darklight.xdarklight@googlemail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kconfigloadertest.h"
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kconfigskeleton.h>
#include <kconfigloader.h>
Q_DECLARE_METATYPE(QList<int>)
#define TEST_NAME QString::fromLatin1("kconfigloadertest")
#define GET_CONFIG_ITEM_VALUE(type, configName) \
KConfigSkeletonItem* item = cl->findItem(TEST_NAME, configName); \
/* Check if we got back a valid item. */ \
QVERIFY(item != nullptr); \
/* Cast the item to the given type. */ \
type typeItem = dynamic_cast<type>(item); \
/* Make sure the cast was successful. */ \
QVERIFY(typeItem != nullptr);
void ConfigLoaderTest::init()
{
QString fileName = TEST_NAME + QLatin1String(".xml");
configFile = new QFile(QFINDTESTDATA(QString::fromLatin1("/") + fileName));
cl = new KConfigLoader(configFile->fileName(), configFile);
}
void ConfigLoaderTest::cleanup()
{
delete cl;
delete configFile;
}
void ConfigLoaderTest::boolDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemBool *, "DefaultBoolItem");
QVERIFY(typeItem->isEqual(true));
}
void ConfigLoaderTest::colorDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor *, "DefaultColorItem");
QVERIFY(typeItem->isEqual(QColor("#00FF00")));
}
void ConfigLoaderTest::dateTimeDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDateTime *, "DefaultDateTimeItem");
QVERIFY(typeItem->isEqual(QDateTime::fromString("Thu Sep 09 2010")));
}
void ConfigLoaderTest::enumDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemEnum *, "DefaultEnumItem");
QVERIFY(typeItem->isEqual(3));
}
void ConfigLoaderTest::fontDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemFont *, "DefaultFontItem");
QVERIFY(typeItem->isEqual(QFont("DejaVu Sans")));
}
void ConfigLoaderTest::intDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemInt *, "DefaultIntItem");
QVERIFY(typeItem->isEqual(27));
}
void ConfigLoaderTest::passwordDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPassword *, "DefaultPasswordItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("h4x.")));
}
void ConfigLoaderTest::pathDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath *, "DefaultPathItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("/dev/null")));
}
void ConfigLoaderTest::stringDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemString *, "DefaultStringItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("TestString")));
}
void ConfigLoaderTest::stringListDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemStringList *, "DefaultStringListItem");
// Create a string list with the expected values.
QStringList expected;
expected.append(QStringLiteral("One"));
expected.append(QStringLiteral("Two"));
expected.append(QStringLiteral("Three"));
expected.append(QStringLiteral("Four"));
expected.append(QStringLiteral("Five"));
QVERIFY(typeItem->isEqual(expected));
}
void ConfigLoaderTest::uintDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUInt *, "DefaultUIntItem");
QVERIFY(typeItem->isEqual(7U));
}
void ConfigLoaderTest::urlDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUrl *, "DefaultUrlItem");
QVERIFY(typeItem->isEqual(QUrl("http://kde.org")));
}
void ConfigLoaderTest::doubleDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDouble *, "DefaultDoubleItem");
QVERIFY(typeItem->isEqual(13.37));
}
void ConfigLoaderTest::intListDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemIntList *, "DefaultIntListItem");
// Create a int list with the expected values.
QList<int> expected;
expected.append(1);
expected.append(1);
expected.append(2);
expected.append(3);
expected.append(5);
expected.append(8);
QVERIFY(typeItem->isEqual(QVariant::fromValue(expected)));
}
void ConfigLoaderTest::longLongDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemLongLong *, "DefaultLongLongItem");
QVERIFY(typeItem->isEqual(Q_INT64_C(-9211372036854775808)));
}
void ConfigLoaderTest::pointDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemPoint *, "DefaultPointItem");
QVERIFY(typeItem->isEqual(QPoint(185, 857)));
}
void ConfigLoaderTest::rectDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemRect *, "DefaultRectItem");
// Create a new QRect with the expected value.
QRect expected;
expected.setCoords(3, 7, 951, 358);
QVERIFY(typeItem->isEqual(expected));
}
void ConfigLoaderTest::sizeDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemSize *, "DefaultSizeItem");
QVERIFY(typeItem->isEqual(QSize(640, 480)));
}
void ConfigLoaderTest::ulongLongDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemULongLong *, "DefaultULongLongItem");
QVERIFY(typeItem->isEqual(Q_UINT64_C(9223372036854775806)));
}
QTEST_MAIN(ConfigLoaderTest)
|