113 |
113 |
114 // If an update is received and startUpdates() or requestUpdate() hasn't |
114 // If an update is received and startUpdates() or requestUpdate() hasn't |
115 // been called, it should still be available through lastKnownPosition() |
115 // been called, it should still be available through lastKnownPosition() |
116 QDateTime dt = QDateTime::currentDateTime().toUTC(); |
116 QDateTime dt = QDateTime::currentDateTime().toUTC(); |
117 proxy->feedUpdate(dt); |
117 proxy->feedUpdate(dt); |
118 QTRY_COMPARE(proxy->source()->lastKnownPosition().dateTime(), dt); |
118 QTRY_COMPARE(proxy->source()->lastKnownPosition().timestamp(), dt); |
119 |
119 |
120 QList<QDateTime> dateTimes = createDateTimes(5); |
120 QList<QDateTime> dateTimes = createDateTimes(5); |
121 for (int i=0; i<dateTimes.count(); i++) { |
121 for (int i=0; i<dateTimes.count(); i++) { |
122 proxy->source()->requestUpdate(); |
122 proxy->source()->requestUpdate(); |
123 proxy->feedUpdate(dateTimes[i]); |
123 proxy->feedUpdate(dateTimes[i]); |
124 QTRY_COMPARE(proxy->source()->lastKnownPosition().dateTime(), dateTimes[i]); |
124 QTRY_COMPARE(proxy->source()->lastKnownPosition().timestamp(), dateTimes[i]); |
125 } |
125 } |
126 |
126 |
127 proxy->source()->startUpdates(); |
127 proxy->source()->startUpdates(); |
128 dateTimes = createDateTimes(5); |
128 dateTimes = createDateTimes(5); |
129 for (int i=0; i<dateTimes.count(); i++) { |
129 for (int i=0; i<dateTimes.count(); i++) { |
130 proxy->feedUpdate(dateTimes[i]); |
130 proxy->feedUpdate(dateTimes[i]); |
131 QTRY_COMPARE(proxy->source()->lastKnownPosition().dateTime(), dateTimes[i]); |
131 QTRY_COMPARE(proxy->source()->lastKnownPosition().timestamp(), dateTimes[i]); |
132 } |
132 } |
133 } |
133 } |
134 |
134 |
135 void tst_QNmeaPositionInfoSource::beginWithBufferedData() |
135 void tst_QNmeaPositionInfoSource::beginWithBufferedData() |
136 { |
136 { |
162 QCOMPARE(spy.count(), 0); |
162 QCOMPARE(spy.count(), 0); |
163 } else { |
163 } else { |
164 if (trigger == StartUpdatesMethod) { |
164 if (trigger == StartUpdatesMethod) { |
165 QTRY_COMPARE(spy.count(), dateTimes.count()); |
165 QTRY_COMPARE(spy.count(), dateTimes.count()); |
166 for (int i=0; i<dateTimes.count(); i++) |
166 for (int i=0; i<dateTimes.count(); i++) |
167 QCOMPARE(spy.at(i).at(0).value<QGeoPositionInfo>().dateTime(), dateTimes[i]); |
167 QCOMPARE(spy.at(i).at(0).value<QGeoPositionInfo>().timestamp(), dateTimes[i]); |
168 } else if (trigger == RequestUpdatesMethod) { |
168 } else if (trigger == RequestUpdatesMethod) { |
169 QTRY_COMPARE(spy.count(), 1); |
169 QTRY_COMPARE(spy.count(), 1); |
170 QCOMPARE(spy.at(0).at(0).value<QGeoPositionInfo>().dateTime(), dateTimes.first()); |
170 QCOMPARE(spy.at(0).at(0).value<QGeoPositionInfo>().timestamp(), dateTimes.first()); |
171 } |
171 } |
172 } |
172 } |
173 } |
173 } |
174 |
174 |
175 void tst_QNmeaPositionInfoSource::beginWithBufferedData_data() |
175 void tst_QNmeaPositionInfoSource::beginWithBufferedData_data() |
227 proxy->source()->startUpdates(); |
227 proxy->source()->startUpdates(); |
228 |
228 |
229 QDateTime dt = QDateTime::currentDateTime().toUTC(); |
229 QDateTime dt = QDateTime::currentDateTime().toUTC(); |
230 |
230 |
231 if (m_mode == QNmeaPositionInfoSource::SimulationMode) { |
231 if (m_mode == QNmeaPositionInfoSource::SimulationMode) { |
|
232 // the first sentence primes the simulation |
232 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt).toLatin1()); |
233 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt).toLatin1()); |
|
234 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addMSecs(50)).toLatin1()); |
233 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(1)).toLatin1()); |
235 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(1)).toLatin1()); |
234 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(2)).toLatin1()); |
236 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(2)).toLatin1()); |
235 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(9)).toLatin1()); |
237 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(9)).toLatin1()); |
236 |
238 |
237 int i = 0; |
239 int i = 0; |
238 |
240 |
239 for (int j = 0; j < 3; ++j) { |
241 for (int j = 0; j < 3; ++j) { |
240 i = 0; |
242 i = 0; |
241 for (; i < 15; ++i) { |
243 for (; i < 12; ++i) { |
242 QTest::qWait(100); |
244 QTest::qWait(100); |
243 if ((spyUpdate.count() == 1) && (spyTimeout.count() == 0)) |
245 if ((spyUpdate.count() == 1) && (spyTimeout.count() == 0)) |
244 break; |
246 break; |
245 } |
247 } |
246 QVERIFY((spyUpdate.count() == 1) && (spyTimeout.count() == 0)); |
248 QVERIFY((spyUpdate.count() == 1) && (spyTimeout.count() == 0)); |
249 QTest::qWait(100); |
251 QTest::qWait(100); |
250 } |
252 } |
251 } |
253 } |
252 |
254 |
253 i = 0; |
255 i = 0; |
254 for (; i < 75; ++i) { |
256 for (; i < 72; ++i) { |
255 QTest::qWait(100); |
257 QTest::qWait(100); |
256 if ((spyUpdate.count() == 0) && (spyTimeout.count() == 1)) |
258 if ((spyUpdate.count() == 0) && (spyTimeout.count() == 1)) |
257 break; |
259 break; |
258 } |
260 } |
259 QVERIFY((spyUpdate.count() == 0) && (spyTimeout.count() == 1)); |
261 QVERIFY((spyUpdate.count() == 0) && (spyTimeout.count() == 1)); |
260 spyTimeout.clear(); |
262 spyTimeout.clear(); |
261 |
263 |
262 for (; i < 75; ++i) { |
264 for (; i < 72; ++i) { |
263 QTest::qWait(100); |
265 QTest::qWait(100); |
264 if ((spyUpdate.count() == 1) && (spyTimeout.count() == 0)) |
266 if ((spyUpdate.count() == 1) && (spyTimeout.count() == 0)) |
265 break; |
267 break; |
266 } |
268 } |
267 QVERIFY((spyUpdate.count() == 1) && (spyTimeout.count() == 0)); |
269 QVERIFY((spyUpdate.count() == 1) && (spyTimeout.count() == 0)); |
|
270 |
268 } else { |
271 } else { |
269 QTest::qWait(900); |
272 QTest::qWait(900); |
270 // dt + 900 |
273 // dt + 900 |
271 QVERIFY(spyUpdate.count() == 0 && spyTimeout.count() == 0); |
274 QVERIFY(spyUpdate.count() == 0 && spyTimeout.count() == 0); |
272 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(1)).toLatin1()); |
275 proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(1)).toLatin1()); |
322 QList<QDateTime> dateTimes = createDateTimes(3); |
325 QList<QDateTime> dateTimes = createDateTimes(3); |
323 for (int i=0; i<dateTimes.count(); i++) |
326 for (int i=0; i<dateTimes.count(); i++) |
324 proxy->feedUpdate(dateTimes[i]); |
327 proxy->feedUpdate(dateTimes[i]); |
325 |
328 |
326 QTRY_COMPARE(spyUpdate.count(), 1); |
329 QTRY_COMPARE(spyUpdate.count(), 1); |
327 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().dateTime(), dateTimes.last()); |
330 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().timestamp(), dateTimes.last()); |
328 } |
331 } |
329 |
332 |
330 void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime() |
333 void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime() |
331 { |
334 { |
332 // Tests that the class does not emit an update until it receives a |
335 // Tests that the class does not emit an update until it receives a |
346 |
349 |
347 proxy->feedBytes(bytes); |
350 proxy->feedBytes(bytes); |
348 QTRY_COMPARE(spy.count(), dateTimes.count()); |
351 QTRY_COMPARE(spy.count(), dateTimes.count()); |
349 |
352 |
350 for (int i=0; i<spy.count(); i++) |
353 for (int i=0; i<spy.count(); i++) |
351 QCOMPARE(spy[i][0].value<QGeoPositionInfo>().dateTime(), dateTimes[i]); |
354 QCOMPARE(spy[i][0].value<QGeoPositionInfo>().timestamp(), dateTimes[i]); |
352 } |
355 } |
353 |
356 |
354 void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime_data() |
357 void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime_data() |
355 { |
358 { |
356 QTest::addColumn<QByteArray>("bytes"); |
359 QTest::addColumn<QByteArray>("bytes"); |
399 QSignalSpy spy(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); |
402 QSignalSpy spy(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); |
400 proxy->source()->requestUpdate(); |
403 proxy->source()->requestUpdate(); |
401 |
404 |
402 proxy->feedBytes(bytes); |
405 proxy->feedBytes(bytes); |
403 QTRY_COMPARE(spy.count(), 1); |
406 QTRY_COMPARE(spy.count(), 1); |
404 QCOMPARE(spy[0][0].value<QGeoPositionInfo>().dateTime(), dateTimes[0]); |
407 QCOMPARE(spy[0][0].value<QGeoPositionInfo>().timestamp(), dateTimes[0]); |
405 } |
408 } |
406 |
409 |
407 void tst_QNmeaPositionInfoSource::requestUpdate_waitForValidDateTime_data() |
410 void tst_QNmeaPositionInfoSource::requestUpdate_waitForValidDateTime_data() |
408 { |
411 { |
409 startUpdates_waitForValidDateTime_data(); |
412 startUpdates_waitForValidDateTime_data(); |
425 |
428 |
426 dt = QDateTime::currentDateTime().toUTC(); |
429 dt = QDateTime::currentDateTime().toUTC(); |
427 proxy->feedUpdate(dt); |
430 proxy->feedUpdate(dt); |
428 proxy->source()->requestUpdate(); |
431 proxy->source()->requestUpdate(); |
429 QTRY_COMPARE(spyUpdate.count(), 1); |
432 QTRY_COMPARE(spyUpdate.count(), 1); |
430 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().dateTime(), dt); |
433 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().timestamp(), dt); |
431 QCOMPARE(spyTimeout.count(), 0); |
434 QCOMPARE(spyTimeout.count(), 0); |
432 spyUpdate.clear(); |
435 spyUpdate.clear(); |
433 |
436 |
434 // delay the update and expect it to be emitted after 300ms |
437 // delay the update and expect it to be emitted after 300ms |
435 dt = QDateTime::currentDateTime().toUTC(); |
438 dt = QDateTime::currentDateTime().toUTC(); |
436 proxy->source()->requestUpdate(1000); |
439 proxy->source()->requestUpdate(1000); |
437 QTest::qWait(300); |
440 QTest::qWait(300); |
438 proxy->feedUpdate(dt); |
441 proxy->feedUpdate(dt); |
439 QTRY_COMPARE(spyUpdate.count(), 1); |
442 QTRY_COMPARE(spyUpdate.count(), 1); |
440 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().dateTime(), dt); |
443 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().timestamp(), dt); |
441 QCOMPARE(spyTimeout.count(), 0); |
444 QCOMPARE(spyTimeout.count(), 0); |
442 spyUpdate.clear(); |
445 spyUpdate.clear(); |
443 |
446 |
444 // delay the update and expect updateTimeout() to be emitted |
447 // delay the update and expect updateTimeout() to be emitted |
445 dt = QDateTime::currentDateTime().toUTC(); |
448 dt = QDateTime::currentDateTime().toUTC(); |
469 proxy->source()->setUpdateInterval(500); |
472 proxy->source()->setUpdateInterval(500); |
470 proxy->source()->startUpdates(); |
473 proxy->source()->startUpdates(); |
471 proxy->source()->requestUpdate(100); |
474 proxy->source()->requestUpdate(100); |
472 proxy->feedUpdate(dt); |
475 proxy->feedUpdate(dt); |
473 QTRY_COMPARE(spyUpdate.count(), 1); |
476 QTRY_COMPARE(spyUpdate.count(), 1); |
474 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().dateTime(), dt); |
477 QCOMPARE(spyUpdate[0][0].value<QGeoPositionInfo>().timestamp(), dt); |
475 QCOMPARE(spyTimeout.count(), 0); |
478 QCOMPARE(spyTimeout.count(), 0); |
476 spyUpdate.clear(); |
479 spyUpdate.clear(); |
477 |
480 |
478 // Update has been emitted for requestUpdate(), shouldn't be emitted for startUpdates() |
481 // Update has been emitted for requestUpdate(), shouldn't be emitted for startUpdates() |
479 QTest::qWait(1000); |
482 QTest::qWait(1000); |
497 proxy->source()->requestUpdate(); |
500 proxy->source()->requestUpdate(); |
498 |
501 |
499 proxy->feedBytes(bytes); |
502 proxy->feedBytes(bytes); |
500 QTRY_COMPARE(spy.count(), dateTimes.count()); |
503 QTRY_COMPARE(spy.count(), dateTimes.count()); |
501 for (int i=0; i<dateTimes.count(); i++) |
504 for (int i=0; i<dateTimes.count(); i++) |
502 QCOMPARE(spy[i][0].value<QGeoPositionInfo>().dateTime(), dateTimes[i]); |
505 QCOMPARE(spy[i][0].value<QGeoPositionInfo>().timestamp(), dateTimes[i]); |
503 } |
506 } |
504 |
507 |
505 void tst_QNmeaPositionInfoSource::testWithBadNmea_data() |
508 void tst_QNmeaPositionInfoSource::testWithBadNmea_data() |
506 { |
509 { |
507 QTest::addColumn<QByteArray>("bytes"); |
510 QTest::addColumn<QByteArray>("bytes"); |