|
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 |
|
42 #include <QTest> |
|
43 #include <QMetaType> |
|
44 #include <QSignalSpy> |
|
45 #include <QDebug> |
|
46 #include <QTimer> |
|
47 |
|
48 #include <limits.h> |
|
49 |
|
50 #include <qnumeric.h> |
|
51 #include <qgeopositioninfosource.h> |
|
52 #include <qgeopositioninfo.h> |
|
53 |
|
54 #include "testqgeopositioninfosource_p.h" |
|
55 #include "qlocationtestutils_p.h" |
|
56 |
|
57 |
|
58 Q_DECLARE_METATYPE(QGeoPositionInfoSource::PositioningMethod) |
|
59 Q_DECLARE_METATYPE(QGeoPositionInfoSource::PositioningMethods) |
|
60 Q_DECLARE_METATYPE(QGeoPositionInfo) |
|
61 |
|
62 #define MAX_WAITING_TIME 50000 |
|
63 |
|
64 // Must provide a valid source, unless testing the source |
|
65 // returned by QGeoPositionInfoSource::createDefaultSource() on a system |
|
66 // that has no default source |
|
67 #define CHECK_SOURCE_VALID { \ |
|
68 if (!m_source) { \ |
|
69 if (m_testingDefaultSource && QGeoPositionInfoSource::createDefaultSource(0) == 0) \ |
|
70 QSKIP("No default position source on this system", SkipAll); \ |
|
71 else \ |
|
72 QFAIL("createTestSource() must return a valid source!"); \ |
|
73 } \ |
|
74 } |
|
75 |
|
76 class MyPositionSource : public QGeoPositionInfoSource |
|
77 { |
|
78 Q_OBJECT |
|
79 public: |
|
80 MyPositionSource(QObject *parent = 0) |
|
81 : QGeoPositionInfoSource(parent) { |
|
82 } |
|
83 |
|
84 QGeoPositionInfo lastKnownPosition(bool /*fromSatellitePositioningMethodsOnly = false*/) const { |
|
85 return QGeoPositionInfo(); |
|
86 } |
|
87 |
|
88 void setSupportedPositioningMethods(PositioningMethods methods) { |
|
89 m_methods = methods; |
|
90 } |
|
91 |
|
92 virtual PositioningMethods supportedPositioningMethods() const { |
|
93 return m_methods; |
|
94 } |
|
95 virtual int minimumUpdateInterval() const { |
|
96 return 0; |
|
97 } |
|
98 |
|
99 virtual void startUpdates() {} |
|
100 virtual void stopUpdates() {} |
|
101 |
|
102 virtual void requestUpdate(int) {} |
|
103 |
|
104 private: |
|
105 PositioningMethods m_methods; |
|
106 }; |
|
107 |
|
108 class DefaultSourceTest : public TestQGeoPositionInfoSource |
|
109 { |
|
110 Q_OBJECT |
|
111 protected: |
|
112 QGeoPositionInfoSource *createTestSource() { |
|
113 return QGeoPositionInfoSource::createDefaultSource(0); |
|
114 } |
|
115 }; |
|
116 |
|
117 |
|
118 TestQGeoPositionInfoSource::TestQGeoPositionInfoSource(QObject *parent) |
|
119 : QObject(parent) |
|
120 { |
|
121 m_testingDefaultSource = false; |
|
122 } |
|
123 |
|
124 TestQGeoPositionInfoSource *TestQGeoPositionInfoSource::createDefaultSourceTest() |
|
125 { |
|
126 DefaultSourceTest *test = new DefaultSourceTest; |
|
127 test->m_testingDefaultSource = true; |
|
128 return test; |
|
129 } |
|
130 |
|
131 void TestQGeoPositionInfoSource::test_slot1() |
|
132 { |
|
133 } |
|
134 |
|
135 void TestQGeoPositionInfoSource::test_slot2() |
|
136 { |
|
137 m_testSlot2Called = true; |
|
138 } |
|
139 |
|
140 void TestQGeoPositionInfoSource::base_initTestCase() |
|
141 { |
|
142 qRegisterMetaType<QGeoPositionInfo>(); |
|
143 } |
|
144 |
|
145 void TestQGeoPositionInfoSource::base_init() |
|
146 { |
|
147 m_source = createTestSource(); |
|
148 m_testSlot2Called = false; |
|
149 } |
|
150 |
|
151 void TestQGeoPositionInfoSource::base_cleanup() |
|
152 { |
|
153 delete m_source; |
|
154 m_source = 0; |
|
155 } |
|
156 |
|
157 void TestQGeoPositionInfoSource::base_cleanupTestCase() |
|
158 { |
|
159 } |
|
160 |
|
161 void TestQGeoPositionInfoSource::initTestCase() |
|
162 { |
|
163 base_initTestCase(); |
|
164 } |
|
165 |
|
166 void TestQGeoPositionInfoSource::init() |
|
167 { |
|
168 base_init(); |
|
169 } |
|
170 |
|
171 void TestQGeoPositionInfoSource::cleanup() |
|
172 { |
|
173 base_cleanup(); |
|
174 } |
|
175 |
|
176 void TestQGeoPositionInfoSource::cleanupTestCase() |
|
177 { |
|
178 base_cleanupTestCase(); |
|
179 } |
|
180 |
|
181 // TC_ID_3_x_1 |
|
182 void TestQGeoPositionInfoSource::constructor_withParent() |
|
183 { |
|
184 //QLocationTestUtils::uheap_mark(); |
|
185 QObject *parent = new QObject(); |
|
186 new MyPositionSource(parent); |
|
187 delete parent; |
|
188 //QLocationTestUtils::uheap_mark_end(); |
|
189 } |
|
190 |
|
191 // TC_ID_3_x_2 |
|
192 void TestQGeoPositionInfoSource::constructor_noParent() |
|
193 { |
|
194 //QLocationTestUtils::uheap_mark(); |
|
195 MyPositionSource *obj = new MyPositionSource(); |
|
196 delete obj; |
|
197 //QLocationTestUtils::uheap_mark_end(); |
|
198 } |
|
199 |
|
200 void TestQGeoPositionInfoSource::updateInterval() |
|
201 { |
|
202 MyPositionSource s; |
|
203 QCOMPARE(s.updateInterval(), 0); |
|
204 } |
|
205 |
|
206 void TestQGeoPositionInfoSource::setPreferredPositioningMethods() |
|
207 { |
|
208 QFETCH(int, supported); |
|
209 QFETCH(int, preferred); |
|
210 QFETCH(int, resulting); |
|
211 |
|
212 MyPositionSource s; |
|
213 s.setSupportedPositioningMethods( |
|
214 static_cast<QGeoPositionInfoSource::PositioningMethods>(supported)); |
|
215 s.setPreferredPositioningMethods( |
|
216 static_cast<QGeoPositionInfoSource::PositioningMethods>(preferred)); |
|
217 QCOMPARE(s.preferredPositioningMethods(), |
|
218 static_cast<QGeoPositionInfoSource::PositioningMethods>(resulting)); |
|
219 } |
|
220 |
|
221 void TestQGeoPositionInfoSource::setPreferredPositioningMethods_data() |
|
222 { |
|
223 QTest::addColumn<int>("supported"); |
|
224 QTest::addColumn<int>("preferred"); |
|
225 QTest::addColumn<int>("resulting"); |
|
226 |
|
227 QTest::newRow("Sat supported, Sat preferred") |
|
228 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
229 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
230 << int(QGeoPositionInfoSource::SatellitePositioningMethods); |
|
231 QTest::newRow("Sat supported, Non-Sat prefered") |
|
232 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
233 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
234 << int(QGeoPositionInfoSource::SatellitePositioningMethods); |
|
235 QTest::newRow("Sat supported, All prefered") |
|
236 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
237 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
238 << int(QGeoPositionInfoSource::SatellitePositioningMethods); |
|
239 |
|
240 QTest::newRow("Non-Sat supported, Sat preferred") |
|
241 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
242 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
243 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods); |
|
244 QTest::newRow("Non-Sat supported, Non-Sat prefered") |
|
245 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
246 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
247 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods); |
|
248 QTest::newRow("Non-Sat supported, All prefered") |
|
249 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
250 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
251 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods); |
|
252 |
|
253 QTest::newRow("All supported, Sat preferred") |
|
254 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
255 << int(QGeoPositionInfoSource::SatellitePositioningMethods) |
|
256 << int(QGeoPositionInfoSource::SatellitePositioningMethods); |
|
257 QTest::newRow("All supported, Non-Sat prefered") |
|
258 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
259 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) |
|
260 << int(QGeoPositionInfoSource::NonSatellitePositioningMethods); |
|
261 QTest::newRow("All supported, All prefered") |
|
262 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
263 << int(QGeoPositionInfoSource::AllPositioningMethods) |
|
264 << int(QGeoPositionInfoSource::AllPositioningMethods); |
|
265 } |
|
266 |
|
267 void TestQGeoPositionInfoSource::preferredPositioningMethods() |
|
268 { |
|
269 MyPositionSource s; |
|
270 QCOMPARE(s.preferredPositioningMethods(), 0); |
|
271 } |
|
272 |
|
273 //TC_ID_3_x_1 : Create a position source with the given parent that reads from the system's default |
|
274 // sources of location data |
|
275 void TestQGeoPositionInfoSource::createDefaultSource() |
|
276 { |
|
277 //QLocationTestUtils::uheap_mark(); |
|
278 QObject *parent = new QObject; |
|
279 |
|
280 QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(parent); |
|
281 #if defined(Q_OS_SYMBIAN) |
|
282 QVERIFY(source != 0); |
|
283 #elif defined(Q_OS_WINCE) |
|
284 QVERIFY(source != 0); |
|
285 #elif defined(Q_WS_MAEMO_5) |
|
286 QVERIFY(source != 0); |
|
287 #else |
|
288 QVERIFY(source == 0); |
|
289 #endif |
|
290 delete parent; |
|
291 //QLocationTestUtils::uheap_mark_end(); |
|
292 } |
|
293 |
|
294 void TestQGeoPositionInfoSource::setUpdateInterval() |
|
295 { |
|
296 CHECK_SOURCE_VALID; |
|
297 |
|
298 QFETCH(int, interval); |
|
299 QFETCH(int, expectedInterval); |
|
300 |
|
301 m_source->setUpdateInterval(interval); |
|
302 QCOMPARE(m_source->updateInterval(), expectedInterval); |
|
303 } |
|
304 |
|
305 void TestQGeoPositionInfoSource::setUpdateInterval_data() |
|
306 { |
|
307 QTest::addColumn<int>("interval"); |
|
308 QTest::addColumn<int>("expectedInterval"); |
|
309 |
|
310 QGeoPositionInfoSource *source = createTestSource(); |
|
311 int minUpdateInterval = source ? source->minimumUpdateInterval() : -1; |
|
312 if (source) |
|
313 delete source; |
|
314 |
|
315 QTest::newRow("0") << 0 << 0; |
|
316 |
|
317 if (minUpdateInterval > -1) { |
|
318 QTest::newRow("INT_MIN") << INT_MIN << minUpdateInterval; |
|
319 QTest::newRow("-1") << -1 << minUpdateInterval; |
|
320 } |
|
321 |
|
322 if (minUpdateInterval > 0) { |
|
323 QTest::newRow("more than minInterval") << minUpdateInterval + 1 << minUpdateInterval + 1; |
|
324 QTest::newRow("equal to minInterval") << minUpdateInterval << minUpdateInterval; |
|
325 } |
|
326 |
|
327 if (minUpdateInterval > 1) { |
|
328 QTest::newRow("less then minInterval") << minUpdateInterval - 1 << minUpdateInterval; |
|
329 QTest::newRow("in btw zero and minInterval") << 1 << minUpdateInterval; |
|
330 } |
|
331 |
|
332 // Fails on S60, should investigate |
|
333 //QTest::newRow("INT_MAX") << INT_MAX << INT_MAX; |
|
334 } |
|
335 |
|
336 void TestQGeoPositionInfoSource::lastKnownPosition() |
|
337 { |
|
338 CHECK_SOURCE_VALID; |
|
339 |
|
340 QFETCH(int, positioningMethod); |
|
341 QFETCH(bool, lastKnownPositionArgument); |
|
342 QFETCH(bool, positionValid); |
|
343 |
|
344 QGeoPositionInfoSource::PositioningMethods method |
|
345 = static_cast<QGeoPositionInfoSource::PositioningMethods>(positioningMethod); |
|
346 |
|
347 if ((m_source->supportedPositioningMethods() & method) == 0) |
|
348 QSKIP("Not a supported positioning method for this position source", SkipSingle); |
|
349 |
|
350 m_source->setPreferredPositioningMethods(method); |
|
351 |
|
352 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
353 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
354 int time_out = 7000; |
|
355 m_source->setUpdateInterval(time_out); |
|
356 m_source->startUpdates(); |
|
357 |
|
358 // Use QEventLoop instead of qWait() to ensure we stop as soon as a |
|
359 // position is emitted (otherwise the lastKnownPosition() may have |
|
360 // changed by the time it is checked) |
|
361 QEventLoop loop; |
|
362 QTimer timer; |
|
363 timer.setInterval(9500); |
|
364 connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)), |
|
365 &loop, SLOT(quit())); |
|
366 connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); |
|
367 timer.start(); |
|
368 loop.exec(); |
|
369 |
|
370 EXPECT_FAIL_WINCE_SEE_MOBILITY_337_ABORT; |
|
371 |
|
372 QVERIFY((spy.count() > 0) && (timeout.count() == 0)); |
|
373 |
|
374 QList<QVariant> list = spy.takeFirst(); |
|
375 QGeoPositionInfo info; |
|
376 info = list.at(0).value<QGeoPositionInfo>(); |
|
377 QGeoPositionInfo lastPositioninfo; |
|
378 lastPositioninfo = m_source->lastKnownPosition(lastKnownPositionArgument); |
|
379 |
|
380 QCOMPARE(lastPositioninfo.isValid(), positionValid); |
|
381 |
|
382 if (positionValid) { |
|
383 QCOMPARE(info.coordinate(), lastPositioninfo.coordinate()); |
|
384 QCOMPARE(info.timestamp(), lastPositioninfo.timestamp()); |
|
385 |
|
386 QCOMPARE(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy), |
|
387 lastPositioninfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)); |
|
388 |
|
389 if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { |
|
390 bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::HorizontalAccuracy)); |
|
391 bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)); |
|
392 QCOMPARE(isNaN1, isNaN2); |
|
393 if (!isNaN1) { |
|
394 QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy), |
|
395 lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)), TRUE); |
|
396 } |
|
397 } |
|
398 |
|
399 QCOMPARE(info.hasAttribute(QGeoPositionInfo::VerticalAccuracy), |
|
400 lastPositioninfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy)); |
|
401 |
|
402 if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { |
|
403 bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::VerticalAccuracy)); |
|
404 bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)); |
|
405 QCOMPARE(isNaN1, isNaN2); |
|
406 if (!isNaN1) { |
|
407 QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy), |
|
408 lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)), TRUE); |
|
409 } |
|
410 } |
|
411 } |
|
412 |
|
413 m_source->stopUpdates(); |
|
414 } |
|
415 |
|
416 void TestQGeoPositionInfoSource::lastKnownPosition_data() |
|
417 { |
|
418 QTest::addColumn<int>("positioningMethod"); |
|
419 QTest::addColumn<bool>("lastKnownPositionArgument"); |
|
420 QTest::addColumn<bool>("positionValid"); |
|
421 |
|
422 QTest::newRow("satellite - false") << int(QGeoPositionInfoSource::SatellitePositioningMethods) << false << true; |
|
423 QTest::newRow("satellite - true") << int(QGeoPositionInfoSource::SatellitePositioningMethods) << true << true; |
|
424 QTest::newRow("nonsatellite - false") << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) << false << false; |
|
425 QTest::newRow("nonsatellite - true") << int(QGeoPositionInfoSource::NonSatellitePositioningMethods) << true << true; |
|
426 QTest::newRow("all - false") << int(QGeoPositionInfoSource::AllPositioningMethods) << false << true; |
|
427 QTest::newRow("all - true") << int(QGeoPositionInfoSource::AllPositioningMethods) << true << true; |
|
428 } |
|
429 |
|
430 void TestQGeoPositionInfoSource::minimumUpdateInterval() |
|
431 { |
|
432 CHECK_SOURCE_VALID; |
|
433 |
|
434 QVERIFY(m_source->minimumUpdateInterval() > 0); |
|
435 } |
|
436 |
|
437 //TC_ID_3_x_1 |
|
438 void TestQGeoPositionInfoSource::startUpdates_testIntervals() |
|
439 { |
|
440 CHECK_SOURCE_VALID; |
|
441 |
|
442 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
443 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
444 m_source->setUpdateInterval(7000); |
|
445 int interval = m_source->updateInterval(); |
|
446 |
|
447 m_source->startUpdates(); |
|
448 |
|
449 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
450 |
|
451 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 9500); |
|
452 for (int i = 0; i < 6; i++) { |
|
453 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
454 |
|
455 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), (interval*2)); |
|
456 spy.clear(); |
|
457 } |
|
458 |
|
459 m_source->stopUpdates(); |
|
460 } |
|
461 |
|
462 |
|
463 void TestQGeoPositionInfoSource::startUpdates_testIntervalChangesWhileRunning() |
|
464 { |
|
465 // There are two ways of dealing with an interval change, and we have left it system dependent. |
|
466 // The interval can be changed will running or after the next update. |
|
467 // WinCE uses the first method, S60 uses the second method. |
|
468 |
|
469 // The minimum interval on the symbian emulator is 5000 msecs, which is why the times in |
|
470 // this test are as high as they are. |
|
471 |
|
472 CHECK_SOURCE_VALID; |
|
473 |
|
474 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
475 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
476 m_source->setUpdateInterval(0); |
|
477 m_source->startUpdates(); |
|
478 m_source->setUpdateInterval(0); |
|
479 |
|
480 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
481 |
|
482 QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 7000); |
|
483 QCOMPARE(timeout.count(), 0); |
|
484 spy.clear(); |
|
485 |
|
486 m_source->setUpdateInterval(5000); |
|
487 |
|
488 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
489 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000); |
|
490 spy.clear(); |
|
491 |
|
492 m_source->setUpdateInterval(10000); |
|
493 |
|
494 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
495 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 30000); |
|
496 spy.clear(); |
|
497 |
|
498 m_source->setUpdateInterval(5000); |
|
499 |
|
500 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
501 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000); |
|
502 spy.clear(); |
|
503 |
|
504 m_source->setUpdateInterval(5000); |
|
505 |
|
506 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
507 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000); |
|
508 spy.clear(); |
|
509 |
|
510 m_source->setUpdateInterval(0); |
|
511 |
|
512 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
513 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), 7000); |
|
514 spy.clear(); |
|
515 |
|
516 m_source->setUpdateInterval(0); |
|
517 |
|
518 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
519 QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), 7000); |
|
520 spy.clear(); |
|
521 |
|
522 m_source->stopUpdates(); |
|
523 } |
|
524 |
|
525 //TC_ID_3_x_2 |
|
526 void TestQGeoPositionInfoSource::startUpdates_testDefaultInterval() |
|
527 { |
|
528 CHECK_SOURCE_VALID; |
|
529 |
|
530 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
531 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
532 m_source->startUpdates(); |
|
533 for (int i = 0; i < 3; i++) { |
|
534 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
535 |
|
536 QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000); |
|
537 spy.clear(); |
|
538 } |
|
539 m_source->stopUpdates(); |
|
540 } |
|
541 |
|
542 //TC_ID_3_x_3 |
|
543 void TestQGeoPositionInfoSource::startUpdates_testZeroInterval() |
|
544 { |
|
545 CHECK_SOURCE_VALID; |
|
546 |
|
547 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
548 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
549 m_source->setUpdateInterval(0); |
|
550 m_source->startUpdates(); |
|
551 for (int i = 0; i < 3; i++) { |
|
552 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
553 |
|
554 QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000); |
|
555 spy.clear(); |
|
556 } |
|
557 m_source->stopUpdates(); |
|
558 } |
|
559 |
|
560 void TestQGeoPositionInfoSource::startUpdates_moreThanOnce() |
|
561 { |
|
562 CHECK_SOURCE_VALID; |
|
563 |
|
564 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
565 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
566 m_source->setUpdateInterval(0); |
|
567 m_source->startUpdates(); |
|
568 |
|
569 m_source->startUpdates(); // check there is no crash |
|
570 |
|
571 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
572 |
|
573 QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000); |
|
574 |
|
575 m_source->startUpdates(); // check there is no crash |
|
576 |
|
577 m_source->stopUpdates(); |
|
578 } |
|
579 |
|
580 //TC_ID_3_x_1 |
|
581 void TestQGeoPositionInfoSource::stopUpdates() |
|
582 { |
|
583 CHECK_SOURCE_VALID; |
|
584 |
|
585 QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
586 QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); |
|
587 m_source->setUpdateInterval(7000); |
|
588 m_source->startUpdates(); |
|
589 for (int i = 0; i < 2; i++) { |
|
590 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
591 |
|
592 QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 9500); |
|
593 spy.clear(); |
|
594 } |
|
595 m_source->stopUpdates(); |
|
596 QTest::qWait(9500); |
|
597 QCOMPARE(spy.count(), 0); |
|
598 spy.clear(); |
|
599 |
|
600 m_source->setUpdateInterval(0); |
|
601 m_source->startUpdates(); |
|
602 m_source->stopUpdates(); |
|
603 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 0, 9500); |
|
604 } |
|
605 |
|
606 //TC_ID_3_x_2 |
|
607 void TestQGeoPositionInfoSource::stopUpdates_withoutStart() |
|
608 { |
|
609 CHECK_SOURCE_VALID; |
|
610 |
|
611 m_source->stopUpdates(); // check there is no crash |
|
612 } |
|
613 |
|
614 void TestQGeoPositionInfoSource::requestUpdate() |
|
615 { |
|
616 CHECK_SOURCE_VALID; |
|
617 |
|
618 QFETCH(int, timeout); |
|
619 QSignalSpy spy(m_source, SIGNAL(updateTimeout())); |
|
620 m_source->requestUpdate(timeout); |
|
621 QTRY_COMPARE(spy.count(), 1); |
|
622 } |
|
623 |
|
624 void TestQGeoPositionInfoSource::requestUpdate_data() |
|
625 { |
|
626 QTest::addColumn<int>("timeout"); |
|
627 QTest::newRow("less than zero") << -1; //TC_ID_3_x_7 |
|
628 } |
|
629 |
|
630 // TC_ID_3_x_1 : Create position source and call requestUpdate with valid timeout value |
|
631 void TestQGeoPositionInfoSource::requestUpdate_validTimeout() |
|
632 { |
|
633 CHECK_SOURCE_VALID; |
|
634 |
|
635 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
636 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
637 |
|
638 m_source->requestUpdate(7000); |
|
639 |
|
640 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
641 |
|
642 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
643 } |
|
644 |
|
645 void TestQGeoPositionInfoSource::requestUpdate_defaultTimeout() |
|
646 { |
|
647 CHECK_SOURCE_VALID; |
|
648 |
|
649 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
650 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
651 |
|
652 m_source->requestUpdate(0); |
|
653 |
|
654 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
655 |
|
656 // S60 emulator fail |
|
657 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
658 } |
|
659 |
|
660 // TC_ID_3_x_2 : Create position source and call requestUpdate with a timeout less than |
|
661 // minimumupdateInterval |
|
662 void TestQGeoPositionInfoSource::requestUpdate_timeoutLessThanMinimumInterval() |
|
663 { |
|
664 CHECK_SOURCE_VALID; |
|
665 |
|
666 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
667 m_source->requestUpdate(1); |
|
668 |
|
669 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
670 |
|
671 QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 1, 1000); |
|
672 } |
|
673 |
|
674 // TC_ID_3_x_3 : Call requestUpdate() with same value repeatedly |
|
675 void TestQGeoPositionInfoSource::requestUpdate_repeatedCalls() |
|
676 { |
|
677 CHECK_SOURCE_VALID; |
|
678 |
|
679 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
680 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
681 |
|
682 m_source->requestUpdate(7000); |
|
683 |
|
684 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
685 |
|
686 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
687 spyUpdate.clear(); |
|
688 m_source->requestUpdate(7000); |
|
689 |
|
690 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
691 |
|
692 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
693 } |
|
694 |
|
695 void TestQGeoPositionInfoSource::requestUpdate_overlappingCalls() |
|
696 { |
|
697 CHECK_SOURCE_VALID; |
|
698 |
|
699 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
700 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
701 |
|
702 m_source->requestUpdate(7000); |
|
703 m_source->requestUpdate(7000); |
|
704 |
|
705 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
706 |
|
707 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
708 } |
|
709 |
|
710 //TC_ID_3_x_4 |
|
711 void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_ZeroInterval() |
|
712 { |
|
713 CHECK_SOURCE_VALID; |
|
714 |
|
715 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
716 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
717 |
|
718 m_source->setUpdateInterval(0); |
|
719 m_source->startUpdates(); |
|
720 |
|
721 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
722 |
|
723 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
724 spyUpdate.clear(); |
|
725 |
|
726 m_source->requestUpdate(7000); |
|
727 QTest::qWait(7000); |
|
728 |
|
729 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
730 |
|
731 QVERIFY((spyUpdate.count() > 0) && (spyTimeout.count() == 0)); |
|
732 spyUpdate.clear(); |
|
733 |
|
734 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
735 |
|
736 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), MAX_WAITING_TIME); |
|
737 |
|
738 m_source->stopUpdates(); |
|
739 } |
|
740 |
|
741 void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_SmallInterval() |
|
742 { |
|
743 CHECK_SOURCE_VALID; |
|
744 |
|
745 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
746 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
747 |
|
748 m_source->setUpdateInterval(10000); |
|
749 m_source->startUpdates(); |
|
750 |
|
751 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
752 |
|
753 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 20000); |
|
754 spyUpdate.clear(); |
|
755 |
|
756 m_source->requestUpdate(7000); |
|
757 |
|
758 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
759 |
|
760 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 7000); |
|
761 spyUpdate.clear(); |
|
762 |
|
763 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
764 |
|
765 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 20000); |
|
766 |
|
767 m_source->stopUpdates(); |
|
768 } |
|
769 |
|
770 void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_ZeroInterval() |
|
771 { |
|
772 CHECK_SOURCE_VALID; |
|
773 |
|
774 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
775 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
776 |
|
777 m_source->requestUpdate(7000); |
|
778 |
|
779 m_source->setUpdateInterval(0); |
|
780 m_source->startUpdates(); |
|
781 |
|
782 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
783 |
|
784 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() >= 2) && (spyTimeout.count() == 0), 14000); |
|
785 spyUpdate.clear(); |
|
786 |
|
787 QTest::qWait(7000); |
|
788 |
|
789 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
790 |
|
791 QCOMPARE(spyTimeout.count(), 0); |
|
792 |
|
793 m_source->stopUpdates(); |
|
794 } |
|
795 |
|
796 void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_SmallInterval() |
|
797 { |
|
798 CHECK_SOURCE_VALID; |
|
799 |
|
800 QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); |
|
801 QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); |
|
802 |
|
803 m_source->requestUpdate(7000); |
|
804 |
|
805 m_source->setUpdateInterval(10000); |
|
806 m_source->startUpdates(); |
|
807 |
|
808 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
809 |
|
810 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000); |
|
811 spyUpdate.clear(); |
|
812 |
|
813 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
814 |
|
815 QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 20000); |
|
816 |
|
817 m_source->stopUpdates(); |
|
818 } |
|
819 |
|
820 void TestQGeoPositionInfoSource::removeSlotForRequestTimeout() |
|
821 { |
|
822 CHECK_SOURCE_VALID; |
|
823 |
|
824 bool i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1())); |
|
825 QVERIFY(i == true); |
|
826 i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot2())); |
|
827 QVERIFY(i == true); |
|
828 i = disconnect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1())); |
|
829 QVERIFY(i == true); |
|
830 |
|
831 m_source->requestUpdate(-1); |
|
832 QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 1000); |
|
833 } |
|
834 |
|
835 void TestQGeoPositionInfoSource::removeSlotForPositionUpdated() |
|
836 { |
|
837 CHECK_SOURCE_VALID; |
|
838 |
|
839 bool i = connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(test_slot1())); |
|
840 QVERIFY(i == true); |
|
841 i = connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(test_slot2())); |
|
842 QVERIFY(i == true); |
|
843 i = disconnect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(test_slot1())); |
|
844 QVERIFY(i == true); |
|
845 |
|
846 m_source->requestUpdate(7000); |
|
847 |
|
848 EXPECT_FAIL_WINCE_SEE_MOBILITY_337; |
|
849 |
|
850 QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 7000); |
|
851 } |
|
852 |
|
853 #include "testqgeopositioninfosource.moc" |