1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//TESTED_COMPONENT=src/location
#include <QTest>
#include <QMetaType>
#include <QSignalSpy>
#include <QDebug>
#include <QTimer>
#include <limits.h>
#include <qnumeric.h>
#include <qgeopositioninfosource.h>
#include <qgeopositioninfo.h>
#include "testqgeopositioninfosource_p.h"
#include "../utils/qlocationtestutils_p.h"
Q_DECLARE_METATYPE(QGeoPositionInfoSource::PositioningMethod)
Q_DECLARE_METATYPE(QGeoPositionInfoSource::PositioningMethods)
Q_DECLARE_METATYPE(QGeoPositionInfo)
#define MAX_WAITING_TIME 50000
// Must provide a valid source, unless testing the source
// returned by QGeoPositionInfoSource::createDefaultSource() on a system
// that has no default source
#define CHECK_SOURCE_VALID { \
if (!m_source) { \
if (m_testingDefaultSource && QGeoPositionInfoSource::createDefaultSource(0) == 0) \
QSKIP("No default position source on this system"); \
else \
QFAIL("createTestSource() must return a valid source!"); \
} \
}
class MyPositionSource : public QGeoPositionInfoSource
{
Q_OBJECT
public:
MyPositionSource(QObject *parent = 0)
: QGeoPositionInfoSource(parent) {
}
QGeoPositionInfo lastKnownPosition(bool /*fromSatellitePositioningMethodsOnly = false*/) const {
return QGeoPositionInfo();
}
void setSupportedPositioningMethods(PositioningMethods methods) {
m_methods = methods;
}
virtual PositioningMethods supportedPositioningMethods() const {
return m_methods;
}
virtual int minimumUpdateInterval() const {
return 0;
}
virtual void startUpdates() {}
virtual void stopUpdates() {}
virtual void requestUpdate(int) {}
Error error() const { return QGeoPositionInfoSource::NoError; }
private:
PositioningMethods m_methods;
};
class DefaultSourceTest : public TestQGeoPositionInfoSource
{
Q_OBJECT
protected:
QGeoPositionInfoSource *createTestSource() {
return QGeoPositionInfoSource::createSource(QStringLiteral("test.source"), 0);
}
};
TestQGeoPositionInfoSource::TestQGeoPositionInfoSource(QObject *parent)
: QObject(parent)
{
m_testingDefaultSource = false;
/*
* Set custom path since CI doesn't install test plugins
*/
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()
+ QStringLiteral("/../../../plugins"));
}
TestQGeoPositionInfoSource *TestQGeoPositionInfoSource::createDefaultSourceTest()
{
DefaultSourceTest *test = new DefaultSourceTest;
test->m_testingDefaultSource = true;
return test;
}
void TestQGeoPositionInfoSource::test_slot1()
{
}
void TestQGeoPositionInfoSource::test_slot2()
{
m_testSlot2Called = true;
}
void TestQGeoPositionInfoSource::base_initTestCase()
{
qRegisterMetaType<QGeoPositionInfo>();
}
void TestQGeoPositionInfoSource::base_init()
{
m_source = createTestSource();
m_testSlot2Called = false;
}
void TestQGeoPositionInfoSource::base_cleanup()
{
delete m_source;
m_source = 0;
}
void TestQGeoPositionInfoSource::base_cleanupTestCase()
{
}
void TestQGeoPositionInfoSource::initTestCase()
{
base_initTestCase();
}
void TestQGeoPositionInfoSource::init()
{
base_init();
}
void TestQGeoPositionInfoSource::cleanup()
{
base_cleanup();
}
void TestQGeoPositionInfoSource::cleanupTestCase()
{
base_cleanupTestCase();
}
// TC_ID_3_x_1
void TestQGeoPositionInfoSource::constructor_withParent()
{
QObject *parent = new QObject();
new MyPositionSource(parent);
delete parent;
}
// TC_ID_3_x_2
void TestQGeoPositionInfoSource::constructor_noParent()
{
MyPositionSource *obj = new MyPositionSource();
delete obj;
}
void TestQGeoPositionInfoSource::updateInterval()
{
MyPositionSource s;
QCOMPARE(s.updateInterval(), 0);
}
void TestQGeoPositionInfoSource::setPreferredPositioningMethods()
{
QFETCH(QGeoPositionInfoSource::PositioningMethod, supported);
QFETCH(QGeoPositionInfoSource::PositioningMethod, preferred);
QFETCH(QGeoPositionInfoSource::PositioningMethod, resulting);
MyPositionSource s;
s.setSupportedPositioningMethods(supported);
s.setPreferredPositioningMethods(preferred);
QCOMPARE(s.preferredPositioningMethods(), resulting);
}
void TestQGeoPositionInfoSource::setPreferredPositioningMethods_data()
{
QTest::addColumn<QGeoPositionInfoSource::PositioningMethod>("supported");
QTest::addColumn<QGeoPositionInfoSource::PositioningMethod>("preferred");
QTest::addColumn<QGeoPositionInfoSource::PositioningMethod>("resulting");
QTest::newRow("Sat supported, Sat preferred")
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods;
QTest::newRow("Sat supported, Non-Sat preferred")
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods;
QTest::newRow("Sat supported, All preferred")
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods;
QTest::newRow("Non-Sat supported, Sat preferred")
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods;
QTest::newRow("Non-Sat supported, Non-Sat preferred")
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods;
QTest::newRow("Non-Sat supported, All preferred")
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods;
QTest::newRow("All supported, Sat preferred")
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods
<< QGeoPositionInfoSource::SatellitePositioningMethods;
QTest::newRow("All supported, Non-Sat preferred")
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods
<< QGeoPositionInfoSource::NonSatellitePositioningMethods;
QTest::newRow("All supported, All preferred")
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::AllPositioningMethods
<< QGeoPositionInfoSource::AllPositioningMethods;
}
void TestQGeoPositionInfoSource::preferredPositioningMethods()
{
MyPositionSource s;
QCOMPARE(s.preferredPositioningMethods(), 0);
}
//TC_ID_3_x_1 : Create a position source with the given parent that reads from the system's default
// sources of location data
void TestQGeoPositionInfoSource::createDefaultSource()
{
QObject *parent = new QObject;
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(parent);
// now all platforms have the dummy plugin at least
QVERIFY(source != 0);
delete parent;
}
void TestQGeoPositionInfoSource::setUpdateInterval()
{
CHECK_SOURCE_VALID;
QFETCH(int, interval);
QFETCH(int, expectedInterval);
m_source->setUpdateInterval(interval);
QCOMPARE(m_source->updateInterval(), expectedInterval);
}
void TestQGeoPositionInfoSource::setUpdateInterval_data()
{
QTest::addColumn<int>("interval");
QTest::addColumn<int>("expectedInterval");
QGeoPositionInfoSource *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 TestQGeoPositionInfoSource::lastKnownPosition()
{
CHECK_SOURCE_VALID;
QFETCH(QGeoPositionInfoSource::PositioningMethod, positioningMethod);
QFETCH(bool, lastKnownPositionArgument);
if ((m_source->supportedPositioningMethods() & positioningMethod) == 0)
QSKIP("Not a supported positioning method for this position source");
m_source->setPreferredPositioningMethods(positioningMethod);
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
int time_out = 7000;
m_source->setUpdateInterval(time_out);
m_source->startUpdates();
// Use QEventLoop instead of qWait() to ensure we stop as soon as a
// position is emitted (otherwise the lastKnownPosition() may have
// changed by the time it is checked)
QEventLoop loop;
QTimer timer;
//simulated CI tests will quickly return -> real GPS tests take 2 minutes for satellite systems
//use a 5 min timeout
timer.setInterval(300000);
connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)),
&loop, SLOT(quit()));
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start();
loop.exec();
QVERIFY((spy.count() > 0) && (timeout.count() == 0));
QList<QVariant> list = spy.takeFirst();
QGeoPositionInfo info = list.at(0).value<QGeoPositionInfo>();
QGeoPositionInfo lastPositioninfo = m_source->lastKnownPosition(lastKnownPositionArgument);
// lastPositioninfo is only gauranteed to be valid in all cases when only using satelite
// positioning methods or when lastKnownPositionArgument is false
if (!lastKnownPositionArgument ||
positioningMethod == QGeoPositionInfoSource::SatellitePositioningMethods) {
QVERIFY(lastPositioninfo.isValid());
}
if (lastPositioninfo.isValid()) {
QCOMPARE(info.coordinate(), lastPositioninfo.coordinate());
// On some CI machines the above evenloop code is not sufficient as positionUpdated
// still fires causing last know position and last update to be out of sync.
// To accommodate we check that the time stamps are no more than 1s apart
// ideally they should be the same
// doesn't work: QCOMPARE(info.timestamp(), lastPositioninfo.timestamp());
const qint64 diff = qAbs(info.timestamp().msecsTo(lastPositioninfo.timestamp()));
QCOMPARE(diff < 1000, true);
QCOMPARE(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy),
lastPositioninfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy));
if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::HorizontalAccuracy));
bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy));
QCOMPARE(isNaN1, isNaN2);
if (!isNaN1) {
QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy),
lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)), true);
}
}
QCOMPARE(info.hasAttribute(QGeoPositionInfo::VerticalAccuracy),
lastPositioninfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy));
if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::VerticalAccuracy));
bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy));
QCOMPARE(isNaN1, isNaN2);
if (!isNaN1) {
QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy),
lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)), true);
}
}
}
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::lastKnownPosition_data()
{
QTest::addColumn<QGeoPositionInfoSource::PositioningMethod>("positioningMethod");
QTest::addColumn<bool>("lastKnownPositionArgument");
// no good way to determine on MeeGo what are supported. If we ask for all or non-satellites, we
// typically get geoclue-example provider, which is not suitable for this test.
QTest::newRow("all - false") << QGeoPositionInfoSource::AllPositioningMethods << false;
QTest::newRow("all - true") << QGeoPositionInfoSource::AllPositioningMethods << true;
QTest::newRow("satellite - false") << QGeoPositionInfoSource::SatellitePositioningMethods << false;
QTest::newRow("satellite - true") << QGeoPositionInfoSource::SatellitePositioningMethods << true;
}
void TestQGeoPositionInfoSource::minimumUpdateInterval()
{
CHECK_SOURCE_VALID;
QVERIFY(m_source->minimumUpdateInterval() > 0);
}
//TC_ID_3_x_1
void TestQGeoPositionInfoSource::startUpdates_testIntervals()
{
CHECK_SOURCE_VALID;
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(7000);
int interval = m_source->updateInterval();
m_source->startUpdates();
QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 9500);
for (int i = 0; i < 6; i++) {
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), (interval*2));
spy.clear();
}
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::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 spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(0);
m_source->startUpdates();
m_source->setUpdateInterval(0);
QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 7000);
QCOMPARE(timeout.count(), 0);
spy.clear();
m_source->setUpdateInterval(5000);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000);
spy.clear();
m_source->setUpdateInterval(10000);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 30000);
spy.clear();
m_source->setUpdateInterval(5000);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000);
spy.clear();
m_source->setUpdateInterval(5000);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 2) && (timeout.count() == 0), 15000);
spy.clear();
m_source->setUpdateInterval(0);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), 7000);
spy.clear();
m_source->setUpdateInterval(0);
QTRY_VERIFY_WITH_TIMEOUT((spy.count() == 1) && (timeout.count() == 0), 7000);
spy.clear();
m_source->stopUpdates();
}
//TC_ID_3_x_2
void TestQGeoPositionInfoSource::startUpdates_testDefaultInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->startUpdates();
for (int i = 0; i < 3; i++) {
QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000);
spy.clear();
}
m_source->stopUpdates();
}
//TC_ID_3_x_3
void TestQGeoPositionInfoSource::startUpdates_testZeroInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(0);
m_source->startUpdates();
for (int i = 0; i < 3; i++) {
QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000);
spy.clear();
}
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::startUpdates_moreThanOnce()
{
CHECK_SOURCE_VALID;
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(0);
m_source->startUpdates();
m_source->startUpdates(); // check there is no crash
QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 7000);
m_source->startUpdates(); // check there is no crash
m_source->stopUpdates();
}
//TC_ID_3_x_1
void TestQGeoPositionInfoSource::stopUpdates()
{
CHECK_SOURCE_VALID;
QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(7000);
m_source->startUpdates();
for (int i = 0; i < 2; i++) {
QTRY_VERIFY_WITH_TIMEOUT((spy.count() > 0) && (timeout.count() == 0), 9500);
spy.clear();
}
m_source->stopUpdates();
QTest::qWait(9500);
QCOMPARE(spy.count(), 0);
spy.clear();
m_source->setUpdateInterval(0);
m_source->startUpdates();
m_source->stopUpdates();
QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 0, 9500);
}
//TC_ID_3_x_2
void TestQGeoPositionInfoSource::stopUpdates_withoutStart()
{
CHECK_SOURCE_VALID;
m_source->stopUpdates(); // check there is no crash
}
void TestQGeoPositionInfoSource::requestUpdate()
{
CHECK_SOURCE_VALID;
QFETCH(int, timeout);
QSignalSpy spy(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(timeout);
QTRY_COMPARE(spy.count(), 1);
}
void TestQGeoPositionInfoSource::requestUpdate_data()
{
QTest::addColumn<int>("timeout");
QTest::newRow("less than zero") << -1; //TC_ID_3_x_7
}
// TC_ID_3_x_1 : Create position source and call requestUpdate with valid timeout value
void TestQGeoPositionInfoSource::requestUpdate_validTimeout()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
}
void TestQGeoPositionInfoSource::requestUpdate_defaultTimeout()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(0);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
}
// TC_ID_3_x_2 : Create position source and call requestUpdate with a timeout less than
// minimumupdateInterval
void TestQGeoPositionInfoSource::requestUpdate_timeoutLessThanMinimumInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(1);
QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 1, 1000);
}
// TC_ID_3_x_3 : Call requestUpdate() with same value repeatedly
void TestQGeoPositionInfoSource::requestUpdate_repeatedCalls()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
spyUpdate.clear();
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
}
void TestQGeoPositionInfoSource::requestUpdate_overlappingCalls()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(7000);
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
}
//TC_ID_3_x_4
void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_ZeroInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(0);
m_source->startUpdates();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
spyUpdate.clear();
m_source->requestUpdate(7000);
QTest::qWait(7000);
QVERIFY((spyUpdate.count() > 0) && (spyTimeout.count() == 0));
spyUpdate.clear();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), MAX_WAITING_TIME);
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_SmallInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->setUpdateInterval(10000);
m_source->startUpdates();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 20000);
spyUpdate.clear();
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 7000);
spyUpdate.clear();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 20000);
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_ZeroInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(7000);
m_source->setUpdateInterval(0);
m_source->startUpdates();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() >= 2) && (spyTimeout.count() == 0), 14000);
spyUpdate.clear();
QTest::qWait(7000);
QCOMPARE(spyTimeout.count(), 0);
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_SmallInterval()
{
CHECK_SOURCE_VALID;
QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)));
QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout()));
m_source->requestUpdate(7000);
m_source->setUpdateInterval(10000);
m_source->startUpdates();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 7000);
spyUpdate.clear();
QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() > 0) && (spyTimeout.count() == 0), 20000);
m_source->stopUpdates();
}
void TestQGeoPositionInfoSource::removeSlotForRequestTimeout()
{
CHECK_SOURCE_VALID;
bool i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1()));
QVERIFY(i == true);
i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot2()));
QVERIFY(i == true);
i = disconnect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1()));
QVERIFY(i == true);
m_source->requestUpdate(-1);
QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 1000);
}
void TestQGeoPositionInfoSource::removeSlotForPositionUpdated()
{
CHECK_SOURCE_VALID;
bool i = connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(test_slot1()));
QVERIFY(i == true);
i = connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(test_slot2()));
QVERIFY(i == true);
i = disconnect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(test_slot1()));
QVERIFY(i == true);
m_source->requestUpdate(7000);
QTRY_VERIFY_WITH_TIMEOUT((m_testSlot2Called == true), 7000);
}
#include "testqgeopositioninfosource.moc"
|