1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtCore/QString> |
30 | #include <QtTest/QtTest> |
31 | #include <QVariantMap> |
32 | |
33 | #include <QtLocation/private/qgeomaptype_p.h> |
34 | |
35 | QT_USE_NAMESPACE |
36 | |
37 | Q_DECLARE_METATYPE(QGeoMapType) |
38 | |
39 | class tst_MapType : public QObject |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | tst_MapType(); |
45 | |
46 | private Q_SLOTS: |
47 | void constructorTest(); |
48 | void comparison(); |
49 | void comparison_data(); |
50 | }; |
51 | |
52 | tst_MapType::tst_MapType() {} |
53 | |
54 | void tst_MapType::constructorTest() |
55 | { |
56 | QGeoCameraCapabilities capabilities; |
57 | capabilities.setMinimumZoomLevel(0.0); |
58 | capabilities.setMaximumZoomLevel(20.0); |
59 | capabilities.setSupportsBearing(true); |
60 | capabilities.setSupportsTilting(true); |
61 | capabilities.setMinimumTilt(0); |
62 | capabilities.setMaximumTilt(60); |
63 | capabilities.setMinimumFieldOfView(20); |
64 | capabilities.setMaximumFieldOfView(90); |
65 | const QByteArray pluginName = "tst_MapType" ; |
66 | QGeoMapType *testObjPtr = new QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street map" ), |
67 | QStringLiteral("map description" ), true, true, 1, pluginName, capabilities); |
68 | QVERIFY(testObjPtr); |
69 | QCOMPARE(testObjPtr->style(), QGeoMapType::StreetMap); |
70 | QCOMPARE(testObjPtr->name(), QStringLiteral("street map" )); |
71 | QCOMPARE(testObjPtr->description(), QStringLiteral("map description" )); |
72 | QVERIFY(testObjPtr->mobile()); |
73 | QVERIFY(testObjPtr->night()); |
74 | QCOMPARE(testObjPtr->mapId(), 1); |
75 | QCOMPARE(testObjPtr->pluginName(), pluginName); |
76 | QCOMPARE(testObjPtr->cameraCapabilities(), capabilities); |
77 | QCOMPARE(testObjPtr->metadata(), QVariantMap()); |
78 | delete testObjPtr; |
79 | |
80 | testObjPtr = new QGeoMapType(); |
81 | QCOMPARE(testObjPtr->style(), QGeoMapType::NoMap); |
82 | QVERIFY2(testObjPtr->name().isEmpty(), "Wrong default value" ); |
83 | QVERIFY2(testObjPtr->description().isEmpty(), "Wrong default value" ); |
84 | QVERIFY2(!testObjPtr->mobile(), "Wrong default value" ); |
85 | QVERIFY2(!testObjPtr->night(), "Wrong default value" ); |
86 | QCOMPARE(testObjPtr->mapId(), 0); |
87 | QCOMPARE(testObjPtr->pluginName(), QByteArrayLiteral("" )); |
88 | QCOMPARE(testObjPtr->cameraCapabilities(), QGeoCameraCapabilities()); |
89 | delete testObjPtr; |
90 | } |
91 | |
92 | void tst_MapType::comparison_data() |
93 | { |
94 | QTest::addColumn<QGeoMapType>(name: "type1" ); |
95 | QTest::addColumn<QGeoMapType>(name: "type2" ); |
96 | QTest::addColumn<bool>(name: "expected" ); |
97 | |
98 | const QByteArray pluginName = "tst_MapType" ; |
99 | QGeoCameraCapabilities capabilities; |
100 | capabilities.setMinimumZoomLevel(0.0); |
101 | capabilities.setMaximumZoomLevel(20.0); |
102 | capabilities.setSupportsBearing(true); |
103 | capabilities.setSupportsTilting(true); |
104 | capabilities.setMinimumTilt(0); |
105 | capabilities.setMaximumTilt(60); |
106 | capabilities.setMinimumFieldOfView(20); |
107 | capabilities.setMaximumFieldOfView(90); |
108 | QGeoCameraCapabilities capabilities2 = capabilities; |
109 | capabilities2.setMaximumFieldOfView(80); |
110 | |
111 | QTest::newRow(dataTag: "null" ) << QGeoMapType() << QGeoMapType() << true; |
112 | |
113 | QTest::newRow(dataTag: "equal" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
114 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
115 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
116 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
117 | << true; |
118 | |
119 | QTest::newRow(dataTag: "style" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
120 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
121 | << QGeoMapType(QGeoMapType::TerrainMap, QStringLiteral("street name" ), |
122 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
123 | << false; |
124 | |
125 | QTest::newRow(dataTag: "name" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
126 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
127 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("different name" ), |
128 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
129 | << false; |
130 | |
131 | QTest::newRow(dataTag: "description" ) << QGeoMapType(QGeoMapType::StreetMap, |
132 | QStringLiteral("street name" ), |
133 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
134 | << QGeoMapType(QGeoMapType::StreetMap, |
135 | QStringLiteral("street name" ), |
136 | QStringLiteral("different desc" ), false, false, 42, pluginName, capabilities) |
137 | << false; |
138 | |
139 | QTest::newRow(dataTag: "mobile" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
140 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
141 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
142 | QStringLiteral("street desc" ), true, false, 42, pluginName, capabilities) |
143 | << false; |
144 | |
145 | QTest::newRow(dataTag: "night" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
146 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
147 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
148 | QStringLiteral("street desc" ), false, true, 42, pluginName, capabilities) |
149 | << false; |
150 | |
151 | QTest::newRow(dataTag: "id" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
152 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
153 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
154 | QStringLiteral("street desc" ), false, false, 99, pluginName, capabilities) |
155 | << false; |
156 | |
157 | QTest::newRow(dataTag: "plugin_name" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
158 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
159 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
160 | QStringLiteral("street desc" ), false, false, 42, QByteArrayLiteral("abc" ), capabilities) |
161 | << false; |
162 | |
163 | QTest::newRow(dataTag: "camera_capabilities" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
164 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
165 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
166 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities2) |
167 | << false; |
168 | |
169 | QVariantMap metadata; |
170 | metadata["foo" ] = 42; |
171 | QTest::newRow(dataTag: "metadata" ) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
172 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities) |
173 | << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name" ), |
174 | QStringLiteral("street desc" ), false, false, 42, pluginName, capabilities, metadata) |
175 | << false; |
176 | } |
177 | |
178 | void tst_MapType::comparison() |
179 | { |
180 | QFETCH(QGeoMapType, type1); |
181 | QFETCH(QGeoMapType, type2); |
182 | QFETCH(bool, expected); |
183 | |
184 | QCOMPARE(type1 == type2, expected); |
185 | QCOMPARE(type1 != type2, !expected); |
186 | } |
187 | |
188 | QTEST_APPLESS_MAIN(tst_MapType) |
189 | |
190 | #include "tst_maptype.moc" |
191 | |