| 1 | /*********************f******************************************************* |
| 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 | //TESTED_COMPONENT=src/location |
| 30 | |
| 31 | #include <QTest> |
| 32 | #include <QMetaType> |
| 33 | #include <QSignalSpy> |
| 34 | #include <QDebug> |
| 35 | #include <QTimer> |
| 36 | |
| 37 | #include <QtPositioning/qgeosatelliteinfosource.h> |
| 38 | #include <QtPositioning/qgeosatelliteinfo.h> |
| 39 | |
| 40 | #include "testqgeosatelliteinfosource_p.h" |
| 41 | #include "../utils/qlocationtestutils_p.h" |
| 42 | |
| 43 | Q_DECLARE_METATYPE(QList<QGeoSatelliteInfo>) |
| 44 | Q_DECLARE_METATYPE(QGeoSatelliteInfoSource::Error) |
| 45 | |
| 46 | #define MAX_WAITING_TIME 50000 |
| 47 | |
| 48 | // Must provide a valid source, unless testing the source |
| 49 | // returned by QGeoSatelliteInfoSource::createDefaultSource() on a system |
| 50 | // that has no default source |
| 51 | #define CHECK_SOURCE_VALID { \ |
| 52 | if (!m_source) { \ |
| 53 | if (m_testingDefaultSource && QGeoSatelliteInfoSource::createDefaultSource(0) == 0) \ |
| 54 | QSKIP("No default satellite source on this system"); \ |
| 55 | else \ |
| 56 | QFAIL("createTestSource() must return a valid source!"); \ |
| 57 | } \ |
| 58 | } |
| 59 | |
| 60 | class MySatelliteSource : public QGeoSatelliteInfoSource |
| 61 | { |
| 62 | Q_OBJECT |
| 63 | public: |
| 64 | MySatelliteSource(QObject *parent = 0) |
| 65 | : QGeoSatelliteInfoSource(parent) { |
| 66 | } |
| 67 | virtual void startUpdates() {} |
| 68 | virtual void stopUpdates() {} |
| 69 | virtual void requestUpdate(int) {} |
| 70 | virtual int minimumUpdateInterval() const { |
| 71 | return 0; |
| 72 | } |
| 73 | Error error() const { return QGeoSatelliteInfoSource::NoError; } |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | class DefaultSourceTest : public TestQGeoSatelliteInfoSource |
| 78 | { |
| 79 | Q_OBJECT |
| 80 | protected: |
| 81 | QGeoSatelliteInfoSource *createTestSource() { |
| 82 | return QGeoSatelliteInfoSource::createDefaultSource(parent: 0); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | TestQGeoSatelliteInfoSource::TestQGeoSatelliteInfoSource(QObject *parent) |
| 87 | : QObject(parent) |
| 88 | { |
| 89 | qRegisterMetaType<QGeoSatelliteInfoSource::Error>(); |
| 90 | |
| 91 | m_testingDefaultSource = false; |
| 92 | } |
| 93 | |
| 94 | TestQGeoSatelliteInfoSource *TestQGeoSatelliteInfoSource::createDefaultSourceTest() |
| 95 | { |
| 96 | DefaultSourceTest *test = new DefaultSourceTest; |
| 97 | test->m_testingDefaultSource = true; |
| 98 | return test; |
| 99 | } |
| 100 | |
| 101 | void TestQGeoSatelliteInfoSource::base_initTestCase() |
| 102 | { |
| 103 | qRegisterMetaType<QList<QGeoSatelliteInfo> >(); |
| 104 | } |
| 105 | |
| 106 | void TestQGeoSatelliteInfoSource::base_init() |
| 107 | { |
| 108 | m_source = createTestSource(); |
| 109 | m_testSlot2Called = false; |
| 110 | } |
| 111 | |
| 112 | void TestQGeoSatelliteInfoSource::base_cleanup() |
| 113 | { |
| 114 | delete m_source; |
| 115 | m_source = 0; |
| 116 | } |
| 117 | |
| 118 | void TestQGeoSatelliteInfoSource::base_cleanupTestCase() |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | void TestQGeoSatelliteInfoSource::initTestCase() |
| 123 | { |
| 124 | base_initTestCase(); |
| 125 | } |
| 126 | |
| 127 | void TestQGeoSatelliteInfoSource::init() |
| 128 | { |
| 129 | base_init(); |
| 130 | } |
| 131 | |
| 132 | void TestQGeoSatelliteInfoSource::cleanup() |
| 133 | { |
| 134 | base_cleanup(); |
| 135 | } |
| 136 | |
| 137 | void TestQGeoSatelliteInfoSource::cleanupTestCase() |
| 138 | { |
| 139 | base_cleanupTestCase(); |
| 140 | } |
| 141 | |
| 142 | void TestQGeoSatelliteInfoSource::test_slot1() |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | void TestQGeoSatelliteInfoSource::test_slot2() |
| 147 | { |
| 148 | m_testSlot2Called = true; |
| 149 | } |
| 150 | |
| 151 | void TestQGeoSatelliteInfoSource::constructor_withParent() |
| 152 | { |
| 153 | QObject *parent = new QObject(); |
| 154 | new MySatelliteSource(parent); |
| 155 | delete parent; |
| 156 | } |
| 157 | |
| 158 | void TestQGeoSatelliteInfoSource::constructor_noParent() |
| 159 | { |
| 160 | MySatelliteSource *obj = new MySatelliteSource(); |
| 161 | delete obj; |
| 162 | } |
| 163 | |
| 164 | void TestQGeoSatelliteInfoSource::createDefaultSource() |
| 165 | { |
| 166 | QObject *parent = new QObject; |
| 167 | QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(parent); |
| 168 | |
| 169 | // Check that default satellite source is successfully created. |
| 170 | if (!QGeoSatelliteInfoSource::availableSources().isEmpty()) |
| 171 | QVERIFY(source); |
| 172 | else |
| 173 | QVERIFY(!source); |
| 174 | |
| 175 | delete parent; |
| 176 | } |
| 177 | |
| 178 | void TestQGeoSatelliteInfoSource::createDefaultSource_noParent() |
| 179 | { |
| 180 | QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(parent: 0); |
| 181 | |
| 182 | // Check that default satellite source is successfully created. |
| 183 | if (!QGeoSatelliteInfoSource::availableSources().isEmpty()) |
| 184 | QVERIFY(source); |
| 185 | else |
| 186 | QVERIFY(!source); |
| 187 | |
| 188 | delete source; |
| 189 | } |
| 190 | |
| 191 | void TestQGeoSatelliteInfoSource::updateInterval() |
| 192 | { |
| 193 | MySatelliteSource s; |
| 194 | QCOMPARE(s.updateInterval(), 0); |
| 195 | } |
| 196 | |
| 197 | void TestQGeoSatelliteInfoSource::setUpdateInterval() |
| 198 | { |
| 199 | CHECK_SOURCE_VALID; |
| 200 | |
| 201 | QFETCH(int, interval); |
| 202 | QFETCH(int, expectedInterval); |
| 203 | |
| 204 | m_source->setUpdateInterval(interval); |
| 205 | QCOMPARE(m_source->updateInterval(), expectedInterval); |
| 206 | } |
| 207 | |
| 208 | void TestQGeoSatelliteInfoSource::setUpdateInterval_data() |
| 209 | { |
| 210 | QTest::addColumn<int>(name: "interval" ); |
| 211 | QTest::addColumn<int>(name: "expectedInterval" ); |
| 212 | QGeoSatelliteInfoSource *source = createTestSource(); |
| 213 | int minUpdateInterval = source ? source->minimumUpdateInterval() : -1; |
| 214 | if (source) |
| 215 | delete source; |
| 216 | |
| 217 | QTest::newRow(dataTag: "0" ) << 0 << 0; |
| 218 | |
| 219 | if (minUpdateInterval > -1) { |
| 220 | QTest::newRow(dataTag: "INT_MIN" ) << INT_MIN << minUpdateInterval; |
| 221 | QTest::newRow(dataTag: "-1" ) << -1 << minUpdateInterval; |
| 222 | } |
| 223 | |
| 224 | if (minUpdateInterval > 0) { |
| 225 | QTest::newRow(dataTag: "more than minInterval" ) << minUpdateInterval + 1 << minUpdateInterval + 1; |
| 226 | QTest::newRow(dataTag: "equal to minInterval" ) << minUpdateInterval << minUpdateInterval; |
| 227 | } |
| 228 | |
| 229 | if (minUpdateInterval > 1) { |
| 230 | QTest::newRow(dataTag: "less then minInterval" ) << minUpdateInterval - 1 << minUpdateInterval; |
| 231 | QTest::newRow(dataTag: "in btw zero and minInterval" ) << 1 << minUpdateInterval; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void TestQGeoSatelliteInfoSource::minimumUpdateInterval() |
| 236 | { |
| 237 | CHECK_SOURCE_VALID; |
| 238 | |
| 239 | QVERIFY(m_source->minimumUpdateInterval() > 0); |
| 240 | } |
| 241 | |
| 242 | void TestQGeoSatelliteInfoSource::startUpdates_testIntervals() |
| 243 | { |
| 244 | CHECK_SOURCE_VALID; |
| 245 | QSignalSpy spyView(m_source, |
| 246 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 247 | QSignalSpy spyUse(m_source, |
| 248 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 249 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 250 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 251 | |
| 252 | m_source->setUpdateInterval(7000); |
| 253 | int interval = m_source->updateInterval(); |
| 254 | |
| 255 | m_source->startUpdates(); |
| 256 | |
| 257 | if (!errorSpy.isEmpty()) |
| 258 | QSKIP("Error starting satellite updates." ); |
| 259 | |
| 260 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 9500); |
| 261 | for (int i = 0; i < 6; i++) { |
| 262 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1) && (timeout.count() == 0), (interval*2)); |
| 263 | spyView.clear(); |
| 264 | spyUse.clear(); |
| 265 | } |
| 266 | m_source->stopUpdates(); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | void TestQGeoSatelliteInfoSource::startUpdates_testIntervalChangesWhileRunning() |
| 271 | { |
| 272 | // There are two ways of dealing with an interval change, and we have left it system dependent. |
| 273 | // The interval can be changed will running or after the next update. |
| 274 | // WinCE uses the first method, S60 uses the second method. |
| 275 | |
| 276 | // The minimum interval on the symbian emulator is 5000 msecs, which is why the times in |
| 277 | // this test are as high as they are. |
| 278 | |
| 279 | CHECK_SOURCE_VALID; |
| 280 | QSignalSpy spyView(m_source, |
| 281 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 282 | QSignalSpy spyUse(m_source, |
| 283 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 284 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 285 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 286 | |
| 287 | m_source->setUpdateInterval(0); |
| 288 | m_source->startUpdates(); |
| 289 | m_source->setUpdateInterval(0); |
| 290 | |
| 291 | if (!errorSpy.isEmpty()) |
| 292 | QSKIP("Error starting satellite updates." ); |
| 293 | |
| 294 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0), 7000); |
| 295 | QCOMPARE(timeout.count(), 0); |
| 296 | spyView.clear(); |
| 297 | spyUse.clear(); |
| 298 | |
| 299 | m_source->setUpdateInterval(5000); |
| 300 | |
| 301 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); |
| 302 | spyView.clear(); |
| 303 | spyUse.clear(); |
| 304 | |
| 305 | m_source->setUpdateInterval(10000); |
| 306 | |
| 307 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 30000); |
| 308 | spyView.clear(); |
| 309 | spyUse.clear(); |
| 310 | |
| 311 | m_source->setUpdateInterval(5000); |
| 312 | |
| 313 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); |
| 314 | spyView.clear(); |
| 315 | spyUse.clear(); |
| 316 | |
| 317 | m_source->setUpdateInterval(5000); |
| 318 | |
| 319 | QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() == 2) && (spyUse.count() == 2) && (timeout.count() == 0), 15000); |
| 320 | spyView.clear(); |
| 321 | spyUse.clear(); |
| 322 | |
| 323 | m_source->setUpdateInterval(0); |
| 324 | |
| 325 | QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); |
| 326 | spyView.clear(); |
| 327 | spyUse.clear(); |
| 328 | |
| 329 | m_source->setUpdateInterval(0); |
| 330 | |
| 331 | QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); |
| 332 | spyView.clear(); |
| 333 | spyUse.clear(); |
| 334 | m_source->stopUpdates(); |
| 335 | } |
| 336 | |
| 337 | void TestQGeoSatelliteInfoSource::startUpdates_testDefaultInterval() |
| 338 | { |
| 339 | CHECK_SOURCE_VALID; |
| 340 | QSignalSpy spyView(m_source, |
| 341 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 342 | QSignalSpy spyUse(m_source, |
| 343 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 344 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 345 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 346 | |
| 347 | m_source->startUpdates(); |
| 348 | |
| 349 | if (!errorSpy.isEmpty()) |
| 350 | QSKIP("Error starting satellite updates." ); |
| 351 | |
| 352 | for (int i = 0; i < 3; i++) { |
| 353 | QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); |
| 354 | spyView.clear(); |
| 355 | spyUse.clear(); |
| 356 | } |
| 357 | m_source->stopUpdates(); |
| 358 | } |
| 359 | |
| 360 | void TestQGeoSatelliteInfoSource::startUpdates_testZeroInterval() |
| 361 | { |
| 362 | CHECK_SOURCE_VALID; |
| 363 | QSignalSpy spyView(m_source, |
| 364 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 365 | QSignalSpy spyUse(m_source, |
| 366 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 367 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 368 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 369 | |
| 370 | m_source->setUpdateInterval(0); |
| 371 | m_source->startUpdates(); |
| 372 | |
| 373 | if (!errorSpy.isEmpty()) |
| 374 | QSKIP("Error starting satellite updates." ); |
| 375 | |
| 376 | for (int i = 0; i < 3; i++) { |
| 377 | QTRY_VERIFY_WITH_TIMEOUT( (spyView.count() > 0 ) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); |
| 378 | spyView.clear(); |
| 379 | spyUse.clear(); |
| 380 | } |
| 381 | m_source->stopUpdates(); |
| 382 | } |
| 383 | |
| 384 | void TestQGeoSatelliteInfoSource::startUpdates_moreThanOnce() |
| 385 | { |
| 386 | CHECK_SOURCE_VALID; |
| 387 | QSignalSpy spyView(m_source, |
| 388 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 389 | QSignalSpy spyUse(m_source, |
| 390 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 391 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 392 | |
| 393 | m_source->setUpdateInterval(0); |
| 394 | m_source->startUpdates(); |
| 395 | |
| 396 | if (!errorSpy.isEmpty()) |
| 397 | QSKIP("Error starting satellite updates." ); |
| 398 | |
| 399 | m_source->startUpdates(); // check there is no crash |
| 400 | |
| 401 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0), MAX_WAITING_TIME); |
| 402 | |
| 403 | m_source->startUpdates(); // check there is no crash |
| 404 | |
| 405 | m_source->stopUpdates(); |
| 406 | } |
| 407 | |
| 408 | void TestQGeoSatelliteInfoSource::stopUpdates() |
| 409 | { |
| 410 | CHECK_SOURCE_VALID; |
| 411 | |
| 412 | QSignalSpy spyView(m_source, |
| 413 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 414 | QSignalSpy spyUse(m_source, |
| 415 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 416 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 417 | |
| 418 | m_source->setUpdateInterval(10000); |
| 419 | m_source->startUpdates(); |
| 420 | |
| 421 | if (!errorSpy.isEmpty()) |
| 422 | QSKIP("Error starting satellite updates." ); |
| 423 | |
| 424 | for (int i = 0; i < 2; i++) { |
| 425 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 12000); |
| 426 | spyView.clear(); |
| 427 | spyUse.clear(); |
| 428 | } |
| 429 | |
| 430 | m_source->stopUpdates(); |
| 431 | |
| 432 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 0) && (spyUse.count() == 0), 12000); |
| 433 | } |
| 434 | |
| 435 | void TestQGeoSatelliteInfoSource::stopUpdates_withoutStart() |
| 436 | { |
| 437 | CHECK_SOURCE_VALID; |
| 438 | |
| 439 | m_source->stopUpdates(); // check there is no crash |
| 440 | } |
| 441 | |
| 442 | void TestQGeoSatelliteInfoSource::requestUpdate() |
| 443 | { |
| 444 | CHECK_SOURCE_VALID; |
| 445 | |
| 446 | QFETCH(int, timeout); |
| 447 | QSignalSpy spy(m_source, SIGNAL(requestTimeout())); |
| 448 | QSignalSpy spyView(m_source, |
| 449 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 450 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 451 | |
| 452 | m_source->requestUpdate(timeout); |
| 453 | |
| 454 | if (!errorSpy.isEmpty()) |
| 455 | QSKIP("Error starting satellite updates." ); |
| 456 | |
| 457 | // Geoclue may deliver update instantly if there is a satellite fix |
| 458 | QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty() || !spyView.isEmpty(), 10); |
| 459 | } |
| 460 | |
| 461 | void TestQGeoSatelliteInfoSource::requestUpdate_data() |
| 462 | { |
| 463 | QTest::addColumn<int>(name: "timeout" ); |
| 464 | QTest::newRow(dataTag: "less than zero" ) << -1; |
| 465 | QTest::newRow(dataTag: "very small timeout" ) << 1; |
| 466 | } |
| 467 | |
| 468 | void TestQGeoSatelliteInfoSource::requestUpdate_validTimeout() |
| 469 | { |
| 470 | CHECK_SOURCE_VALID; |
| 471 | |
| 472 | QSignalSpy spyView(m_source, |
| 473 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 474 | QSignalSpy spyUse(m_source, |
| 475 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 476 | QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); |
| 477 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 478 | |
| 479 | m_source->requestUpdate(timeout: 7000); |
| 480 | |
| 481 | if (!errorSpy.isEmpty()) |
| 482 | QSKIP("Error starting satellite updates." ); |
| 483 | |
| 484 | QTRY_VERIFY_WITH_TIMEOUT( |
| 485 | (spyView.count() == 1) && (spyUse.count() == 1 && (spyTimeout.count()) == 0), 7000); |
| 486 | } |
| 487 | |
| 488 | void TestQGeoSatelliteInfoSource::requestUpdate_defaultTimeout() |
| 489 | { |
| 490 | CHECK_SOURCE_VALID; |
| 491 | |
| 492 | QSignalSpy spyView(m_source, |
| 493 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 494 | QSignalSpy spyUse(m_source, |
| 495 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 496 | QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); |
| 497 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 498 | |
| 499 | m_source->requestUpdate(timeout: 0); |
| 500 | |
| 501 | if (!errorSpy.isEmpty()) |
| 502 | QSKIP("Error starting satellite updates." ); |
| 503 | |
| 504 | QTRY_VERIFY_WITH_TIMEOUT( |
| 505 | (spyView.count() == 1) && (spyUse.count() == 1 && (spyTimeout.count()) == 0), |
| 506 | MAX_WAITING_TIME); |
| 507 | } |
| 508 | |
| 509 | void TestQGeoSatelliteInfoSource::requestUpdate_timeoutLessThanMinimumInterval() |
| 510 | { |
| 511 | CHECK_SOURCE_VALID; |
| 512 | |
| 513 | QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); |
| 514 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 515 | |
| 516 | m_source->requestUpdate(timeout: 1); |
| 517 | |
| 518 | if (!errorSpy.isEmpty()) |
| 519 | QSKIP("Error starting satellite updates." ); |
| 520 | |
| 521 | QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 1, 1000); |
| 522 | } |
| 523 | |
| 524 | void TestQGeoSatelliteInfoSource::requestUpdate_repeatedCalls() |
| 525 | { |
| 526 | CHECK_SOURCE_VALID; |
| 527 | |
| 528 | QSignalSpy spyView(m_source, |
| 529 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 530 | QSignalSpy spyUse(m_source, |
| 531 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 532 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 533 | |
| 534 | m_source->requestUpdate(timeout: 7000); |
| 535 | |
| 536 | if (!errorSpy.isEmpty()) |
| 537 | QSKIP("Error starting satellite updates." ); |
| 538 | |
| 539 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 7000); |
| 540 | spyView.clear(); |
| 541 | spyUse.clear(); |
| 542 | |
| 543 | m_source->requestUpdate(timeout: 7000); |
| 544 | |
| 545 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 7000); |
| 546 | } |
| 547 | |
| 548 | void TestQGeoSatelliteInfoSource::requestUpdate_overlappingCalls() |
| 549 | { |
| 550 | CHECK_SOURCE_VALID; |
| 551 | |
| 552 | QSignalSpy spyView(m_source, |
| 553 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 554 | QSignalSpy spyUse(m_source, |
| 555 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 556 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 557 | |
| 558 | m_source->requestUpdate(timeout: 7000); |
| 559 | |
| 560 | if (!errorSpy.isEmpty()) |
| 561 | QSKIP("Error starting satellite updates." ); |
| 562 | |
| 563 | m_source->requestUpdate(timeout: 7000); |
| 564 | |
| 565 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 7000); |
| 566 | } |
| 567 | |
| 568 | void TestQGeoSatelliteInfoSource::requestUpdate_overlappingCallsWithTimeout() |
| 569 | { |
| 570 | CHECK_SOURCE_VALID; |
| 571 | |
| 572 | QSignalSpy spyView(m_source, |
| 573 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 574 | QSignalSpy spyUse(m_source, |
| 575 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 576 | QSignalSpy spyTimeout(m_source, |
| 577 | SIGNAL(requestTimeout())); |
| 578 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 579 | |
| 580 | m_source->requestUpdate(timeout: 0); |
| 581 | |
| 582 | if (!errorSpy.isEmpty()) |
| 583 | QSKIP("Error starting satellite updates." ); |
| 584 | |
| 585 | m_source->requestUpdate(timeout: 1); |
| 586 | |
| 587 | QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 0, 7000); |
| 588 | |
| 589 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 7000); |
| 590 | } |
| 591 | |
| 592 | void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates_ZeroInterval() |
| 593 | { |
| 594 | CHECK_SOURCE_VALID; |
| 595 | |
| 596 | QSignalSpy spyView(m_source, |
| 597 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 598 | QSignalSpy spyUse(m_source, |
| 599 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 600 | QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); |
| 601 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 602 | |
| 603 | m_source->setUpdateInterval(0); |
| 604 | m_source->startUpdates(); |
| 605 | |
| 606 | if (!errorSpy.isEmpty()) |
| 607 | QSKIP("Error starting satellite updates." ); |
| 608 | |
| 609 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), MAX_WAITING_TIME); |
| 610 | spyView.clear(); |
| 611 | spyUse.clear(); |
| 612 | |
| 613 | m_source->requestUpdate(timeout: 7000); |
| 614 | |
| 615 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1) |
| 616 | && (spyTimeout.count() == 0), 7000); |
| 617 | |
| 618 | spyView.clear(); |
| 619 | spyUse.clear(); |
| 620 | |
| 621 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 12000); |
| 622 | |
| 623 | m_source->stopUpdates(); |
| 624 | } |
| 625 | |
| 626 | void TestQGeoSatelliteInfoSource::requestUpdateAfterStartUpdates_SmallInterval() |
| 627 | { |
| 628 | CHECK_SOURCE_VALID; |
| 629 | |
| 630 | QSignalSpy spyView(m_source, |
| 631 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 632 | QSignalSpy spyUse(m_source, |
| 633 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 634 | QSignalSpy spyTimeout(m_source, SIGNAL(requestTimeout())); |
| 635 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 636 | |
| 637 | m_source->setUpdateInterval(10000); |
| 638 | m_source->requestUpdate(timeout: 7000); |
| 639 | |
| 640 | if (!errorSpy.isEmpty()) |
| 641 | QSKIP("Error starting satellite updates." ); |
| 642 | |
| 643 | m_source->startUpdates(); |
| 644 | |
| 645 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0) |
| 646 | && (spyTimeout.count() == 0), 7000); |
| 647 | |
| 648 | spyView.clear(); |
| 649 | spyUse.clear(); |
| 650 | |
| 651 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() == 1) && (spyUse.count() == 1), 12000); |
| 652 | |
| 653 | m_source->stopUpdates(); |
| 654 | } |
| 655 | |
| 656 | void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates_ZeroInterval() |
| 657 | { |
| 658 | CHECK_SOURCE_VALID; |
| 659 | QSignalSpy spyView(m_source, |
| 660 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 661 | QSignalSpy spyUse(m_source, |
| 662 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 663 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 664 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 665 | |
| 666 | m_source->requestUpdate(timeout: 7000); |
| 667 | |
| 668 | if (!errorSpy.isEmpty()) |
| 669 | QSKIP("Error starting satellite updates." ); |
| 670 | |
| 671 | m_source->setUpdateInterval(0); |
| 672 | m_source->startUpdates(); |
| 673 | |
| 674 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() >= 2) && (spyUse.count() >= 2) && (timeout.count() == 0), 14000); |
| 675 | spyView.clear(); |
| 676 | spyUse.clear(); |
| 677 | |
| 678 | QTest::qWait(ms: 7000); |
| 679 | |
| 680 | QCOMPARE(timeout.count(), 0); |
| 681 | |
| 682 | m_source->stopUpdates(); |
| 683 | } |
| 684 | |
| 685 | void TestQGeoSatelliteInfoSource::requestUpdateBeforeStartUpdates_SmallInterval() |
| 686 | { |
| 687 | CHECK_SOURCE_VALID; |
| 688 | QSignalSpy spyView(m_source, |
| 689 | SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); |
| 690 | QSignalSpy spyUse(m_source, |
| 691 | SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); |
| 692 | QSignalSpy timeout(m_source, SIGNAL(requestTimeout())); |
| 693 | QSignalSpy errorSpy(m_source, SIGNAL(error(QGeoSatelliteInfoSource::Error))); |
| 694 | |
| 695 | m_source->requestUpdate(timeout: 7000); |
| 696 | |
| 697 | if (!errorSpy.isEmpty()) |
| 698 | QSKIP("Error starting satellite updates." ); |
| 699 | |
| 700 | m_source->setUpdateInterval(10000); |
| 701 | m_source->startUpdates(); |
| 702 | |
| 703 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0) && (timeout.count() == 0), 7000); |
| 704 | spyView.clear(); |
| 705 | spyUse.clear(); |
| 706 | |
| 707 | QTRY_VERIFY_WITH_TIMEOUT((spyView.count() > 0) && (spyUse.count() > 0) && (timeout.count() == 0), 20000); |
| 708 | |
| 709 | m_source->stopUpdates(); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | |
| 714 | void TestQGeoSatelliteInfoSource::removeSlotForRequestTimeout() |
| 715 | { |
| 716 | CHECK_SOURCE_VALID; |
| 717 | |
| 718 | bool i = connect(sender: m_source, SIGNAL(requestTimeout()), receiver: this, SLOT(test_slot1())); |
| 719 | QVERIFY(i==true); |
| 720 | i = connect(sender: m_source, SIGNAL(requestTimeout()), receiver: this, SLOT(test_slot2())); |
| 721 | QVERIFY(i==true); |
| 722 | i = disconnect(sender: m_source, SIGNAL(requestTimeout()), receiver: this, SLOT(test_slot1())); |
| 723 | QVERIFY(i==true); |
| 724 | |
| 725 | m_source->requestUpdate(timeout: -1); |
| 726 | QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 1000); |
| 727 | } |
| 728 | |
| 729 | void TestQGeoSatelliteInfoSource::removeSlotForSatellitesInUseUpdated() |
| 730 | { |
| 731 | CHECK_SOURCE_VALID; |
| 732 | |
| 733 | bool i = connect(sender: m_source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot1())); |
| 734 | QVERIFY(i == true); |
| 735 | i = connect(sender: m_source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot2())); |
| 736 | QVERIFY(i == true); |
| 737 | i = disconnect(sender: m_source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot1())); |
| 738 | QVERIFY(i == true); |
| 739 | |
| 740 | m_source->requestUpdate(timeout: 7000); |
| 741 | |
| 742 | if (m_source->error() != QGeoSatelliteInfoSource::NoError) |
| 743 | QSKIP("Error starting satellite updates." ); |
| 744 | |
| 745 | QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 7000); |
| 746 | } |
| 747 | |
| 748 | void TestQGeoSatelliteInfoSource::removeSlotForSatellitesInViewUpdated() |
| 749 | { |
| 750 | CHECK_SOURCE_VALID; |
| 751 | |
| 752 | bool i = connect(sender: m_source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot1())); |
| 753 | QVERIFY(i == true); |
| 754 | i = connect(sender: m_source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot2())); |
| 755 | QVERIFY(i == true); |
| 756 | i = disconnect(sender: m_source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)), receiver: this, SLOT(test_slot1())); |
| 757 | QVERIFY(i == true); |
| 758 | |
| 759 | m_source->requestUpdate(timeout: 7000); |
| 760 | |
| 761 | if (m_source->error() != QGeoSatelliteInfoSource::NoError) |
| 762 | QSKIP("Error starting satellite updates." ); |
| 763 | |
| 764 | QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 7000); |
| 765 | } |
| 766 | |
| 767 | #include "testqgeosatelliteinfosource.moc" |
| 768 | |