summaryrefslogtreecommitdiff
path: root/tests/auto/qplaceresult
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-07-23 17:44:10 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-31 06:18:16 +0200
commit173d55eff6f5cc5ae0391a9f26f9ff5f2bad58a4 (patch)
tree0c95ac5ce1b146d64f47e124d4932b52ed214878 /tests/auto/qplaceresult
parent7e064646ff9eb88d387461a01a761f087d307eb6 (diff)
downloadqtlocation-173d55eff6f5cc5ae0391a9f26f9ff5f2bad58a4.tar.gz
Fixes for QPlaceResult + unit tests
-Comparing QPlaceResult objects resulted in a crash due to a comparison function incorrectly calling itself recursively. -Copying a QPlaceResult object did not copy the data fields from QPlaceSearchResult This patch fixes the above issues and also has a comprehensive set of unit tests for QPlaceResult. Task-number: QTBUG-26611 Change-Id: I9b6dcc90e5f061d2e268051c682291adf1b04c7b Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/auto/qplaceresult')
-rw-r--r--tests/auto/qplaceresult/qplaceresult.pro7
-rw-r--r--tests/auto/qplaceresult/tst_qplaceresult.cpp283
2 files changed, 290 insertions, 0 deletions
diff --git a/tests/auto/qplaceresult/qplaceresult.pro b/tests/auto/qplaceresult/qplaceresult.pro
new file mode 100644
index 00000000..966c2404
--- /dev/null
+++ b/tests/auto/qplaceresult/qplaceresult.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+CONFIG += testcase
+TARGET = tst_qplaceresult
+
+SOURCES += tst_qplaceresult.cpp
+
+QT += location testlib
diff --git a/tests/auto/qplaceresult/tst_qplaceresult.cpp b/tests/auto/qplaceresult/tst_qplaceresult.cpp
new file mode 100644
index 00000000..f54fef9b
--- /dev/null
+++ b/tests/auto/qplaceresult/tst_qplaceresult.cpp
@@ -0,0 +1,283 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite module 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 <QtCore/QString>
+#include <QtLocation/QPlaceResult>
+#include <QtLocation/QPlaceIcon>
+#include <QtTest/QtTest>
+
+#include "../qgeocoordinate/qlocationtestutils_p.h"
+
+QT_USE_NAMESPACE
+
+class tst_QPlaceResult : public QObject
+{
+ Q_OBJECT
+
+public:
+ QPlaceResult initialSubObject();
+ bool checkType(const QPlaceSearchResult &);
+ void detach(QPlaceSearchResult *);
+ void setSubClassProperty(QPlaceResult *);
+
+private Q_SLOTS:
+ void constructorTest();
+ void title();
+ void icon();
+ void distance();
+ void place();
+ void sponsored();
+ void conversion();
+};
+
+QPlaceResult tst_QPlaceResult::initialSubObject()
+{
+ QPlaceResult placeResult;
+ placeResult.setTitle(QStringLiteral("title"));
+
+ QPlaceIcon icon;
+ QVariantMap parameters;
+ parameters.insert(QPlaceIcon::SingleUrl,
+ QUrl(QStringLiteral("file:///opt/icons/icon.png")));
+ icon.setParameters(parameters);
+ placeResult.setIcon(icon);
+
+ QPlace place;
+ place.setName(QStringLiteral("place"));
+ placeResult.setPlace(place);
+
+ placeResult.setDistance(5);
+ placeResult.setSponsored(true);
+
+ return placeResult;
+}
+
+bool tst_QPlaceResult::checkType(const QPlaceSearchResult &result)
+{
+ return result.type() == QPlaceSearchResult::PlaceResult;
+}
+
+void tst_QPlaceResult::detach(QPlaceSearchResult * result)
+{
+ result->setTitle("title");
+}
+
+void tst_QPlaceResult::setSubClassProperty(QPlaceResult *result)
+{
+ result->setSponsored(false);
+}
+
+void tst_QPlaceResult::constructorTest()
+{
+ QPlaceResult result;
+ QCOMPARE(result.type(), QPlaceSearchResult::PlaceResult);
+
+ result.setTitle(QStringLiteral("title"));
+
+ QPlaceIcon icon;
+ QVariantMap parameters;
+ parameters.insert(QLatin1String("paramKey"), QLatin1String("paramValue"));
+ icon.setParameters(parameters);
+ result.setIcon(icon);
+
+ QPlace place;
+ place.setName("place");
+ result.setPlace(place);
+
+ result.setDistance(500);
+ result.setSponsored(true);
+
+ //check copy constructor
+ QPlaceResult result2(result);
+ QCOMPARE(result2.title(), QStringLiteral("title"));
+ QCOMPARE(result2.icon(), icon);
+ QCOMPARE(result2.place(), place);
+ QVERIFY(qFuzzyCompare(result.distance(), 500));
+ QCOMPARE(result2.isSponsored(), true);
+
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ //check results are the same after detachment of underlying shared data pointer
+ result2.setTitle("title");
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ //check construction of SearchResult using a PlaceResult
+ QPlaceSearchResult searchResult(result);
+ QCOMPARE(searchResult.title(), QStringLiteral("title"));
+ QCOMPARE(searchResult.icon(), icon);
+ QVERIFY(QLocationTestUtils::compareEquality(searchResult, result));
+ QVERIFY(searchResult.type() == QPlaceSearchResult::PlaceResult);
+ result2 = searchResult;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ //check construction of a SearchResult using a SearchResult
+ //that is actually a PlaceResult underneath
+ QPlaceSearchResult searchResult2(searchResult);
+ QCOMPARE(searchResult2.title(), QStringLiteral("title"));
+ QCOMPARE(searchResult2.icon(), icon);
+ QVERIFY(QLocationTestUtils::compareEquality(searchResult2, result));
+ QVERIFY(QLocationTestUtils::compareEquality(searchResult, searchResult2));
+ QVERIFY(searchResult2.type() == QPlaceSearchResult::PlaceResult);
+ result2 = searchResult2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::title()
+{
+ QPlaceResult result;
+ QVERIFY(result.title().isEmpty());
+
+ result.setTitle(QStringLiteral("title"));
+ QCOMPARE(result.title(), QStringLiteral("title"));
+
+ result.setTitle(QString());
+ QVERIFY(result.title().isEmpty());
+
+ QPlaceResult result2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ result2.setTitle("title");
+ QVERIFY(QLocationTestUtils::compareInequality(result, result2));
+
+ result.setTitle("title");
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::icon()
+{
+ QPlaceResult result;
+ QVERIFY(result.icon().isEmpty());
+
+ QPlaceIcon icon;
+ QVariantMap iconParams;
+ iconParams.insert(QLatin1String("paramKey"), QLatin1String("paramValue"));
+ icon.setParameters(iconParams);
+ result.setIcon(icon);
+ QCOMPARE(result.icon(), icon);
+
+ result.setIcon(QPlaceIcon());
+ QVERIFY(result.icon().isEmpty());
+
+ QPlaceResult result2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ result2.setIcon(icon);
+ QVERIFY(QLocationTestUtils::compareInequality(result, result2));
+
+ result.setIcon(icon);
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::distance()
+{
+ QPlaceResult result;
+ QVERIFY(qIsNaN(result.distance()));
+
+ result.setDistance(3.14);
+ QVERIFY(qFuzzyCompare(result.distance(), 3.14));
+
+ result.setDistance(qQNaN());
+ QVERIFY(qIsNaN(result.distance()));
+
+ QPlaceResult result2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ result2.setDistance(3.14);
+ QVERIFY(QLocationTestUtils::compareInequality(result, result2));
+
+ result.setDistance(3.14);
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::place()
+{
+ QPlaceResult result;
+ QCOMPARE(result.place(), QPlace());
+
+ QPlace place;
+ place.setName("place");
+ result.setPlace (place);
+ QCOMPARE(result.place(), place);
+
+ result.setPlace(QPlace());
+ QCOMPARE(result.place(), QPlace());
+
+ QPlaceResult result2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ result2.setPlace(place);
+ QVERIFY(QLocationTestUtils::compareInequality(result, result2));
+
+ result.setPlace(place);
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::sponsored()
+{
+ QPlaceResult result;
+ QCOMPARE(result.isSponsored(), false);
+
+ result.setSponsored(true);
+ QCOMPARE(result.isSponsored(), true);
+
+ result.setSponsored(false);
+ QCOMPARE(result.isSponsored(), false);
+
+ QPlaceResult result2;
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+
+ result2.setSponsored(true);
+ QVERIFY(QLocationTestUtils::compareInequality(result, result2));
+
+ result.setSponsored(true);
+ QVERIFY(QLocationTestUtils::compareEquality(result, result2));
+}
+
+void tst_QPlaceResult::conversion()
+{
+ QLocationTestUtils::testConversion<tst_QPlaceResult,
+ QPlaceSearchResult,
+ QPlaceResult>(this);
+}
+
+QTEST_APPLESS_MAIN(tst_QPlaceResult)
+
+#include "tst_qplaceresult.moc"