summaryrefslogtreecommitdiff
path: root/tests/auto/utils
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-07-27 13:37:07 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-01 04:43:44 +0200
commit4c7059968fff72300790d9b00e324a154ab3cc1a (patch)
tree2ac18e9e71ee373d3bfd0dc722299908a7d20a45 /tests/auto/utils
parent173d55eff6f5cc5ae0391a9f26f9ff5f2bad58a4 (diff)
downloadqtlocation-4c7059968fff72300790d9b00e324a154ab3cc1a.tar.gz
Move qlocationtestutils.* to a more appropriate location
qlocationtestutils is no longer specifically dedicated for qgeocoordinate therefore move it into a common utils directory. Change-Id: I3f25d0e1f0524323813f78b0bcf18112d5755ef5 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/auto/utils')
-rw-r--r--tests/auto/utils/qlocationtestutils.cpp95
-rw-r--r--tests/auto/utils/qlocationtestutils_p.h182
2 files changed, 277 insertions, 0 deletions
diff --git a/tests/auto/utils/qlocationtestutils.cpp b/tests/auto/utils/qlocationtestutils.cpp
new file mode 100644
index 00000000..ec876567
--- /dev/null
+++ b/tests/auto/utils/qlocationtestutils.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlocationtestutils_p.h"
+
+bool QLocationTestUtils::hasDefaultSource()
+{
+ return false;
+}
+
+bool QLocationTestUtils::hasDefaultMonitor()
+{
+ return false;
+}
+
+QString QLocationTestUtils::addNmeaChecksumAndBreaks(const QString &sentence)
+{
+ Q_ASSERT(sentence[0] == '$' && sentence[sentence.length()-1] == '*');
+
+ // XOR byte value of all characters between '$' and '*'
+ int result = 0;
+ for (int i=1; i<sentence.length()-1; i++)
+ result ^= sentence[i].toLatin1();
+ QString sum;
+ sum.sprintf("%02x", result);
+ return sentence + sum + "\r\n";
+}
+
+QString QLocationTestUtils::createRmcSentence(const QDateTime &dt)
+{
+ QString time = dt.toString("hhmmss.zzz");
+ QString date = dt.toString("ddMMyy");
+ QString nmea = QString("$GPRMC,%1,A,2730.83609,S,15301.87844,E,0.7,9.0,%2,11.2,W,A*")
+ .arg(time).arg(date);
+ return addNmeaChecksumAndBreaks(nmea);
+}
+
+QString QLocationTestUtils::createGgaSentence(const QTime &time)
+{
+ QString nmea = QString("$GPGGA,%1,2734.76859,S,15305.99361,E,1,04,3.5,49.4,M,39.2,M,,*")
+ .arg(time.toString("hhmmss.zzz"));
+ return addNmeaChecksumAndBreaks(nmea);
+}
+
+QString QLocationTestUtils::createGgaSentence(int lat, int lng, const QTime &time) {
+ QString nmea = QString("$GPGGA,%1,%200.00000,S,%300.,E,1,04,3.5,49.4,M,39.2,M,,*")
+ .arg(time.toString("hhmmss.zzz")).arg(lat).arg(lng);
+ return addNmeaChecksumAndBreaks(nmea);
+}
+
+QString QLocationTestUtils::createZdaSentence(const QDateTime &dt)
+{
+ QString time = dt.toString("hhmmss.zzz");
+ QString nmea = QString("$GPZDA,%1,%2,%3,%4,,*")
+ .arg(time).arg(dt.toString("dd")).arg(dt.toString("MM")).arg(dt.toString("yyyy"));
+ return addNmeaChecksumAndBreaks(nmea);
+}
diff --git a/tests/auto/utils/qlocationtestutils_p.h b/tests/auto/utils/qlocationtestutils_p.h
new file mode 100644
index 00000000..c40441dd
--- /dev/null
+++ b/tests/auto/utils/qlocationtestutils_p.h
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOCATIONTESTUTILS_P_H
+#define QLOCATIONTESTUTILS_P_H
+
+#include <QDebug>
+#include <QString>
+#include <QTest>
+
+namespace QLocationTestUtils
+{
+ bool hasDefaultSource();
+ bool hasDefaultMonitor();
+
+ QString addNmeaChecksumAndBreaks(const QString &sentence);
+
+ QString createRmcSentence(const QDateTime &dt);
+ QString createGgaSentence(const QTime &time);
+ QString createGgaSentence(int lat, int lng, const QTime &time);
+ QString createZdaSentence(const QDateTime &dt);
+
+ //The purpose of compareEquality() is to test equality
+ //operators where it is expected that A == B.
+ template<typename A, typename B>
+ bool compareEquality(const A &first, const B &second) {
+ if (first != second) {
+ qWarning() << "compareEquality() failed: first != second";
+ return false;
+ }
+
+ if (second != first) {
+ qWarning() << "compareEquality() failed: second != first";
+ return false;
+ }
+
+ if (!(first == second)) {
+ qWarning() << "compareEquality() failed: !(first == second)";
+ return false;
+ }
+
+ if (!(second == first)) {
+ qWarning() << "compareEquality() failed: !(second == first)";
+ return false;
+ }
+
+ return true;
+ }
+
+ //The purpose of compareInequality() is to test equality
+ //operators where it is expected that A != B.
+ //Using !compareEquality(...) is not sufficient because
+ //only the first operator checked would end up being tested.
+ template<typename A, typename B>
+ bool compareInequality(const A &first, const B &second) {
+ if (!(first != second)){
+ qWarning() << "compareInequality() failed: !(first != second)";
+ return false;
+ }
+
+ if (!(second != first)) {
+ qWarning() << "compareInequality() failed: !(second != first)";
+ return false;
+ }
+
+ if (first == second) {
+ qWarning() << "compareInequality() failed: first == second)";
+ return false;
+ }
+
+ if (second == first) {
+ qWarning() << "compareInequality() failed: second == first";
+ return false;
+ }
+ return true;
+ }
+
+ // Tests conversions between sub and base classes
+ // TC (test case) must implement:
+ // SubClass initialSubObject();
+ // bool checkType(const BaseClass &)
+ // void detach(BaseClass *) - calls a mutator method, but doesn't actually modify the
+ // property to something different.
+ // void setSubClassProperty(SubClass *) - sets a property in the subclass instance
+ template<typename TC, typename BaseClass, typename SubClass>
+ void testConversion(TC *tc) {
+ SubClass sub = tc->initialSubObject();
+ //check conversion from SubClass -> BaseClass
+ //using assignment operator
+ BaseClass base;
+ base = sub;
+ QVERIFY(QLocationTestUtils::compareEquality(base, sub));
+ QVERIFY(tc->checkType(base));
+
+ //check comparing base classes
+ BaseClass base2;
+ base2 = sub;
+ QVERIFY(QLocationTestUtils::compareEquality(base, base2));
+
+ //check conversion from BaseClass -> SubClass
+ //using assignment operator
+ SubClass sub2;
+ sub2 = base;
+ QVERIFY(QLocationTestUtils::compareEquality(sub, sub2));
+ QVERIFY(tc->checkType(sub2));
+
+ //check that equality still holds with detachment of underlying data pointer
+ tc->detach(&base);
+ sub2 = base;
+ QVERIFY(QLocationTestUtils::compareEquality(sub, sub2));
+ QVERIFY(QLocationTestUtils::compareEquality(sub, base));
+ QVERIFY(QLocationTestUtils::compareEquality(base, base2));
+
+ //check that comparing objects are not the same
+ //when an underlying subclass field has been modified
+ tc->setSubClassProperty(&sub2);
+ base2 = sub2;
+ QVERIFY(QLocationTestUtils::compareInequality(sub, sub2));
+ QVERIFY(QLocationTestUtils::compareInequality(sub, base2));
+ QVERIFY(QLocationTestUtils::compareInequality(base, base2));
+
+ //check conversion from SubClass -> BaseClass
+ //using copy constructor
+ BaseClass base3(sub);
+ QVERIFY(QLocationTestUtils::compareEquality(sub, base3));
+ QVERIFY(QLocationTestUtils::compareEquality(base, base3));
+
+ //check conversion from BaseClass -> SubClass
+ //using copy constructor
+ SubClass sub3(base3);
+ QVERIFY(QLocationTestUtils::compareEquality(sub, sub3));
+
+ //check conversion to subclass using a default base class instance
+ BaseClass baseDefault;
+ SubClass subDefault;
+ SubClass sub4(baseDefault);
+ QVERIFY(QLocationTestUtils::compareEquality(sub4, subDefault));
+
+ SubClass sub5 = baseDefault;
+ QVERIFY(QLocationTestUtils::compareEquality(sub5, subDefault));
+ }
+};
+
+#endif