qtmobility/tests/benchmarks/location/tst_bm_location.cpp
changeset 14 6fbed849b4f4
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include <QApplication>
       
    42 #include <QtTest/QtTest>
       
    43 #include <QDebug>
       
    44 #include <QEventLoop>
       
    45 #include <QTimer>
       
    46 
       
    47 #include <qdebug.h>
       
    48 
       
    49 #include <qgeopositioninfosource.h>
       
    50 #include <qgeosatelliteinfosource.h>
       
    51 
       
    52 QTM_USE_NAMESPACE
       
    53 
       
    54 class tst_bm_location : public QObject
       
    55 {
       
    56     Q_OBJECT
       
    57 
       
    58 public:    
       
    59     
       
    60 private slots:
       
    61     void initTestCase();
       
    62     void cleanupTestCase();
       
    63     
       
    64 //    void tst_createTime_data();
       
    65     void tst_ps_createTime();
       
    66 //    void tst_ps_createTime_2nd();
       
    67     void tst_ps_setInterval();
       
    68     void tst_ps_interval();
       
    69     void tst_ps_setMethod();
       
    70     void tst_ps_method();
       
    71     void tst_ps_lastKnownPos();
       
    72     void tst_ps_supportedPodMethods();
       
    73     void tst_ps_minUpdateInterval();
       
    74     void tst_ps_startRequest();
       
    75     void tst_ps_stopUpdates();
       
    76     void tst_ps_requestUpdates();
       
    77     
       
    78     void tst_ps_getUpdate();
       
    79     
       
    80     void tst_si_createTime();
       
    81     void tst_si_startUpdates();
       
    82     void tst_si_stopUpdates();    
       
    83     void tst_si_requestUpdates();
       
    84     
       
    85     void tst_si_getUpdate();
       
    86     
       
    87     
       
    88 public slots:
       
    89     void timeout();
       
    90     
       
    91     void positionUpdated(const QGeoPositionInfo &update);
       
    92     void updateTimeout();
       
    93     
       
    94     void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites);
       
    95     void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites);
       
    96 
       
    97 private:    
       
    98     QEventLoop *loop;
       
    99     QTimer *timer;
       
   100     
       
   101     int early_exit;
       
   102 
       
   103 };
       
   104 
       
   105 
       
   106 void tst_bm_location::initTestCase()
       
   107 {
       
   108   loop = new QEventLoop;
       
   109   timer = new QTimer(this);
       
   110   timer->setSingleShot(true);
       
   111   connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
       
   112 
       
   113 }
       
   114 
       
   115 void tst_bm_location::cleanupTestCase()
       
   116 {
       
   117   delete loop;
       
   118   delete timer;
       
   119 }
       
   120 
       
   121 void tst_bm_location::tst_ps_createTime()
       
   122 {   
       
   123     QGeoPositionInfoSource *ps = NULL;
       
   124 
       
   125     QBENCHMARK {
       
   126         ps =  QGeoPositionInfoSource::createDefaultSource(NULL);
       
   127     }
       
   128 
       
   129     delete ps;
       
   130 }
       
   131 
       
   132 void tst_bm_location::tst_ps_setInterval()
       
   133 {
       
   134   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   135   
       
   136   QBENCHMARK {
       
   137     ps->setUpdateInterval(3000);    
       
   138   }
       
   139   delete ps;  
       
   140 }
       
   141 
       
   142 void tst_bm_location::tst_ps_interval()
       
   143 {
       
   144   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   145   
       
   146   QBENCHMARK {
       
   147     ps->updateInterval();    
       
   148   }
       
   149   delete ps;  
       
   150 }
       
   151 
       
   152 void tst_bm_location::tst_ps_setMethod()
       
   153 {
       
   154   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   155   
       
   156   QBENCHMARK {
       
   157     ps->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);    
       
   158   }
       
   159   delete ps;    
       
   160 }
       
   161 
       
   162 
       
   163 void tst_bm_location::tst_ps_method()
       
   164 {
       
   165   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   166   
       
   167   QBENCHMARK {
       
   168     ps->preferredPositioningMethods();    
       
   169   }
       
   170   delete ps;  
       
   171 }
       
   172 
       
   173 void tst_bm_location::tst_ps_lastKnownPos()
       
   174 {
       
   175   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   176   
       
   177   QBENCHMARK {
       
   178     ps->lastKnownPosition();    
       
   179   }
       
   180   delete ps;  
       
   181 
       
   182 }
       
   183 //void tst_bm_location::tst_ps_createTime_2nd()
       
   184 //{
       
   185 //    QObject *o = new QObject;
       
   186 //    QGeoPositionInfoSource *ps = NULL;
       
   187 //
       
   188 //    QBENCHMARK {
       
   189 //        ps =  QGeoPositionInfoSource::createDefaultSource(o);
       
   190 //    }
       
   191 //
       
   192 //    delete ps;
       
   193 //    delete o;
       
   194 //}
       
   195 
       
   196 void tst_bm_location::tst_ps_supportedPodMethods()
       
   197 {
       
   198   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   199   
       
   200   QBENCHMARK {
       
   201     ps->supportedPositioningMethods();    
       
   202   }
       
   203   delete ps;    
       
   204 }
       
   205 
       
   206 void tst_bm_location::tst_ps_minUpdateInterval()
       
   207 {
       
   208   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   209   
       
   210   QBENCHMARK {
       
   211     ps->minimumUpdateInterval();    
       
   212   }
       
   213   delete ps;  
       
   214 }
       
   215 
       
   216 void tst_bm_location::tst_ps_startRequest()
       
   217 {
       
   218   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   219   
       
   220   QBENCHMARK {
       
   221     ps->startUpdates();    
       
   222   }
       
   223   delete ps;  
       
   224 }
       
   225 
       
   226 void tst_bm_location::tst_ps_stopUpdates()
       
   227 {
       
   228   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   229   
       
   230   QBENCHMARK {
       
   231     ps->stopUpdates();    
       
   232   }
       
   233   delete ps;  
       
   234 }
       
   235 
       
   236 void tst_bm_location::tst_ps_requestUpdates()
       
   237 {
       
   238   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   239   
       
   240   QBENCHMARK {
       
   241     ps->requestUpdate(5000);    
       
   242   }
       
   243   delete ps;  
       
   244 }
       
   245 
       
   246 void tst_bm_location::tst_ps_getUpdate(){ // XXX test may not produce stable results, might need to be removed
       
   247   QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(NULL);
       
   248 
       
   249   early_exit = 0;
       
   250   connect(ps, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
       
   251   connect(ps, SIGNAL(positionUpdated(const QGeoPositionInfo &)), 
       
   252       this, SLOT(positionUpdated(const QGeoPositionInfo &)));
       
   253     
       
   254   timer->start(20000);
       
   255   ps->startUpdates(); // XXX work around for bug, remove me
       
   256   
       
   257   QBENCHMARK {
       
   258     ps->requestUpdate(15000);    
       
   259     if(early_exit || (loop->exec() > 1)){
       
   260       QFAIL("Test failed to provide any results within backup timeout");      
       
   261     }
       
   262   }
       
   263   
       
   264   ps->stopUpdates();
       
   265   delete ps;  
       
   266 }
       
   267 
       
   268 void tst_bm_location::updateTimeout()
       
   269 {
       
   270   qDebug() << "Update timeout";
       
   271   early_exit = 1;
       
   272   loop->exit(1);
       
   273 }
       
   274 
       
   275 void tst_bm_location::timeout()
       
   276 {
       
   277   qDebug() << "Timer timeout";
       
   278   early_exit = 1;
       
   279   loop->exit(2);  
       
   280 }
       
   281 
       
   282 void tst_bm_location::positionUpdated(const QGeoPositionInfo &)
       
   283 {    
       
   284   early_exit = 1;
       
   285   loop->exit(0);
       
   286 }
       
   287 
       
   288 void tst_bm_location::tst_si_createTime()
       
   289 { 
       
   290   QGeoSatelliteInfoSource *si = NULL;
       
   291   QBENCHMARK {
       
   292    si = QGeoSatelliteInfoSource::createDefaultSource(NULL);        
       
   293   }
       
   294   delete si;    
       
   295 }
       
   296 
       
   297 void tst_bm_location::tst_si_startUpdates()
       
   298 {
       
   299   QGeoSatelliteInfoSource *si = QGeoSatelliteInfoSource::createDefaultSource(NULL);
       
   300   
       
   301   QBENCHMARK {
       
   302     si->startUpdates();
       
   303   }
       
   304   delete si;
       
   305 }
       
   306 
       
   307 void tst_bm_location::tst_si_stopUpdates()
       
   308 {
       
   309   QGeoSatelliteInfoSource *si = QGeoSatelliteInfoSource::createDefaultSource(NULL);
       
   310   
       
   311   QBENCHMARK {
       
   312     si->stopUpdates();
       
   313   }
       
   314   delete si;
       
   315 }
       
   316 
       
   317 void tst_bm_location::tst_si_requestUpdates()
       
   318 {
       
   319   QGeoSatelliteInfoSource *si = QGeoSatelliteInfoSource::createDefaultSource(NULL);
       
   320   
       
   321   QBENCHMARK {
       
   322     si->requestUpdate(0);
       
   323   }
       
   324   delete si;
       
   325 }
       
   326 
       
   327 void tst_bm_location::tst_si_getUpdate(){ // XXX test may not produce stable results, might need to be removed
       
   328   QGeoSatelliteInfoSource *si = QGeoSatelliteInfoSource::createDefaultSource(NULL);
       
   329   
       
   330   early_exit = 0;
       
   331   connect(si, SIGNAL(requestTimeout()), this, SLOT(updateTimeout()));
       
   332   connect(si, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)), 
       
   333       this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));
       
   334   connect(si, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)), 
       
   335       this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)));
       
   336     
       
   337   timer->start(20000);
       
   338   si->startUpdates(); // XXX work around for bug, remove me
       
   339   
       
   340   QBENCHMARK {
       
   341     si->requestUpdate(15000);    
       
   342     if(early_exit || (loop->exec() > 1)){
       
   343       QFAIL("Test failed to provide any results within backup timeout");      
       
   344     }
       
   345   }
       
   346   
       
   347   si->stopUpdates();
       
   348   delete si;  
       
   349 }
       
   350 
       
   351 void tst_bm_location::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)
       
   352 {
       
   353 //  qDebug() << "Got location info" << update.timestamp() << " - " << update.isValid();
       
   354   early_exit = 1;
       
   355   loop->exit(0);
       
   356 }
       
   357 
       
   358 void tst_bm_location::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)
       
   359 {
       
   360 //  qDebug() << "Got location info" << update.timestamp() << " - " << update.isValid();
       
   361   early_exit = 1;
       
   362   loop->exit(0);
       
   363 }
       
   364 
       
   365 
       
   366 
       
   367 int main(int argc, char **argv){
       
   368 
       
   369     QApplication app(argc, argv);
       
   370     
       
   371     tst_bm_location test1;
       
   372     QTest::qExec(&test1, argc, argv);
       
   373     
       
   374 }
       
   375 //QTEST_MAIN(tst_messaging);
       
   376 
       
   377 
       
   378 #include "tst_bm_location.moc"
       
   379