diff options
author | alex <alex.blasche@nokia.com> | 2011-10-05 13:52:08 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-05 06:09:07 +0200 |
commit | e7c2c1281a238e4c9e7cf37c4e770b38d8a238a5 (patch) | |
tree | 4718e741aa1929eea2537354c20c65ab09aafe2f /tests | |
parent | 5ab4a6a93365d3bfbcaf360353eb53c53369d046 (diff) | |
download | qtlocation-e7c2c1281a238e4c9e7cf37c4e770b38d8a238a5.tar.gz |
Add new QGeoSatelliteInfo unit test
The test is based on the QtMobility 1.2 version.
Change-Id: I666354b710277da46b97a13f4ee2fbad3f6d1df9
Reviewed-on: http://codereview.qt-project.org/6004
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 5 | ||||
-rw-r--r-- | tests/auto/qgeosatelliteinfo/qgeosatelliteinfo.pro | 7 | ||||
-rw-r--r-- | tests/auto/qgeosatelliteinfo/tst_qgeosatelliteinfo.cpp | 384 |
3 files changed, 394 insertions, 2 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 5e1cbb6a..7165ae12 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -5,13 +5,14 @@ SUBDIRS += geotestplugin \ qgeoaddress \ qgeoboundingbox \ qgeoboundingcircle \ + qgeocodereply \ + qgeocodingmanager \ qgeocoordinate \ qgeolocation \ qgeomaneuver \ qgeopositioninfo \ + qgeosatelliteinfo \ qplace \ - qgeocodereply \ - qgeocodingmanager \ qplacecategory \ qplacecontentrequest \ qplaceeditorial \ diff --git a/tests/auto/qgeosatelliteinfo/qgeosatelliteinfo.pro b/tests/auto/qgeosatelliteinfo/qgeosatelliteinfo.pro new file mode 100644 index 00000000..18235817 --- /dev/null +++ b/tests/auto/qgeosatelliteinfo/qgeosatelliteinfo.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG+=testcase +TARGET=tst_qgeosatelliteinfo + +SOURCES += tst_qgeosatelliteinfo.cpp + +QT += testlib location diff --git a/tests/auto/qgeosatelliteinfo/tst_qgeosatelliteinfo.cpp b/tests/auto/qgeosatelliteinfo/tst_qgeosatelliteinfo.cpp new file mode 100644 index 00000000..b5f26009 --- /dev/null +++ b/tests/auto/qgeosatelliteinfo/tst_qgeosatelliteinfo.cpp @@ -0,0 +1,384 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/location + +#include <qgeosatelliteinfo.h> + +#include <QMetaType> +#include <QObject> +#include <QDebug> +#include <QTest> + +#include <float.h> +#include <limits.h> + +QT_USE_NAMESPACE +Q_DECLARE_METATYPE(QGeoSatelliteInfo) +Q_DECLARE_METATYPE(QGeoSatelliteInfo::Attribute) + +QByteArray tst_qgeosatelliteinfo_debug; + +void tst_qgeosatelliteinfo_messageHandler(QtMsgType type, const char *msg) +{ + switch (type) { + case QtDebugMsg : + tst_qgeosatelliteinfo_debug = QByteArray(msg); + break; + default: + break; + } +} + + +QList<qreal> tst_qgeosatelliteinfo_qrealTestValues() +{ + QList<qreal> values; + +// the following platforms use float for qreal +#if !defined(QT_NO_FPU) && !defined(QT_ARCH_ARM) && !defined(QT_ARCH_WINDOWSCE) && !defined(QT_ARCH_SYMBIAN) + if (qreal(DBL_MIN) == DBL_MIN) + values << DBL_MIN; +#endif + + values << FLT_MIN; + values << -1.0 << 0.0 << 1.0; + values << FLT_MAX; + +// the following platforms use float for qreal +#if !defined(QT_NO_FPU) && !defined(QT_ARCH_ARM) && !defined(QT_ARCH_WINDOWSCE) && !defined(QT_ARCH_SYMBIAN) + if (qreal(DBL_MAX) == DBL_MAX) + values << DBL_MAX; +#endif + + return values; +} + +QList<int> tst_qgeosatelliteinfo_intTestValues() +{ + QList<int> values; + values << INT_MIN << -100 << 0 << 100 << INT_MAX; + return values; +} + +QList<QGeoSatelliteInfo::Attribute> tst_qgeosatelliteinfo_getAttributes() +{ + QList<QGeoSatelliteInfo::Attribute> attributes; + attributes << QGeoSatelliteInfo::Elevation + << QGeoSatelliteInfo::Azimuth; + return attributes; +} + + +class tst_QGeoSatelliteInfo : public QObject +{ + Q_OBJECT + +private: + QGeoSatelliteInfo updateWithAttribute(QGeoSatelliteInfo::Attribute attribute, qreal value) + { + QGeoSatelliteInfo info; + info.setAttribute(attribute, value); + return info; + } + + void addTestData_update() + { + QTest::addColumn<QGeoSatelliteInfo>("info"); + + QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); + for (int i=0; i<intValues.count(); i++) { + QGeoSatelliteInfo info; + info.setPrnNumber(intValues[i]); + QTest::newRow("prn") << info; + } + + for (int i=0; i<intValues.count(); i++) { + QGeoSatelliteInfo info; + info.setSignalStrength(intValues[i]); + QTest::newRow("signal strength") << info; + } + + QList<QGeoSatelliteInfo::Attribute> attributes = tst_qgeosatelliteinfo_getAttributes(); + QList<qreal> qrealValues = tst_qgeosatelliteinfo_qrealTestValues(); + for (int i=0; i<attributes.count(); i++) { + QTest::newRow(qPrintable(QString("Attribute %1 = %2").arg(attributes[i]).arg(qrealValues[i]))) + << updateWithAttribute(attributes[i], qrealValues[i]); + } + } + +private slots: + void constructor() + { + QGeoSatelliteInfo info; + QCOMPARE(info.prnNumber(), -1); + QCOMPARE(info.signalStrength(), -1); + QList<QGeoSatelliteInfo::Attribute> attributes = tst_qgeosatelliteinfo_getAttributes(); + for (int i=0; i<attributes.count(); i++) + QCOMPARE(info.attribute(attributes[i]), qreal(-1.0)); + } + + void constructor_copy() + { + QFETCH(QGeoSatelliteInfo, info); + + QCOMPARE(QGeoSatelliteInfo(info), info); + } + + void constructor_copy_data() + { + addTestData_update(); + } + + void operator_comparison() + { + QFETCH(QGeoSatelliteInfo, info); + + QVERIFY(info == info); + QCOMPARE(info != info, false); + QCOMPARE(info == QGeoSatelliteInfo(), false); + QCOMPARE(info != QGeoSatelliteInfo(), true); + + QVERIFY(QGeoSatelliteInfo() == QGeoSatelliteInfo()); + } + + void operator_comparison_data() + { + addTestData_update(); + } + + void operator_assign() + { + QFETCH(QGeoSatelliteInfo, info); + + QGeoSatelliteInfo info2 = info; + QCOMPARE(info2, info); + } + + void operator_assign_data() + { + addTestData_update(); + } + + void setPrnNumber() + { + QFETCH(int, prn); + + QGeoSatelliteInfo info; + QCOMPARE(info.prnNumber(), -1); + + info.setPrnNumber(prn); + QCOMPARE(info.prnNumber(), prn); + } + + void setPrnNumber_data() + { + QTest::addColumn<int>("prn"); + + QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); + for (int i=0; i<intValues.count(); i++) + QTest::newRow(qPrintable(QString("%1").arg(intValues[i]))) << intValues[i]; + } + + void setSignalStrength() + { + QFETCH(int, signal); + + QGeoSatelliteInfo info; + QCOMPARE(info.signalStrength(), -1); + + info.setSignalStrength(signal); + QCOMPARE(info.signalStrength(), signal); + } + + void setSignalStrength_data() + { + QTest::addColumn<int>("signal"); + + QList<int> intValues = tst_qgeosatelliteinfo_intTestValues(); + for (int i=0; i<intValues.count(); i++) + QTest::newRow(qPrintable(QString("%1").arg(intValues[i]))) << intValues[i]; + } + + void attribute() + { + QFETCH(QGeoSatelliteInfo::Attribute, attribute); + QFETCH(qreal, value); + + QGeoSatelliteInfo u; + QCOMPARE(u.attribute(attribute), qreal(-1.0)); + + u.setAttribute(attribute, value); + QCOMPARE(u.attribute(attribute), value); + + u.removeAttribute(attribute); + QCOMPARE(u.attribute(attribute), qreal(-1.0)); + } + + void attribute_data() + { + QTest::addColumn<QGeoSatelliteInfo::Attribute>("attribute"); + QTest::addColumn<qreal>("value"); + + QList<QGeoSatelliteInfo::Attribute> props; + props << QGeoSatelliteInfo::Elevation + << QGeoSatelliteInfo::Azimuth; + for (int i=0; i<props.count(); i++) { + QTest::newRow(qPrintable(QString("Attribute %1 = -1.0").arg(props[i]))) + << props[i] + << qreal(-1.0); + QTest::newRow(qPrintable(QString("Attribute %1 = 0.0").arg(props[i]))) + << props[i] + << qreal(0.0); + QTest::newRow(qPrintable(QString("Attribute %1 = 1.0").arg(props[i]))) + << props[i] + << qreal(1.0); + } + } + + void hasAttribute() + { + QFETCH(QGeoSatelliteInfo::Attribute, attribute); + QFETCH(qreal, value); + + QGeoSatelliteInfo u; + QVERIFY(!u.hasAttribute(attribute)); + + u.setAttribute(attribute, value); + QVERIFY(u.hasAttribute(attribute)); + + u.removeAttribute(attribute); + QVERIFY(!u.hasAttribute(attribute)); + } + + void hasAttribute_data() + { + attribute_data(); + } + + void removeAttribute() + { + QFETCH(QGeoSatelliteInfo::Attribute, attribute); + QFETCH(qreal, value); + + QGeoSatelliteInfo u; + QVERIFY(!u.hasAttribute(attribute)); + + u.setAttribute(attribute, value); + QVERIFY(u.hasAttribute(attribute)); + + u.removeAttribute(attribute); + QVERIFY(!u.hasAttribute(attribute)); + + u.setAttribute(attribute, value); + QVERIFY(u.hasAttribute(attribute)); + } + + void removeAttribute_data() + { + attribute_data(); + } + + void datastream() + { + QFETCH(QGeoSatelliteInfo, info); + + QByteArray ba; + QDataStream out(&ba, QIODevice::WriteOnly); + out << info; + + QDataStream in(&ba, QIODevice::ReadOnly); + QGeoSatelliteInfo inInfo; + in >> inInfo; + QCOMPARE(inInfo, info); + } + + void datastream_data() + { + addTestData_update(); + } + + void debug() + { + QFETCH(QGeoSatelliteInfo, info); + QFETCH(QByteArray, debugString); + + qInstallMsgHandler(tst_qgeosatelliteinfo_messageHandler); + qDebug() << info; + qInstallMsgHandler(0); + QCOMPARE(QString(tst_qgeosatelliteinfo_debug), QString(debugString)); + } + + void debug_data() + { + QTest::addColumn<QGeoSatelliteInfo>("info"); + QTest::addColumn<QByteArray>("debugString"); + + QGeoSatelliteInfo info; + + QTest::newRow("uninitialized") << info + << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1)"); + + info = QGeoSatelliteInfo(); + info.setPrnNumber(1); + QTest::newRow("with PRN") << info + << QByteArray("QGeoSatelliteInfo(PRN=1, signal-strength=-1)"); + + info = QGeoSatelliteInfo(); + info.setSignalStrength(1); + QTest::newRow("with PRN") << info + << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=1)"); + + info = QGeoSatelliteInfo(); + info.setAttribute(QGeoSatelliteInfo::Elevation, 1.1); + QTest::newRow("with Elevation") << info + << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1, Elevation=1.1)"); + + info = QGeoSatelliteInfo(); + info.setAttribute(QGeoSatelliteInfo::Azimuth, 1.1); + QTest::newRow("with Azimuth") << info + << QByteArray("QGeoSatelliteInfo(PRN=-1, signal-strength=-1, Azimuth=1.1)"); + } +}; + + +QTEST_APPLESS_MAIN(tst_QGeoSatelliteInfo) +#include "tst_qgeosatelliteinfo.moc" |