tests/auto/qlocationtestutils.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 
       
    42 #include "qlocationtestutils_p.h"
       
    43 
       
    44 #if defined(Q_OS_SYMBIAN)
       
    45     #include <e32std.h>
       
    46 #endif
       
    47 
       
    48 void QLocationTestUtils::uheap_mark()
       
    49 {
       
    50 #if defined(Q_OS_SYMBIAN)
       
    51     __UHEAP_MARK;
       
    52 #endif
       
    53 }
       
    54 
       
    55 void QLocationTestUtils::uheap_mark_end()
       
    56 {
       
    57 #if defined(Q_OS_SYMBIAN)
       
    58     __UHEAP_MARKEND;
       
    59 #endif
       
    60 }
       
    61 
       
    62 bool QLocationTestUtils::hasDefaultSource()
       
    63 {
       
    64 #if defined(Q_OS_SYMBIAN)
       
    65     return true;
       
    66 #elif defined (Q_OS_WINCE)
       
    67     return true;
       
    68 #else 
       
    69     return false;    
       
    70 #endif
       
    71 }
       
    72 
       
    73 bool QLocationTestUtils::hasDefaultMonitor()
       
    74 {
       
    75 #if defined(Q_OS_SYMBIAN) && defined(QT_LOCATION_S60_MONITORING)
       
    76     return true;
       
    77 #elif defined (Q_WS_MAEMO_5)
       
    78     return true;
       
    79 #else
       
    80     return false;
       
    81 #endif
       
    82 }
       
    83 
       
    84 QString QLocationTestUtils::addNmeaChecksumAndBreaks(const QString &sentence)
       
    85 {
       
    86     Q_ASSERT(sentence[0] == '$' && sentence[sentence.length()-1] == '*');
       
    87 
       
    88     // XOR byte value of all characters between '$' and '*'
       
    89     int result = 0;
       
    90     for (int i=1; i<sentence.length()-1; i++)
       
    91         result ^= sentence[i].toAscii();
       
    92     QString sum;
       
    93     sum.sprintf("%02x", result);
       
    94     return sentence + sum + "\r\n";
       
    95 }
       
    96 
       
    97 QString QLocationTestUtils::createRmcSentence(const QDateTime &dt)
       
    98 {
       
    99     QString time = dt.toString("hhmmss.zzz");
       
   100     QString date = dt.toString("ddMMyy");
       
   101     QString nmea = QString("$GPRMC,%1,A,2730.83609,S,15301.87844,E,0.7,9.0,%2,11.2,W,A*")
       
   102         .arg(time).arg(date);
       
   103     return addNmeaChecksumAndBreaks(nmea);
       
   104 }
       
   105 
       
   106 QString QLocationTestUtils::createGgaSentence(const QTime &time)
       
   107 {
       
   108     QString nmea = QString("$GPGGA,%1,2734.76859,S,15305.99361,E,1,04,3.5,49.4,M,39.2,M,,*")
       
   109             .arg(time.toString("hhmmss.zzz"));
       
   110     return addNmeaChecksumAndBreaks(nmea);
       
   111 }
       
   112 
       
   113 QString QLocationTestUtils::createGgaSentence(int lat, int lng, const QTime &time) {
       
   114     QString nmea = QString("$GPGGA,%1,%200.00000,S,%300.,E,1,04,3.5,49.4,M,39.2,M,,*")
       
   115             .arg(time.toString("hhmmss.zzz")).arg(lat).arg(lng);
       
   116     return addNmeaChecksumAndBreaks(nmea);
       
   117 }
       
   118 
       
   119 QString QLocationTestUtils::createZdaSentence(const QDateTime &dt)
       
   120 {
       
   121     QString time = dt.toString("hhmmss.zzz");
       
   122     QString nmea = QString("$GPZDA,%1,%2,%3,%4,,*")
       
   123         .arg(time).arg(dt.toString("dd")).arg(dt.toString("MM")).arg(dt.toString("yyyy"));
       
   124     return addNmeaChecksumAndBreaks(nmea);
       
   125 }