void QGeoPositionInfoSourceAndroid::updateTimeoutElapsed()
{
    QGeoPositionInfo position;
    position=m_lastUpdate;

    if (position.isValid())
    {
        if (m_positionInfoState & QGeoPositionInfoSourceAndroid::RequestActive)
        {
            m_requestTimer->stop();
            m_positionInfoState &= ~QGeoPositionInfoSourceAndroid::RequestActive;

            if (m_positionInfoState & QGeoPositionInfoSourceAndroid::Stopped
                ||!(m_positionInfoState & QGeoPositionInfoSourceAndroid::StartUpdateActive))
            {
                QtLocationJni::disableUpdates(this);
            }

        }
        emit positionUpdated(position);
    }
    else
    {
        emit updateTimeout();
    }
    activateTimer();
}
void
QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition)
{
    if (!geoPosition.isValid()) {
        NS_WARNING("Invalida geoposition received");
        return;
    }

    QGeoCoordinate coord = geoPosition.coordinate();
    double latitude = coord.latitude();
    double longitude = coord.longitude();
    double altitude = coord.altitude();
    double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);
    double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);
    double heading = geoPosition.attribute(QGeoPositionInfo::Direction);

    bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
    double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);

    nsRefPtr<nsGeoPosition> p =
        new nsGeoPosition(latitude, longitude,
                          altitude, accuracy,
                          altitudeAccuracy, heading,
                          speed, geoPosition.timestamp().toTime_t());
    if (mCallback) {
        mCallback->Update(p);
    }
}
Exemple #3
0
void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
    if (geoPositionInfo.isValid())
    {
        // Stop regular position updates, because a valid position has been
        // obtained
        locationDataSource->stopUpdates();

        // Get the current location as latitude and longitude
        QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
        qreal latitude = geoCoordinate.latitude();
        qreal longitude = geoCoordinate.longitude();



        QString string1;
        QString string2;
     //   QChar c = 'g';

        //build the string for latitude-longitude
        string1.setNum(latitude);
        this->latlng.append(string1);
        string2.setNum(longitude);
        this->latlng.append(",");
        this->latlng.append(string2);


        //send the location request
        sendRequest();
    }
}
void GeolocationClientQt::positionUpdated(const QGeoPositionInfo &geoPosition)
{
    if (!geoPosition.isValid())
        return;

    QGeoCoordinate coord = geoPosition.coordinate();
    double latitude = coord.latitude();
    double longitude = coord.longitude();
    bool providesAltitude = (geoPosition.coordinate().type() == QGeoCoordinate::Coordinate3D);
    double altitude = coord.altitude();

    double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);

    bool providesAltitudeAccuracy = geoPosition.hasAttribute(QGeoPositionInfo::VerticalAccuracy);
    double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);

    bool providesHeading =  geoPosition.hasAttribute(QGeoPositionInfo::Direction);
    double heading = geoPosition.attribute(QGeoPositionInfo::Direction);

    bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
    double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);

    double timeStampInSeconds = geoPosition.timestamp().toMSecsSinceEpoch() / 1000;

    m_lastPosition = GeolocationPosition::create(timeStampInSeconds, latitude, longitude,
                                                 accuracy, providesAltitude, altitude,
                                                 providesAltitudeAccuracy, altitudeAccuracy,
                                                 providesHeading, heading, providesSpeed, speed);

    WebCore::Page* page = QWebPagePrivate::core(m_page);
    page->geolocationController()->positionChanged(m_lastPosition.get());
}
void CLbsPositionLogger::readNextPosition()
{
    QByteArray line = m_logFile.readLine().trimmed();
    if (line.isEmpty()) {
        LOG_MODEL_ERROR("CLbsPositionLogger", "no readlien");
        return;
    }
    
    QList<QByteArray> data = line.split(',');
    
    QGeoCoordinate coordinate;
    QGeoPositionInfo info;
    
    bool hasTimestamp = false;
    QDateTime timestamp = QDateTime::fromTime_t(data.value(0).toLong(&hasTimestamp), Qt::UTC);
    if(hasTimestamp && timestamp.isValid())
        info.setTimestamp(timestamp);
    double latitude;
    bool hasLatitude = false;
    latitude = data.value(1).toDouble(&hasLatitude);
    if(hasLatitude)
        coordinate.setLatitude(latitude);
    double longitude;
    bool hasLongitude = false;
    longitude = data.value(2).toDouble(&hasLongitude);
    if(hasLongitude)
        coordinate.setLongitude(longitude);
    double altitude;
    bool hasAltitude = false;
    altitude = data.value(3).toDouble(&hasAltitude);
    if(hasAltitude)
        coordinate.setAltitude(altitude);
    info.setCoordinate(coordinate);
    
    double HorizontalAccuracy;
    bool hasHorizontalAccuracy = false;
    HorizontalAccuracy = data.value(4).toDouble(&hasHorizontalAccuracy);
    if(hasHorizontalAccuracy)
        info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, HorizontalAccuracy);
    double Direction;
    bool hasDirection = false;
    Direction = data.value(5).toDouble(&hasDirection);
    if(hasDirection)
        info.setAttribute(QGeoPositionInfo::Direction, Direction);
    double GroundSpeed;
    bool hasGroundSpeed = false;
    GroundSpeed = data.value(6).toDouble(&hasGroundSpeed);
    if(hasGroundSpeed)
        info.setAttribute(QGeoPositionInfo::GroundSpeed, GroundSpeed);
    if (info.isValid()) {
        m_lastPosition = info;
        emit positionUpdated(info);
    }
}
Exemple #6
0
void RouteMePositionInfo::onPositionUpdated(const QGeoPositionInfo &info)
{
    if (!info.isValid() || !info.coordinate().isValid())
        return;

    QGeoCoordinate coordinate = info.coordinate();
    m_currentCoordinate.setGeoCoordinate(coordinate);

    emit currentCoordinateAvailable();

    stopUpdates();
}
void LocationWatcher::positionUpdated(const QGeoPositionInfo &info)
{
    if (info.isValid()) {

        double latitude=info.coordinate().latitude();
        double longitude=info.coordinate().longitude();

        //QSqlDatabase db = openDB();
        profilemanager pm;
        // QSqlDatabase db = QSqlDatabase::database("/home/user/.local/share/data/QML/OfflineStorage/Databases/3e6ed8d4e46837c47b903b1e4ae85712.sqlite");

      if( !db.open() )
      {
        qFatal( "Failed to connect." );
      }
      if( db.open() )
      {      
          QSqlQuery query(db);
          double radius = getSetting("radius").toDouble();

          QString HereProfile="";
          //start looping through all areas
          query.exec("SELECT * FROM records");
          while(query.next()) {
              QString lat = query.value(0).toString();
              QString lon = query.value(1).toString();
              QString profile = query.value(2).toString();
              double lat1 = lat.toDouble();
              double lon1 = lon.toDouble();
              double distance=cut(lat1,lon1,latitude,longitude);
              if(distance<radius){
                    qDebug() << "to vrikame: " << lat<<lon<<profile<<distance<<radius;
                    HereProfile=profile;
                    break;
              }else{
                  HereProfile="";
              }
          }//telos loop perioxes
          if(HereProfile!="")
              pm.setProfile(HereProfile);
          else {
              query.exec("SELECT value FROM settings WHERE key='previousProfile'");
              query.first();
              QString previous=query.value(0).toString();
              qDebug()<<previous;
              pm.setProfile(previous);
          }
      }
    }//telos isvalid

}
Exemple #8
0
void Daemon::positionUpdated(QGeoPositionInfo gpsPos)
{
    qreal haMeters = 0;

    if(gpsPos.isValid()) {
        haMeters = gpsPos.attribute(QGeoPositionInfo::HorizontalAccuracy);
        log(QString("Location accuracy is %1 m").arg(haMeters));
    } else {
        log("Location updated, but not valid");
    }

    if (!m_daemonEnabled) {
        deleteGPS();
        return;
    }

    if(gpsPos.isValid()) {
        m_YougeoPosInfo = gpsPos;

        if (haMeters < m_accuracy && haMeters != 0) {

            emit gpsLocationReceived();

            if (!m_keepGpsRunning) {
                deleteGPS();
                log(QString("GPS stopped. Accuracy was %1 m").arg(haMeters));
            }
            // Is there location request?
            if (!m_askingLocation.isEmpty()) {
                // Send location response SMS
                m_message->sendLocationSMS("RES:", m_YougeoPosInfo, m_askingLocation);
                log(QString("SMS sent to number %1").arg(m_askingLocation));
                // Reset position and requester
                reset();
            }
        }
    }
}
Exemple #9
0
void TrackingService::sendMark()
{
    qDebug() << "sendMark";
    QGeoPositionInfo info = m_locationManager->getInfo();
    if (info.isValid())
    {
        m_dataMark->setLatitude(info.coordinate().latitude());
        m_dataMark->setLongitude(info.coordinate().longitude());
        m_dataMark->setTime();
        m_writeTagQuery->doRequest();
    }
    else
    {
        qDebug() << "invalid geo info, waitin and trying again";
        QTimer::singleShot(m_period * 1000, this, SLOT(sendMark()));
    }
}
Exemple #10
0
void GPSWidget::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
    //qWarning("positionUpdated");
    if (geoPositionInfo.isValid())
    {
        // Stop regular position updates, because a valid position has been
        // obtained
        locationDataSource->stopUpdates();

        // Get the current location as latitude and longitude
        geoCoordinate_ = geoPositionInfo.coordinate();


        emit gpsData(geoCoordinate_);

        locationDataSource->startUpdates();// chamówa

    }
}
void PushN8PhoneGPS::positionUpdated(QGeoPositionInfo info)
{
    if(info.isValid() && !gpsOnline) {
        emit connected();
        gpsOnline = true;
        qDebug() << "GPS now connected";
    }

//    if(info.coordinate().isValid() && !gpsOnline)
//    {
//        //emitting connected signal when receiving first reading
//        emit connected();
//        gpsOnline = true;

//    } else if(gpsOnline) {

//        gpsOnline = false;
//        emit disconnected();

//    }

    if(!streaming)
        return;

    if(info.timestamp().isValid()) { //&& info.coordinate().isValid()

        QDateTime correctedTstamp;
        correctedTstamp = info.timestamp().addSecs(UTCOffset);//ugly localisation!
        info.setTimestamp(correctedTstamp);

        //double checking speed

        NPushGpsTick * newGPSTick = new NPushGpsTick(info);

        if(receivers(SIGNAL(reading_ready(NPushLogTick*))) > 0)
        {
            emit reading_ready(newGPSTick);
        } else {
            delete newGPSTick;
Exemple #12
0
void LocationData::onPositionChanged(const QGeoPositionInfo& info)
{
    emit positionChanged(info);
    if (info.isValid())
    {
        const QGeoCoordinate& c = info.coordinate();
        if (c.isValid())
        {
            double lat = c.latitude();
            double lon = c.longitude();
            double alt = c.altitude();
            //qDebug() << "LocationData::onPositionChanged()" << lat << lon << alt;
            if ((latitude != lat) || (longitude != lon))
            {
                latitude  = lat;
                mask |= LATMASK;
                longitude = lon;
                mask |= LONMASK;
            }
            if (altitude != alt)
            {
                altitude = alt;
                mask |= ALTMASK;
            }
            emit positionChanged(lat,lon,alt);
        }
        if (info.hasAttribute(QGeoPositionInfo::GroundSpeed))
        {
            double s = info.attribute(QGeoPositionInfo::GroundSpeed);
            emit speedChanged(s);
        }
        if (info.hasAttribute(QGeoPositionInfo::Direction))
        {
            double c = info.attribute(QGeoPositionInfo::Direction);
            emit courseChanged(c);
        }
    }
}
Exemple #13
0
void QGeoPositionInfoSourceMaemo::updateTimeoutElapsed()
{
    QGeoPositionInfo position;

    QGeoPositionInfoSource::PositioningMethods methods = preferredPositioningMethods();

    if (methods.testFlag(AllPositioningMethods)) {
        methods |= SatellitePositioningMethods;
        methods |= NonSatellitePositioningMethods;
    }

    if (methods.testFlag(SatellitePositioningMethods) && !methods.testFlag(NonSatellitePositioningMethods)) {
        //only SatellitePositioningMethods preferred
        position = lastUpdateFromSatellite;
    } else if (methods.testFlag(NonSatellitePositioningMethods) && !methods.testFlag(SatellitePositioningMethods)) {
        //only NonSatellitePositioningMethods preferred
        position = lastUpdateFromNetwork;
    } else {
        //AllPositioningMethods or none preferred
        if (lastUpdateFromSatellite.isValid())
            position = lastUpdateFromSatellite;
        else
            position = lastUpdateFromNetwork;
    }

    if (position.isValid()) {
        errorOccurred = false;
        errorSent = false;

        if (positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) {
            positionInfoState &= ~QGeoPositionInfoSourceMaemo::RequestActive;
            requestTimer->stop();

            if (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped)
                if (LiblocationWrapper::instance()->isActive())
                    LiblocationWrapper::instance()->stop();

            // Ensure that requested position fix is emitted even though
            // powersave is active and GPS would normally be off.
            if ((positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) &&
               (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped)) {
                emit positionUpdated(position);
            }
        }

        // Make sure that if update is triggered when waking up, there
        // is no false position update.
        if (!((positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) &&
             (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped)))
            emit positionUpdated(position);
    } else {
        // if an error occurs when we are updating periodically and we haven't
        // sent an error since the last fix...
        if (!(positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) &&
                errorOccurred && !errorSent) {
            errorSent = true;
            // we need to emit the updateTimeout signal
            emit updateTimeout();
        }
    }
    activateTimer();
}
void QGeoPositionInfoSourceAndroid::dataUpdated(const QGeoPositionInfo &data)
{
    if(!data.isValid()) return;
    lastPosition = data;
    emit positionUpdated(data);
}
Exemple #15
0
void androidGps::positionUpdated(const QGeoPositionInfo &info)
{
    qDebug() << "GPS data source 1: " << info.isValid() << info;
}
Exemple #16
0
void TestQGeoPositionInfoSource::lastKnownPosition()
{
    CHECK_SOURCE_VALID;
    QFETCH(int, positioningMethod);
    QFETCH(bool, lastKnownPositionArgument);
    QFETCH(bool, positionValid);

#if defined(Q_OS_SYMBIAN)
    QSKIP("Real GPS not suitable for autotesting, skipping the test.", SkipAll);
#endif
    QGeoPositionInfoSource::PositioningMethods method
            = static_cast<QGeoPositionInfoSource::PositioningMethods>(positioningMethod);

    if ((m_source->supportedPositioningMethods() & method) == 0)
        QSKIP("Not a supported positioning method for this position source", SkipSingle);

    m_source->setPreferredPositioningMethods(method);

    QSignalSpy spy(m_source, SIGNAL(positionUpdated(const 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;
    timer.setInterval(9500);
    connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)),
            &loop, SLOT(quit()));
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start();
    loop.exec();

    EXPECT_FAIL_WINCE_SEE_MOBILITY_337_ABORT;

    QVERIFY((spy.count() > 0) && (timeout.count() == 0));

    QList<QVariant> list = spy.takeFirst();
    QGeoPositionInfo info;
    info = list.at(0).value<QGeoPositionInfo>();
    QGeoPositionInfo lastPositioninfo;
    lastPositioninfo = m_source->lastKnownPosition(lastKnownPositionArgument);
 
    QCOMPARE(lastPositioninfo.isValid(), positionValid);

    if (positionValid) {
        QCOMPARE(info.coordinate(), lastPositioninfo.coordinate());
        QCOMPARE(info.timestamp(), lastPositioninfo.timestamp());

        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();
}
Exemple #17
0
void TestQGeoPositionInfoSource::robustness()
{
    // Perform uneducated API calls and make sure it behaves
    QVERIFY(m_source);
    QGeoPositionInfo info = m_source->lastKnownPosition(true);
    QVERIFY(!info.isValid());
    info = m_source->lastKnownPosition(false);
    QVERIFY(!info.isValid());
    m_source->stopUpdates();

    // Have changing source fail and check interface works.
    geocluemock_set_gcmaster_get_default(false);
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    m_source->setUpdateInterval(1000);
    m_source->startUpdates();
    m_source->requestUpdate(1000);
    m_source->stopUpdates();
    info = m_source->lastKnownPosition(false);
    QVERIFY(!info.isValid());
    geocluemock_set_gcmaster_get_default(true);
    // Check that the source is able to recover
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
    QSignalSpy updateSpy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)));
    QSignalSpy timeoutSpy(m_source, SIGNAL(updateTimeout()));
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(timeoutSpy.isEmpty());

    // Successfully change source during active updates and check updates continue
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(timeoutSpy.isEmpty());
    // Change again successfully the source and check that the requestUpdate is delivered
    m_source->stopUpdates();
    m_source->requestUpdate(2000);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(timeoutSpy.isEmpty());

    // Change the source unsuccessfully and expect timeout
    m_source->startUpdates();
    geocluemock_set_gcmaster_get_default(false);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    QTRY_VERIFY_WITH_TIMEOUT(!timeoutSpy.isEmpty(), 3000);
    QVERIFY(updateSpy.isEmpty());
    geocluemock_set_gcmaster_get_default(true);

    // Issue a start to unsuccessfully changed source and expect timeout
    updateSpy.clear(); timeoutSpy.clear();
    m_source->requestUpdate(2000);
    QTRY_VERIFY_WITH_TIMEOUT(!timeoutSpy.isEmpty(), 3000);
    QVERIFY(updateSpy.isEmpty());

    // Set unknown preferred method and check it has no impact (first set successful method)
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    m_source->setPreferredPositioningMethods((QGeoPositionInfoSource::PositioningMethods)555);
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);

    // Successfully change preferred method but without velocity
    geocluemock_set_geoclue_velocity_new(false);
    geocluemock_set_suppress_velocity_update(true);
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(!info.hasAttribute(QGeoPositionInfo::GroundSpeed));
    geocluemock_set_geoclue_velocity_new(true);
    geocluemock_set_suppress_velocity_update(false);

    // Unsuccessfully change source during active requestUpdate()
    m_source->stopUpdates();
    geocluemock_set_suppress_single_update(true); // Justin Case
    m_source->requestUpdate(1000);
    geocluemock_set_gcmaster_get_default(false);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    QTRY_VERIFY_WITH_TIMEOUT(!timeoutSpy.isEmpty(), 3000);
    QVERIFY(updateSpy.isEmpty());
    geocluemock_set_gcmaster_get_default(true);
    geocluemock_set_suppress_single_update(false);

    // Check that setting same positioning method does nothing.
    // First setup successful and check updates are received
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    m_source->startUpdates();
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
    // then set creation to fail. however should not impact because
    // methods are the same
    geocluemock_set_gcmaster_get_default(false);
    m_source->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 3000);
}
Exemple #18
0
void TestQGeoPositionInfoSource::updateInferno()
{
    // Tests different position update failure scenarios
    // Successful, normal update
    m_source->setUpdateInterval(1000);
    QSignalSpy updateSpy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)));
    QSignalSpy timeoutSpy(m_source, SIGNAL(updateTimeout()));
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 2100);
    QVERIFY(timeoutSpy.isEmpty());

    // Suppress the regular updates and check that timeouts are received
    // Then resume the updates and see it goes ok.
    geocluemock_set_suppress_regular_updates(true);
    updateSpy.clear(); timeoutSpy.clear();
    QTest::qWait(2000);
    // there is no updateTimeout because there is no error
    QTRY_VERIFY_WITH_TIMEOUT(timeoutSpy.isEmpty(), 2000);
    QVERIFY(updateSpy.isEmpty());
    geocluemock_set_suppress_regular_updates(false);
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 4000);
    QVERIFY(timeoutSpy.isEmpty());

    // Restart updates and check velocity is received when expected
    m_source->stopUpdates();
    updateSpy.clear(); timeoutSpy.clear();
    // start updates without velocity
    geocluemock_set_suppress_velocity_update(true);
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 4000);
    QGeoPositionInfo info = updateSpy.takeFirst().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(!info.hasAttribute(QGeoPositionInfo::GroundSpeed));
    // enable velocity updates again
    geocluemock_set_suppress_velocity_update(false);
    updateSpy.clear(); timeoutSpy.clear();
    QTest::qWait(3000);
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 4000);
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(info.hasAttribute(QGeoPositionInfo::GroundSpeed));
    m_source->stopUpdates();

    // Test that bad updatedata produces timeout both on regular updates
    // and single updates
    geocluemock_set_position_fields(0);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!timeoutSpy.isEmpty(), 2000);
    QVERIFY(updateSpy.isEmpty());
    updateSpy.clear(); timeoutSpy.clear();
    m_source->requestUpdate(1000);
    QTRY_VERIFY_WITH_TIMEOUT(!timeoutSpy.isEmpty(), 2000);
    QVERIFY(updateSpy.isEmpty());
    geocluemock_unset_position_fields(); // clear

    // Test that lib works ok with instane lat/lon values
    geocluemock_set_position_latitude(1000);
    updateSpy.clear(); timeoutSpy.clear();
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 2000);
    QVERIFY(timeoutSpy.isEmpty());
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(!info.isValid());
    geocluemock_unset_position_latitude(); // clear

    // Test that invalid velocity updates are not emitted
    geocluemock_set_velocity_fields(0);
    updateSpy.clear(); timeoutSpy.clear();
    QTest::qWait(1500);
    QTRY_VERIFY_WITH_TIMEOUT(!updateSpy.isEmpty(), 2000);
    QVERIFY(timeoutSpy.isEmpty());
    info = updateSpy.takeLast().at(0).value<QGeoPositionInfo>();
    QVERIFY(info.isValid());
    QVERIFY(!info.hasAttribute(QGeoPositionInfo::GroundSpeed));
    geocluemock_unset_velocity_fields();

    // Test that requestUpdate timeouts correctly
    geocluemock_set_suppress_single_update(true);
    geocluemock_set_suppress_regular_updates(true);
    m_source->stopUpdates();
    updateSpy.clear(); timeoutSpy.clear();
    m_source->requestUpdate(2000);
    QTRY_COMPARE_WITH_TIMEOUT(timeoutSpy.count(), 1, 2100);
    QVERIFY(updateSpy.isEmpty());
    geocluemock_set_suppress_single_update(false);
    geocluemock_set_suppress_regular_updates(false);

    // Test changing interval during active updates works ok
    m_source->setUpdateInterval(1000);
    updateSpy.clear(); timeoutSpy.clear();
    m_source->startUpdates();
    QTRY_COMPARE_WITH_TIMEOUT_RANGE(updateSpy.count(), 1, 950, 1050);
    updateSpy.clear();
    m_source->setUpdateInterval(2000);
    QTRY_COMPARE_WITH_TIMEOUT_RANGE(updateSpy.count(), 1, 1900, 2100);
    // Check that unusual
}