diff options
author | Carsten Bürger <carsten.burger@nokia.com> | 2011-12-02 16:11:19 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-08 00:46:51 +0100 |
commit | 3b00c5c23c56554b9e160c41e619f1c62c9f1757 (patch) | |
tree | ae32b9367f60997c162830b1d709b1a0b1971fbc /tests/auto/qgeosatelliteinfosource | |
parent | 81453d0345d49c492e9becfaefea28d9e156b7fa (diff) | |
download | qtlocation-3b00c5c23c56554b9e160c41e619f1c62c9f1757.tar.gz |
adding updateInterval to qGeoSatelliteInfoSource
Change-Id: I58e4263c3ddb9f4c9d6fc6f805a34acb0de7c863
Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'tests/auto/qgeosatelliteinfosource')
3 files changed, 251 insertions, 12 deletions
diff --git a/tests/auto/qgeosatelliteinfosource/qgeosatelliteinfosource.pro b/tests/auto/qgeosatelliteinfosource/qgeosatelliteinfosource.pro index 9166282d..d4c87f43 100644 --- a/tests/auto/qgeosatelliteinfosource/qgeosatelliteinfosource.pro +++ b/tests/auto/qgeosatelliteinfosource/qgeosatelliteinfosource.pro @@ -10,3 +10,7 @@ HEADERS += testqgeosatelliteinfosource_p.h \ ../qgeocoordinate/qlocationtestutils_p.h QT += location testlib + +contains(config_test_jsondb, yes): contains(config_test_mtcore, yes) { + DEFINES += NPE_BACKEND +} diff --git a/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource.cpp b/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource.cpp index c47e0164..80cc3ed5 100644 --- a/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource.cpp +++ b/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource.cpp @@ -79,6 +79,9 @@ public: virtual void startUpdates() {} virtual void stopUpdates() {} virtual void requestUpdate(int) {} + virtual int minimumUpdateInterval() const { + return 0; + } }; @@ -171,36 +174,194 @@ void TestQGeoSatelliteInfoSource::createDefaultSource() { QObject *parent = new QObject; QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(parent); - - //right now nosource available + // currently only NPE_BACKEND provides a source +#if defined(NPE_BACKEND) + QVERIFY(source != 0); +#else QVERIFY(source == 0); +#endif delete parent; } void TestQGeoSatelliteInfoSource::createDefaultSource_noParent() { QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0); +#if defined(NPE_BACKEND) + QVERIFY(source != 0); +#else QVERIFY(source == 0); +#endif delete source; } -void TestQGeoSatelliteInfoSource::startUpdates() +void TestQGeoSatelliteInfoSource::updateInterval() +{ + MySatelliteSource s; + QCOMPARE(s.updateInterval(), 0); +} + +void TestQGeoSatelliteInfoSource::setUpdateInterval() +{ + CHECK_SOURCE_VALID; + + QFETCH(int, interval); + QFETCH(int, expectedInterval); + + m_source->setUpdateInterval(interval); + QCOMPARE(m_source->updateInterval(), expectedInterval); +} + +void TestQGeoSatelliteInfoSource::setUpdateInterval_data() +{ + QTest::addColumn<int>("interval"); + QTest::addColumn<int>("expectedInterval"); + QGeoSatelliteInfoSource *source = createTestSource(); + int minUpdateInterval = source ? source->minimumUpdateInterval() : -1; + if (source) + delete source; + + QTest::newRow("0") << 0 << 0; + + if (minUpdateInterval > -1) { + QTest::newRow("INT_MIN") << INT_MIN << minUpdateInterval; + QTest::newRow("-1") << -1 << minUpdateInterval; + } + + if (minUpdateInterval > 0) { + QTest::newRow("more than minInterval") << minUpdateInterval + 1 << minUpdateInterval + 1; + QTest::newRow("equal to minInterval") << minUpdateInterval << minUpdateInterval; + } + + if (minUpdateInterval > 1) { + QTest::newRow("less then minInterval") << minUpdateInterval - 1 << minUpdateInterval; + QTest::newRow("in btw zero and minInterval") << 1 << minUpdateInterval; + } +} + +void TestQGeoSatelliteInfoSource::minimumUpdateInterval() { + CHECK_SOURCE_VALID; + QVERIFY(m_source->minimumUpdateInterval() > 0); +} + +void TestQGeoSatelliteInfoSource::startUpdates_testIntervals() +{ CHECK_SOURCE_VALID; QSignalSpy spyView(m_source, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); QSignalSpy spyUse(m_source, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + m_source->setUpdateInterval(7000); + int interval = m_source->updateInterval(); m_source->startUpdates(); + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 9500); + for (int i = 0; i < 6; i++) { + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1) && (timeout.count() == 0), (interval*2)); + spyView.clear(); + spyUse.clear(); + } + m_source->stopUpdates(); +} + +void TestQGeoSatelliteInfoSource::startUpdates_testIntervalChangesWhileRunning() +{ + // There are two ways of dealing with an interval change, and we have left it system dependent. + // The interval can be changed will running or after the next update. + // WinCE uses the first method, S60 uses the second method. + + // The minimum interval on the symbian emulator is 5000 msecs, which is why the times in + // this test are as high as they are. + + CHECK_SOURCE_VALID; + QSignalSpy spyView(m_source, + SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy spyUse(m_source, + SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + m_source->setUpdateInterval(0); + m_source->startUpdates(); + m_source->setUpdateInterval(0); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0), 7000); + QCOMPARE(timeout.count(), 0); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(5000); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(10000); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 30000); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(5000); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(5000); + + QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(0); + + QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); + spyView.clear(); + spyUse.clear(); + + m_source->setUpdateInterval(0); + + QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); + spyView.clear(); + spyUse.clear(); + m_source->stopUpdates(); +} + +void TestQGeoSatelliteInfoSource::startUpdates_testDefaultInterval() +{ + CHECK_SOURCE_VALID; + QSignalSpy spyView(m_source, + SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy spyUse(m_source, + SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + m_source->startUpdates(); for (int i = 0; i < 3; i++) { - QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0), 12000); + QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); spyView.clear(); spyUse.clear(); } + m_source->stopUpdates(); +} + +void TestQGeoSatelliteInfoSource::startUpdates_testZeroInterval() +{ + CHECK_SOURCE_VALID; + QSignalSpy spyView(m_source, + SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy spyUse(m_source, + SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + m_source->setUpdateInterval(0); + m_source->startUpdates(); + for (int i = 0; i < 3; i++) { + QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); + spyView.clear(); + spyUse.clear(); + } m_source->stopUpdates(); } @@ -211,7 +372,7 @@ void TestQGeoSatelliteInfoSource::startUpdates_moreThanOnce() SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); QSignalSpy spyUse(m_source, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); - + m_source->setUpdateInterval(0); m_source->startUpdates(); m_source->startUpdates(); // check there is no crash @@ -232,7 +393,7 @@ void TestQGeoSatelliteInfoSource::stopUpdates() SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); QSignalSpy spyUse(m_source, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); - + m_source->setUpdateInterval(10000); m_source->startUpdates(); for (int i = 0; i < 2; i++) { @@ -306,6 +467,16 @@ void TestQGeoSatelliteInfoSource::requestUpdate_defaultTimeout() MAX_WAITING_TIME); } +void TestQGeoSatelliteInfoSource::requestUpdate_timeoutLessThanMinimumInterval() +{ + CHECK_SOURCE_VALID; + + QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); + m_source->requestUpdate(1); + + QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 1, 1000); +} + void TestQGeoSatelliteInfoSource::requestUpdate_repeatedCalls() { CHECK_SOURCE_VALID; @@ -360,7 +531,7 @@ void TestQGeoSatelliteInfoSource::requestUpdate_overlappingCallsWithTimeout() QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 7000); } -void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates() +void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates_ZeroInterval() { CHECK_SOURCE_VALID; @@ -370,6 +541,7 @@ void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates() SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); + m_source->setUpdateInterval(0); m_source->startUpdates(); QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), MAX_WAITING_TIME); @@ -389,7 +561,7 @@ void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates() m_source->stopUpdates(); } -void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates() +void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates_SmallInterval() { CHECK_SOURCE_VALID; @@ -398,7 +570,7 @@ void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates() QSignalSpy spyUse(m_source, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); - + m_source->setUpdateInterval(10000); m_source->requestUpdate(7000); m_source->startUpdates(); @@ -414,6 +586,56 @@ void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates() m_source->stopUpdates(); } +void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates_ZeroInterval() +{ + CHECK_SOURCE_VALID; + QSignalSpy spyView(m_source, + SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy spyUse(m_source, + SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + + m_source->requestUpdate(7000); + + m_source->setUpdateInterval(0); + m_source->startUpdates(); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() >= 2) && (spyUse.count() >= 2) && (timeout.count() == 0), 14000); + spyView.clear(); + spyUse.clear(); + + QTest::qWait(7000); + + QCOMPARE(timeout.count(), 0); + + m_source->stopUpdates(); +} + +void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates_SmallInterval() +{ + CHECK_SOURCE_VALID; + QSignalSpy spyView(m_source, + SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy spyUse(m_source, + SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &))); + QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); + + m_source->requestUpdate(7000); + + m_source->setUpdateInterval(10000); + m_source->startUpdates(); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); + spyView.clear(); + spyUse.clear(); + + QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0) && (timeout.count() == 0), 20000); + + m_source->stopUpdates(); +} + + + void TestQGeoSatelliteInfoSource::removeSlotForRequestTimeout() { CHECK_SOURCE_VALID; diff --git a/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource_p.h b/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource_p.h index 92fd4adc..f0243f26 100644 --- a/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource_p.h +++ b/tests/auto/qgeosatelliteinfosource/testqgeosatelliteinfosource_p.h @@ -81,10 +81,20 @@ private slots: void constructor_withParent(); void constructor_noParent(); + void updateInterval(); + + void setUpdateInterval(); + void setUpdateInterval_data(); + + void minimumUpdateInterval(); + void createDefaultSource(); void createDefaultSource_noParent(); - void startUpdates(); + void startUpdates_testIntervals(); + void startUpdates_testIntervalChangesWhileRunning(); + void startUpdates_testDefaultInterval(); + void startUpdates_testZeroInterval(); void startUpdates_moreThanOnce(); void stopUpdates(); void stopUpdates_withoutStart(); @@ -94,12 +104,15 @@ private slots: void requestUpdate_validTimeout(); void requestUpdate_defaultTimeout(); + void requestUpdate_timeoutLessThanMinimumInterval(); void requestUpdate_repeatedCalls(); void requestUpdate_overlappingCalls(); void requestUpdate_overlappingCallsWithTimeout(); - void requestUpdateBeforeStartUpdates(); - void requestUpdateAfterStartUpdates(); + void requestUpdateAfterStartUpdates_ZeroInterval(); + void requestUpdateAfterStartUpdates_SmallInterval(); + void requestUpdateBeforeStartUpdates_ZeroInterval(); + void requestUpdateBeforeStartUpdates_SmallInterval(); void removeSlotForRequestTimeout(); void removeSlotForSatellitesInUseUpdated(); |