|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qgeosatelliteinfo.h> |
|
42 |
|
43 #include <QMetaType> |
|
44 #include <QObject> |
|
45 #include <QDebug> |
|
46 #include <QTest> |
|
47 |
|
48 #include <float.h> |
|
49 #include <limits.h> |
|
50 |
|
51 QTM_USE_NAMESPACE |
|
52 Q_DECLARE_METATYPE(QGeoSatelliteInfo) |
|
53 Q_DECLARE_METATYPE(QGeoSatelliteInfo::Attribute) |
|
54 |
|
55 QByteArray tst_qgeosatelliteinfo_debug; |
|
56 |
|
57 void tst_qgeosatelliteinfo_messageHandler(QtMsgType type, const char *msg) |
|
58 { |
|
59 switch(type) { |
|
60 case QtDebugMsg : |
|
61 tst_qgeosatelliteinfo_debug = QByteArray(msg); |
|
62 break; |
|
63 default: |
|
64 break; |
|
65 } |
|
66 } |
|
67 |
|
68 |
|
69 QList<qreal> tst_qgeosatelliteinfo_qrealTestValues() |
|
70 { |
|
71 QList<qreal> values; |
|
72 |
|
73 // the following platforms use float for qreal |
|
74 #if !defined(QT_NO_FPU) && !defined(QT_ARCH_ARM) && !defined(QT_ARCH_WINDOWSCE) && !defined(QT_ARCH_SYMBIAN) |
|
75 if (qreal(DBL_MIN) == DBL_MIN) |
|
76 values << DBL_MIN; |
|
77 #endif |
|
78 |
|
79 values << FLT_MIN; |
|
80 values << -1.0 << 0.0 << 1.0; |
|
81 values << FLT_MAX; |
|
82 |
|
83 // the following platforms use float for qreal |
|
84 #if !defined(QT_NO_FPU) && !defined(QT_ARCH_ARM) && !defined(QT_ARCH_WINDOWSCE) && !defined(QT_ARCH_SYMBIAN) |
|
85 if (qreal(DBL_MAX) == DBL_MAX) |
|
86 values << DBL_MAX; |
|
87 #endif |
|
88 |
|
89 return values; |
|
90 } |
|
91 |
|
92 QList<int> tst_qgeosatelliteinfo_intTestValues() |
|
93 { |
|
94 QList<int> values; |
|
95 values << INT_MIN << -100 << 0 << 100 << INT_MAX; |
|
96 return values; |
|
97 } |
|
98 |
|
99 QList<QGeoSatelliteInfo::Attribute> tst_qgeosatelliteinfo_getAttributes() |
|
100 { |
|
101 QList<QGeoSatelliteInfo::Attribute> attributes; |
|
102 attributes << QGeoSatelliteInfo::Elevation |
|
103 << QGeoSatelliteInfo::Azimuth; |
|
104 return attributes; |
|
105 } |
|
106 |
|
107 |
|
108 class tst_QGeoSatelliteInfo : public QObject |
|
109 { |
|
110 Q_OBJECT |
|
111 |
|
112 private: |
|
113 QGeoSatelliteInfo updateWithAttribute(QGeoSatelliteInfo::Attribute attribute, qreal value) |
|
114 { |
|
115 QGeoSatelliteInfo info; |
|
116 info.setAttribute(attribute, value); |
|
117 return info; |
|
118 } |
|
119 |
|
120 void addTestData_update() |
|
121 { |
|
122 QTest::addColumn<QGeoSatelliteInfo>("info"); |
|
123 |
|
124 QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); |
|
125 for (int i=0; i<intValues.count(); i++) { |
|
126 QGeoSatelliteInfo info; |
|
127 info.setPrnNumber(intValues[i]); |
|
128 QTest::newRow("prn") << info; |
|
129 } |
|
130 |
|
131 for (int i=0; i<intValues.count(); i++) { |
|
132 QGeoSatelliteInfo info; |
|
133 info.setSignalStrength(intValues[i]); |
|
134 QTest::newRow("signal strength") << info; |
|
135 } |
|
136 |
|
137 QList<QGeoSatelliteInfo::Attribute> attributes = tst_qgeosatelliteinfo_getAttributes(); |
|
138 QList<qreal> qrealValues = tst_qgeosatelliteinfo_qrealTestValues(); |
|
139 for (int i=0; i<attributes.count(); i++) { |
|
140 QTest::newRow(qPrintable(QString("Attribute %1 = %2").arg(attributes[i]).arg(qrealValues[i]))) |
|
141 << updateWithAttribute(attributes[i], qrealValues[i]); |
|
142 } |
|
143 } |
|
144 |
|
145 private slots: |
|
146 void constructor() |
|
147 { |
|
148 QGeoSatelliteInfo info; |
|
149 QCOMPARE(info.prnNumber(), -1); |
|
150 QCOMPARE(info.signalStrength(), -1); |
|
151 QList<QGeoSatelliteInfo::Attribute> attributes = tst_qgeosatelliteinfo_getAttributes(); |
|
152 for (int i=0; i<attributes.count(); i++) |
|
153 QCOMPARE(info.attribute(attributes[i]), qreal(-1.0)); |
|
154 } |
|
155 |
|
156 void constructor_copy() |
|
157 { |
|
158 QFETCH(QGeoSatelliteInfo, info); |
|
159 |
|
160 QCOMPARE(QGeoSatelliteInfo(info), info); |
|
161 } |
|
162 |
|
163 void constructor_copy_data() |
|
164 { |
|
165 addTestData_update(); |
|
166 } |
|
167 |
|
168 void operator_comparison() |
|
169 { |
|
170 QFETCH(QGeoSatelliteInfo, info); |
|
171 |
|
172 QVERIFY(info == info); |
|
173 QCOMPARE(info != info, false); |
|
174 QCOMPARE(info == QGeoSatelliteInfo(), false); |
|
175 QCOMPARE(info != QGeoSatelliteInfo(), true); |
|
176 |
|
177 QVERIFY(QGeoSatelliteInfo() == QGeoSatelliteInfo()); |
|
178 } |
|
179 |
|
180 void operator_comparison_data() |
|
181 { |
|
182 addTestData_update(); |
|
183 } |
|
184 |
|
185 void operator_assign() |
|
186 { |
|
187 QFETCH(QGeoSatelliteInfo, info); |
|
188 |
|
189 QGeoSatelliteInfo info2 = info; |
|
190 QCOMPARE(info2, info); |
|
191 } |
|
192 |
|
193 void operator_assign_data() |
|
194 { |
|
195 addTestData_update(); |
|
196 } |
|
197 |
|
198 void setPrnNumber() |
|
199 { |
|
200 QFETCH(int, prn); |
|
201 |
|
202 QGeoSatelliteInfo info; |
|
203 QCOMPARE(info.prnNumber(), -1); |
|
204 |
|
205 info.setPrnNumber(prn); |
|
206 QCOMPARE(info.prnNumber(), prn); |
|
207 } |
|
208 |
|
209 void setPrnNumber_data() |
|
210 { |
|
211 QTest::addColumn<int>("prn"); |
|
212 |
|
213 QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); |
|
214 for (int i=0; i<intValues.count(); i++) |
|
215 QTest::newRow(qPrintable(QString("%1").arg(intValues[i]))) << intValues[i]; |
|
216 } |
|
217 |
|
218 void setSignalStrength() |
|
219 { |
|
220 QFETCH(int, signal); |
|
221 |
|
222 QGeoSatelliteInfo info; |
|
223 QCOMPARE(info.signalStrength(), -1); |
|
224 |
|
225 info.setSignalStrength(signal); |
|
226 QCOMPARE(info.signalStrength(), signal); |
|
227 } |
|
228 |
|
229 void setSignalStrength_data() |
|
230 { |
|
231 QTest::addColumn<int>("signal"); |
|
232 |
|
233 QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); |
|
234 for (int i=0; i<intValues.count(); i++) |
|
235 QTest::newRow(qPrintable(QString("%1").arg(intValues[i]))) << intValues[i]; |
|
236 } |
|
237 |
|
238 void attribute() |
|
239 { |
|
240 QFETCH(QGeoSatelliteInfo::Attribute, attribute); |
|
241 QFETCH(qreal, value); |
|
242 |
|
243 QGeoSatelliteInfo u; |
|
244 QCOMPARE(u.attribute(attribute), qreal(-1.0)); |
|
245 |
|
246 u.setAttribute(attribute, value); |
|
247 QCOMPARE(u.attribute(attribute), value); |
|
248 |
|
249 u.removeAttribute(attribute); |
|
250 QCOMPARE(u.attribute(attribute), qreal(-1.0)); |
|
251 } |
|
252 |
|
253 void attribute_data() |
|
254 { |
|
255 QTest::addColumn<QGeoSatelliteInfo::Attribute>("attribute"); |
|
256 QTest::addColumn<qreal>("value"); |
|
257 |
|
258 QList<QGeoSatelliteInfo::Attribute> props; |
|
259 props << QGeoSatelliteInfo::Elevation |
|
260 << QGeoSatelliteInfo::Azimuth; |
|
261 for (int i=0; i<props.count(); i++) { |
|
262 QTest::newRow(QTest::toString("attribute " + props[i])) << props[i] << qreal(-1.0); |
|
263 QTest::newRow(QTest::toString("attribute " + props[i])) << props[i] << qreal(0.0); |
|
264 QTest::newRow(QTest::toString("attribute " + props[i])) << props[i] << qreal(1.0); |
|
265 } |
|
266 } |
|
267 |
|
268 void hasAttribute() |
|
269 { |
|
270 QFETCH(QGeoSatelliteInfo::Attribute, attribute); |
|
271 QFETCH(qreal, value); |
|
272 |
|
273 QGeoSatelliteInfo u; |
|
274 QVERIFY(!u.hasAttribute(attribute)); |
|
275 |
|
276 u.setAttribute(attribute, value); |
|
277 QVERIFY(u.hasAttribute(attribute)); |
|
278 |
|
279 u.removeAttribute(attribute); |
|
280 QVERIFY(!u.hasAttribute(attribute)); |
|
281 } |
|
282 |
|
283 void hasAttribute_data() |
|
284 { |
|
285 attribute_data(); |
|
286 } |
|
287 |
|
288 void removeAttribute() |
|
289 { |
|
290 QFETCH(QGeoSatelliteInfo::Attribute, attribute); |
|
291 QFETCH(qreal, value); |
|
292 |
|
293 QGeoSatelliteInfo u; |
|
294 QVERIFY(!u.hasAttribute(attribute)); |
|
295 |
|
296 u.setAttribute(attribute, value); |
|
297 QVERIFY(u.hasAttribute(attribute)); |
|
298 |
|
299 u.removeAttribute(attribute); |
|
300 QVERIFY(!u.hasAttribute(attribute)); |
|
301 |
|
302 u.setAttribute(attribute, value); |
|
303 QVERIFY(u.hasAttribute(attribute)); |
|
304 } |
|
305 |
|
306 void removeAttribute_data() |
|
307 { |
|
308 attribute_data(); |
|
309 } |
|
310 |
|
311 void datastream() |
|
312 { |
|
313 QFETCH(QGeoSatelliteInfo, info); |
|
314 |
|
315 QByteArray ba; |
|
316 QDataStream out(&ba, QIODevice::WriteOnly); |
|
317 out << info; |
|
318 |
|
319 QDataStream in(&ba, QIODevice::ReadOnly); |
|
320 QGeoSatelliteInfo inInfo; |
|
321 in >> inInfo; |
|
322 QCOMPARE(inInfo, info); |
|
323 } |
|
324 |
|
325 void datastream_data() |
|
326 { |
|
327 addTestData_update(); |
|
328 } |
|
329 |
|
330 void debug() |
|
331 { |
|
332 QFETCH(QGeoSatelliteInfo, info); |
|
333 QFETCH(QByteArray, debugString); |
|
334 |
|
335 qInstallMsgHandler(tst_qgeosatelliteinfo_messageHandler); |
|
336 qDebug() << info; |
|
337 qInstallMsgHandler(0); |
|
338 QCOMPARE(QString(tst_qgeosatelliteinfo_debug), QString(debugString)); |
|
339 } |
|
340 |
|
341 void debug_data() |
|
342 { |
|
343 QTest::addColumn<QGeoSatelliteInfo>("info"); |
|
344 QTest::addColumn<QByteArray>("debugString"); |
|
345 |
|
346 QGeoSatelliteInfo info; |
|
347 |
|
348 QTest::newRow("uninitialized") << info |
|
349 << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1)"); |
|
350 |
|
351 info = QGeoSatelliteInfo(); |
|
352 info.setPrnNumber(1); |
|
353 QTest::newRow("with PRN") << info |
|
354 << QByteArray("QGeoSatelliteInfo(PRN=1, signal-strength=-1)"); |
|
355 |
|
356 info = QGeoSatelliteInfo(); |
|
357 info.setSignalStrength(1); |
|
358 QTest::newRow("with PRN") << info |
|
359 << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=1)"); |
|
360 |
|
361 info = QGeoSatelliteInfo(); |
|
362 info.setAttribute(QGeoSatelliteInfo::Elevation, 1.1); |
|
363 QTest::newRow("with Elevation") << info |
|
364 << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1, Elevation=1.1)"); |
|
365 |
|
366 info = QGeoSatelliteInfo(); |
|
367 info.setAttribute(QGeoSatelliteInfo::Azimuth, 1.1); |
|
368 QTest::newRow("with Azimuth") << info |
|
369 << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1, Azimuth=1.1)"); |
|
370 } |
|
371 }; |
|
372 |
|
373 |
|
374 QTEST_MAIN(tst_QGeoSatelliteInfo) |
|
375 #include "tst_qgeosatelliteinfo.moc" |