summaryrefslogtreecommitdiff
path: root/tests/auto/qgeotilespec/tst_qgeotilespec.cpp
blob: cda8bd65664c77113c66e919a41dafb04d43e02a (plain)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtCore/QString>
#include <QtTest/QtTest>

#include "qgeotilespec_p.h"

QT_USE_NAMESPACE

class tst_QGeoTileSpec : public QObject
{
    Q_OBJECT

public:
    tst_QGeoTileSpec();

private:
    void populateGeoTileSpecData();

private Q_SLOTS:
    void constructorTest_data();
    void constructorTest();
    void pluginTest();
    void zoomTest();
    void xTest();
    void yTest();
    void mapIdTest();
    void assignsOperatorTest_data();
    void assignsOperatorTest();
    void equalsOperatorTest_data();
    void equalsOperatorTest();
    void lessThanOperatorTest_data();
    void lessThanOperatorTest();
    void qHashTest_data();
    void qHashTest();
};

tst_QGeoTileSpec::tst_QGeoTileSpec()
{
}

void tst_QGeoTileSpec::populateGeoTileSpecData(){
    QTest::addColumn<QString>("plugin");
    QTest::addColumn<int>("mapId");
    QTest::addColumn<int>("zoom");
    QTest::addColumn<int>("x");
    QTest::addColumn<int>("y");
    QTest::newRow("zeros") << QString() << 0 << 0 << 0 << 0;
    QTest::newRow("valid") << QString("geo plugin") << 455 << 1 << 20 << 50;
    QTest::newRow("negative values") << QString("geo plugin negative") << -350 << 2 << -20 << -50;
}

void tst_QGeoTileSpec::constructorTest_data()
{
    populateGeoTileSpecData();
}

void tst_QGeoTileSpec::constructorTest()
{
    QFETCH(QString,plugin);
    QFETCH(int,zoom);
    QFETCH(int,mapId);
    QFETCH(int,x);
    QFETCH(int,y);

    // test constructor copy with default values
    QGeoTileSpec testObj;
    QGeoTileSpec testObj2(testObj);
    QCOMPARE(testObj.plugin(), testObj2.plugin());
    QCOMPARE(testObj.mapId(), testObj2.mapId());
    QCOMPARE(testObj.zoom(), testObj2.zoom());
    QCOMPARE(testObj.x(), testObj2.x());
    QCOMPARE(testObj.y(), testObj2.y());

    // test second construct
    QGeoTileSpec testObj3(plugin, mapId, zoom, x, y);
    QCOMPARE(testObj3.plugin(), plugin);
    QCOMPARE(testObj3.mapId(), mapId);
    QCOMPARE(testObj3.zoom(), zoom);
    QCOMPARE(testObj3.x(), x);
    QCOMPARE(testObj3.y(), y);
}

void tst_QGeoTileSpec::pluginTest()
{
    QGeoTileSpec tileSpec;
    QCOMPARE(tileSpec.plugin(), QString());

    QGeoTileSpec tileSpec2(QString("plugin test"),1,10,10,5);
    QCOMPARE(tileSpec2.plugin(), QString("plugin test"));
}

void tst_QGeoTileSpec::zoomTest()
{
    QGeoTileSpec tileSpec;
    QVERIFY(tileSpec.zoom() == -1);
    tileSpec.setZoom(1);
    QVERIFY(tileSpec.zoom() == 1);

    QGeoTileSpec tileSpec2 = tileSpec;
    QVERIFY(tileSpec2.zoom() == 1);
    tileSpec.setZoom(2);
    QVERIFY(tileSpec2.zoom() == 1);
}

void tst_QGeoTileSpec::xTest()
{
    QGeoTileSpec tileSpec;
    QVERIFY(tileSpec.x() == -1);
    tileSpec.setX(10);
    QVERIFY(tileSpec.x() == 10);

    QGeoTileSpec tileSpec2 = tileSpec;
    QVERIFY(tileSpec2.x() == 10);
    tileSpec.setX(30);
    QVERIFY(tileSpec2.x() == 10);
}

void tst_QGeoTileSpec::yTest()
{
    QGeoTileSpec tileSpec;
    QVERIFY(tileSpec.y() == -1);
    tileSpec.setY(20);
    QVERIFY(tileSpec.y() == 20);

    QGeoTileSpec tileSpec2 = tileSpec;
    QVERIFY(tileSpec2.y() == 20);
    tileSpec.setY(40);
    QVERIFY(tileSpec2.y() == 20);
}

void tst_QGeoTileSpec::mapIdTest()
{
    QGeoTileSpec tileSpec;
    QVERIFY(tileSpec.mapId() == 0);
    tileSpec.setMapId(1);
    QVERIFY(tileSpec.mapId() == 1);

    QGeoTileSpec tileSpec2 = tileSpec;
    QVERIFY(tileSpec2.mapId() == 1);
    tileSpec.setMapId(5);
    QVERIFY(tileSpec2.mapId() == 1);
}

void tst_QGeoTileSpec::assignsOperatorTest_data()
{
    populateGeoTileSpecData();
}


void tst_QGeoTileSpec::assignsOperatorTest()
{
    QFETCH(QString,plugin);
    QFETCH(int,mapId);
    QFETCH(int,zoom);
    QFETCH(int,x);
    QFETCH(int,y);

    QGeoTileSpec testObj(plugin, mapId, zoom, x, y);
    QGeoTileSpec testObj2;
    testObj2 = testObj;
    // test the correctness of the asignment operator
    QVERIFY2(testObj2.plugin() == plugin, "Plugin not copied correctly");
    QVERIFY2(testObj2.zoom() == zoom, "Zoom not copied correctly");
    QVERIFY2(testObj2.mapId() == mapId, "Map Id not copied correctly");
    QVERIFY2(testObj2.x() == x, "X not copied correctly");
    QVERIFY2(testObj2.y() == y, "Y not copied correctly");
    // verify that values have not changed after an assignment
    QVERIFY2(testObj.plugin() == testObj2.plugin(), "Plugin not copied correctly");
    QVERIFY2(testObj.zoom() == testObj2.zoom(), "Zoom not copied correctly");
    QVERIFY2(testObj.mapId() == testObj2.mapId(), "Map Id not copied correctly");
    QVERIFY2(testObj.x() == testObj2.x(), "X not copied correctly");
    QVERIFY2(testObj.y() == testObj2.y(), "Y not copied correctly");
}


void tst_QGeoTileSpec::equalsOperatorTest_data()
{
    populateGeoTileSpecData();
}

void tst_QGeoTileSpec::equalsOperatorTest()
{
    QFETCH(QString,plugin);
    QFETCH(int,mapId);
    QFETCH(int,zoom);
    QFETCH(int,x);
    QFETCH(int,y);

    QGeoTileSpec testObj(plugin, mapId, zoom, x, y);
    QGeoTileSpec testObj2(plugin, mapId, zoom, x, y);
    QVERIFY2(testObj == testObj2, "Equals operator is not correct");

    // test QGeoTileSpec pairs where they differ in one field
    testObj2.setZoom(zoom+1);
    QVERIFY2(!(testObj == testObj2), "Equals operator is not correct");
    testObj2 = testObj;
    testObj2.setMapId(mapId+1);
    QVERIFY2(!(testObj == testObj2), "Equals operator is not correct");
    testObj2 = testObj;
    testObj2.setX(x+1);
    QVERIFY2(!(testObj == testObj2), "Equals operator is not correct");
    testObj2 = testObj;
    testObj2.setY(y+1);
    QVERIFY2(!(testObj == testObj2), "Equals operator is not correct");
}

void tst_QGeoTileSpec::lessThanOperatorTest_data()
{
    populateGeoTileSpecData();
}

void tst_QGeoTileSpec::lessThanOperatorTest()
{
    QFETCH(QString,plugin);
    QFETCH(int,mapId);
    QFETCH(int,zoom);
    QFETCH(int,x);
    QFETCH(int,y);

    QGeoTileSpec testObj(plugin, mapId, zoom, x, y);
    QGeoTileSpec testObj2(testObj);
    QVERIFY(!(testObj < testObj2));

    testObj2.setMapId(mapId-1);
    QVERIFY2(testObj2 < testObj, "Less than operator is not correct for mapId");
    testObj2 = testObj;
    testObj2.setZoom(zoom-1);
    QVERIFY2(testObj2 < testObj, "Less than operator is not correct for zoom");
    testObj2 = testObj;
    testObj2.setX(x-1);
    QVERIFY2(testObj2 < testObj, "Less than operator is not correct for x");
    testObj2 = testObj;
    testObj2.setY(y-1);
    QVERIFY2(testObj2 < testObj, "Less than operator is not correct for y");

    // less than comparisons are done in the order: plugin -> mapId -> zoom -> x -> y
    // the test below checks if the order is correct
    QGeoTileSpec testObj3(plugin + QString('a'), mapId-1, zoom-1, x-1, y-1);
    QVERIFY2(testObj < testObj3, "Order of less than operator is not correct");
    QGeoTileSpec testObj4(plugin, mapId+1, zoom-1, x-1, y-1);
    QVERIFY2(testObj < testObj4, "Order of less than operator is not correct");
    QGeoTileSpec testObj5(plugin, mapId, zoom+1, x-1, y-1);
    QVERIFY2(testObj < testObj5, "Order of less than operator is not correct");
    QGeoTileSpec testObj6(plugin, mapId, zoom, x+1, y-1);
    QVERIFY2(testObj < testObj6, "Order of less than operator is not correct");
    QGeoTileSpec testObj7(plugin, mapId, zoom, x, y+1);
    QVERIFY2(testObj < testObj7, "Order of less than operator is not correct");

    QGeoTileSpec testObj8(plugin, mapId-1, zoom+1, x+1, y+1);
    QVERIFY2(testObj8 < testObj, "Order of less than operator is not correct");
    QGeoTileSpec testObj9(plugin, mapId, zoom-1, x+1, y+1);
    QVERIFY2(testObj9 < testObj, "Order of less than operator is not correct");
    QGeoTileSpec testObj10(plugin, mapId, zoom, x-1, y+1);
    QVERIFY2(testObj10 < testObj, "Order of less than operator is not correct");
}

void tst_QGeoTileSpec::qHashTest_data(){
    populateGeoTileSpecData();
}

void tst_QGeoTileSpec::qHashTest()
{
    QGeoTileSpec testObj;
    unsigned int hash1 = qHash(testObj);
    QGeoTileSpec testObj2;
    testObj2 = testObj;
    unsigned int hash2 = qHash(testObj2);
    QCOMPARE(hash1, hash2);

    QFETCH(QString,plugin);
    QFETCH(int,mapId);
    QFETCH(int,zoom);
    QFETCH(int,x);
    QFETCH(int,y);

    QGeoTileSpec testObj3(plugin, mapId, zoom, x, y);
    unsigned int hash3 = qHash(testObj3);
    QVERIFY(hash1 != hash3);

    testObj2.setMapId(testObj3.mapId()+1);
    testObj2.setZoom(testObj3.zoom()+1);
    testObj2.setX(testObj3.x()*5);
    testObj2.setY(testObj3.y()*10);
    hash2 = qHash(testObj2);
    QVERIFY(hash2 != hash3);
}

QTEST_APPLESS_MAIN(tst_QGeoTileSpec)

#include "tst_qgeotilespec.moc"