diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/qplacemanager/tst_qplacemanager.cpp | 109 | ||||
-rw-r--r-- | tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp | 107 | ||||
-rw-r--r-- | tests/auto/qplacemanager_nokia/tst_qplacemanager_nokia.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qplacematchreply/qplacematchreply.pro | 7 | ||||
-rw-r--r-- | tests/auto/qplacematchreply/tst_qplacematchreply.cpp | 124 | ||||
-rw-r--r-- | tests/auto/qplacematchrequest/qplacematchrequest.pro | 6 | ||||
-rw-r--r-- | tests/auto/qplacematchrequest/tst_qplacematchrequest.cpp | 179 |
8 files changed, 531 insertions, 5 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 0157b2c2..3b7c032e 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -9,6 +9,8 @@ SUBDIRS += qplace \ qplaceeditorial \ qplacemanager \ qplacemanager_nokia \ + qplacematchreply \ + qplacematchrequest \ qplaceimage \ qplaceratings \ qplacereply \ diff --git a/tests/auto/qplacemanager/tst_qplacemanager.cpp b/tests/auto/qplacemanager/tst_qplacemanager.cpp index 74864630..e42ea0ff 100644 --- a/tests/auto/qplacemanager/tst_qplacemanager.cpp +++ b/tests/auto/qplacemanager/tst_qplacemanager.cpp @@ -39,12 +39,28 @@ ** ****************************************************************************/ +#include <QtCore/QMetaType> #include <QString> #include <QtTest/QtTest> #include <qgeoserviceprovider.h> #include <qplacemanager.h> + +#ifndef WAIT_UNTIL +#define WAIT_UNTIL(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + } while (0) +#endif + QT_USE_NAMESPACE class tst_QPlaceManager : public QObject @@ -58,8 +74,11 @@ private Q_SLOTS: void compatiblePlace(); void testMetadata(); void testLocales(); + void testMatchUnsupported(); private: + bool checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError); + QGeoServiceProvider *provider; QPlaceManager *placeManager; }; @@ -102,6 +121,13 @@ void tst_QPlaceManager::testLocales() QCOMPARE(placeManager->locales().at(1), en_UK); } +void tst_QPlaceManager::testMatchUnsupported() +{ + QPlaceMatchRequest request; + QPlaceMatchReply *reply = placeManager->matchingPlaces(request); + QVERIFY(checkSignals(reply, QPlaceReply::UnsupportedError)); +} + void tst_QPlaceManager::compatiblePlace() { QPlace place; @@ -120,6 +146,89 @@ void tst_QPlaceManager::cleanupTestCase() delete provider; } +bool tst_QPlaceManager::checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError) +{ + QSignalSpy finishedSpy(reply, SIGNAL(finished())); + QSignalSpy errorSpy(reply, SIGNAL(error(QPlaceReply::Error,QString))); + QSignalSpy managerFinishedSpy(placeManager, SIGNAL(finished(QPlaceReply*))); + QSignalSpy managerErrorSpy(placeManager,SIGNAL(error(QPlaceReply*,QPlaceReply::Error,QString))); + + if (expectedError != QPlaceReply::NoError) { + //check that we get an error signal from the reply + WAIT_UNTIL(errorSpy.count() == 1); + if (errorSpy.count() != 1) { + qWarning() << "Error signal for search operation not received"; + return false; + } + + //check that we get the correct error from the reply's signal + QPlaceReply::Error actualError = qvariant_cast<QPlaceReply::Error>(errorSpy.at(0).at(0)); + if (actualError != expectedError) { + qWarning() << "Actual error code in reply signal does not match expected error code"; + qWarning() << "Actual error code = " << actualError; + qWarning() << "Expected error coe =" << expectedError; + return false; + } + + //check that we get an error signal from the manager + WAIT_UNTIL(managerErrorSpy.count() == 1); + if (managerErrorSpy.count() !=1) { + qWarning() << "Error signal from manager for search operation not received"; + return false; + } + + //check that we get the correct reply instance in the error signal from the manager + if (qvariant_cast<QPlaceReply*>(managerErrorSpy.at(0).at(0)) != reply) { + qWarning() << "Reply instance in error signal from manager is incorrect"; + return false; + } + + //check that we get the correct error from the signal of the manager + actualError = qvariant_cast<QPlaceReply::Error>(managerErrorSpy.at(0).at(1)); + if (actualError != expectedError) { + qWarning() << "Actual error code from manager signal does not match expected error code"; + qWarning() << "Actual error code =" << actualError; + qWarning() << "Expected error code = " << expectedError; + return false; + } + } + + //check that we get a finished signal + WAIT_UNTIL(finishedSpy.count() == 1); + if (finishedSpy.count() !=1) { + qWarning() << "Finished signal from reply not received"; + return false; + } + + if (reply->error() != expectedError) { + qWarning() << "Actual error code does not match expected error code"; + qWarning() << "Actual error code: " << reply->error(); + qWarning() << "Expected error code" << expectedError; + return false; + } + + if (expectedError == QPlaceReply::NoError && !reply->errorString().isEmpty()) { + qWarning() << "Expected error was no error but error string was not empty"; + qWarning() << "Error string=" << reply->errorString(); + return false; + } + + //check that we get the finished signal from the manager + WAIT_UNTIL(managerFinishedSpy.count() == 1); + if (managerFinishedSpy.count() != 1) { + qWarning() << "Finished signal from manager not received"; + return false; + } + + //check that the reply instance in the finished signal from the manager is correct + if (qvariant_cast<QPlaceReply *>(managerFinishedSpy.at(0).at(0)) != reply) { + qWarning() << "Reply instance in finished signal from manager is incorrect"; + return false; + } + + return true; +} + QTEST_GUILESS_MAIN(tst_QPlaceManager) #include "tst_qplacemanager.moc" diff --git a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp index 57c484aa..3d0f5e38 100644 --- a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp +++ b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp @@ -50,6 +50,7 @@ #include <qplacemanager.h> #include <qplacecategory.h> #include <qplacecontentreply.h> +#include <qplacematchreply.h> #include <qplacesearchsuggestionreply.h> #include <qplacesearchrequest.h> #include <qplacesearchresult.h> @@ -74,8 +75,6 @@ } while (0) #endif -Q_DECLARE_METATYPE(QPlaceReply::Error); -Q_DECLARE_METATYPE(QPlaceReply *); Q_DECLARE_METATYPE(QPlaceIdReply *); QT_USE_NAMESPACE @@ -113,6 +112,8 @@ private Q_SLOTS: void placeNotifications(); void categoryNotifications(); void compatiblePlace(); + void extendedAttribute(); + void matchingPlaces(); private: bool doSavePlace(const QPlace &place, @@ -148,6 +149,10 @@ private: bool doRemoveCategory(const QPlaceCategory &category, QPlaceReply::Error expectedError = QPlaceReply::NoError); + bool doMatch(const QPlaceMatchRequest &request, + QList<QPlace> *places, + QPlaceReply::Error expectedError = QPlaceReply::NoError); + bool checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError); @@ -1522,7 +1527,92 @@ void tst_QPlaceManagerJsonDb::compatiblePlace() QVERIFY(compatPlace.extendedAttributeTypes().isEmpty()); QCOMPARE(compatPlace.extendedAttribute(QLatin1String("Smoking")), QPlaceAttribute()); - QCOMPARE(compatPlace.visibility(), QtLocation::DeviceVisibility); + QCOMPARE(compatPlace.visibility(), QtLocation::UnspecifiedVisibility); +} + +void tst_QPlaceManagerJsonDb::extendedAttribute() +{ + QPlaceAttribute attribute; + attribute.setLabel(QLatin1String("x_id_nokia")); + attribute.setText(QLatin1String("ae562")); + QPlace place; + place.setExtendedAttribute(QLatin1String("x_id_nokia"), attribute); + + QString placeId; + QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId)); + + QPlace retrievedPlace; + QVERIFY(doFetchDetails(placeId,&retrievedPlace)); + QVERIFY(retrievedPlace.extendedAttributeTypes().contains(QLatin1String("x_id_nokia"))); +} + +void tst_QPlaceManagerJsonDb::matchingPlaces() +{ + QPlace place1; + place1.setPlaceId(QLatin1String("abcd")); + place1.setName("place1"); + + QPlaceAttribute origin1; + origin1.setText("nokia"); + place1.setExtendedAttribute(QLatin1String("x_provider"), origin1); + + QPlace place1Saved; + place1Saved = placeManager->compatiblePlace(place1); + + QString placeId; + QVERIFY(doSavePlace(place1Saved, QPlaceReply::NoError, &placeId)); + place1Saved.setPlaceId(placeId); + + QPlaceSearchResult result1; + result1.setPlace(place1); + + QList<QPlaceSearchResult> results; + results << result1; + + QPlaceMatchRequest matchRequest; + QVariantMap parameters; + parameters.insert(QPlaceMatchRequest::AlternativeId, QLatin1String("x_id_nokia")); + matchRequest.setParameters(parameters); + matchRequest.setResults(results); + QList<QPlace> places; + QVERIFY(doMatch(matchRequest,&places)); + QCOMPARE(places.count(), 1); + QCOMPARE(place1Saved, places.at(0)); + + //try matching multiple places + QPlace nonMatchingPlace; + nonMatchingPlace.setName("Non matching"); + nonMatchingPlace.setPlaceId(QLatin1String("1234")); + QPlaceAttribute originNonMatch; + originNonMatch.setText(QLatin1String("nokia")); + nonMatchingPlace.setExtendedAttribute(QLatin1String("x_provider"),originNonMatch); + QPlaceSearchResult nonMatchingResult; + nonMatchingResult.setPlace(nonMatchingPlace); + results.insert(1, nonMatchingResult); + + QPlace place2; + place2.setName(QLatin1String("place2")); + place2.setPlaceId(QLatin1String("efgh")); + + QPlaceAttribute origin2; + origin2.setText(QLatin1String("nokia")); + place2.setExtendedAttribute(QLatin1String("x_provider"), origin2); + + QPlace place2Saved = placeManager->compatiblePlace(place2); + QVERIFY(doSavePlace(place2Saved, QPlaceReply::NoError, &placeId)); + place2Saved.setPlaceId(placeId); + + QPlaceSearchResult result2; + result2.setPlace(place2); + results.clear(); + results << result1 << nonMatchingResult << result2; + + matchRequest.setResults(results); + QVERIFY(doMatch(matchRequest, &places)); + QCOMPARE(places.count(), 3); + QCOMPARE(places.at(0), place1Saved); + QCOMPARE(places.at(1), QPlace()); + QCOMPARE(places.at(2), place2Saved); } void tst_QPlaceManagerJsonDb::cleanup() @@ -1737,6 +1827,17 @@ bool tst_QPlaceManagerJsonDb::checkSignals(QPlaceReply *reply, QPlaceReply::Erro return true; } +bool tst_QPlaceManagerJsonDb::doMatch(const QPlaceMatchRequest &request, + QList<QPlace> *places, + QPlaceReply::Error expectedError) +{ + QPlaceMatchReply *reply = placeManager->matchingPlaces(request); + bool isSuccessful = checkSignals(reply, expectedError) && + (reply->error() == expectedError); + *places = reply->places(); + return isSuccessful; +} + bool tst_QPlaceManagerJsonDb::compareResults(const QList<QPlaceSearchResult> &results, const QList<QPlace> &expectedResults) { diff --git a/tests/auto/qplacemanager_nokia/tst_qplacemanager_nokia.cpp b/tests/auto/qplacemanager_nokia/tst_qplacemanager_nokia.cpp index c78b11f5..4102a968 100644 --- a/tests/auto/qplacemanager_nokia/tst_qplacemanager_nokia.cpp +++ b/tests/auto/qplacemanager_nokia/tst_qplacemanager_nokia.cpp @@ -60,8 +60,6 @@ } while (0) #endif -Q_DECLARE_METATYPE(QPlaceReply::Error); -Q_DECLARE_METATYPE(QPlaceReply *); Q_DECLARE_METATYPE(QPlaceIdReply *); QT_USE_NAMESPACE diff --git a/tests/auto/qplacematchreply/qplacematchreply.pro b/tests/auto/qplacematchreply/qplacematchreply.pro new file mode 100644 index 00000000..00c1dcd9 --- /dev/null +++ b/tests/auto/qplacematchreply/qplacematchreply.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG += testcase +TARGET = tst_qplacematchreply + +SOURCES += tst_qplacematchreply.cpp + +QT += location testlib diff --git a/tests/auto/qplacematchreply/tst_qplacematchreply.cpp b/tests/auto/qplacematchreply/tst_qplacematchreply.cpp new file mode 100644 index 00000000..05b4d695 --- /dev/null +++ b/tests/auto/qplacematchreply/tst_qplacematchreply.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include <QtLocation/QPlaceMatchReply> + +QT_USE_NAMESPACE + +class TestMatchReply : public QPlaceMatchReply +{ + Q_OBJECT +public: + TestMatchReply(QObject *parent) : QPlaceMatchReply(parent) {} + TestMatchReply() {} + + void setPlaces(const QList<QPlace> &places) { + QPlaceMatchReply::setPlaces(places); + } + + void setRequest(const QPlaceMatchRequest &request) { + QPlaceMatchReply::setRequest(request); + } +}; + +class tst_QPlaceMatchReply : public QObject +{ + Q_OBJECT + +public: + tst_QPlaceMatchReply(); + +private Q_SLOTS: + void constructorTest(); + void typeTest(); + void requestTest(); +// void resultsTest(); +}; + +tst_QPlaceMatchReply::tst_QPlaceMatchReply() +{ +} + +void tst_QPlaceMatchReply::constructorTest() +{ + QPlaceMatchReply *reply = new TestMatchReply(this); + QVERIFY(reply->parent() == this); + delete reply; +} + +void tst_QPlaceMatchReply::typeTest() +{ + TestMatchReply *reply = new TestMatchReply(this); + QVERIFY(reply->type() == QPlaceReply::MatchReply); + delete reply; +} + +void tst_QPlaceMatchReply::requestTest() +{ + TestMatchReply *reply = new TestMatchReply(this); + QPlaceMatchRequest request; + + QPlace place1; + place1.setName(QLatin1String("place1")); + + QPlace place2; + place2.setName(QLatin1String("place2")); + + QList<QPlace> places; + places << place1 << place2; + + request.setPlaces(places); + + reply->setRequest(request); + QCOMPARE(reply->request(), request); + + reply->setRequest(QPlaceMatchRequest()); + QCOMPARE(reply->request(), QPlaceMatchRequest()); + delete reply; +} + + +QTEST_APPLESS_MAIN(tst_QPlaceMatchReply) + +#include "tst_qplacematchreply.moc" diff --git a/tests/auto/qplacematchrequest/qplacematchrequest.pro b/tests/auto/qplacematchrequest/qplacematchrequest.pro new file mode 100644 index 00000000..558cd2ef --- /dev/null +++ b/tests/auto/qplacematchrequest/qplacematchrequest.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +CONFIG += testcase +TARGET = tst_qplacematchrequest +SOURCES += tst_qplacematchrequest.cpp + +QT += location testlib diff --git a/tests/auto/qplacematchrequest/tst_qplacematchrequest.cpp b/tests/auto/qplacematchrequest/tst_qplacematchrequest.cpp new file mode 100644 index 00000000..11fb6794 --- /dev/null +++ b/tests/auto/qplacematchrequest/tst_qplacematchrequest.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include <qplacematchrequest.h> + + +QT_USE_NAMESPACE + +class tst_QPlaceMatchRequest : public QObject +{ + Q_OBJECT + +public: + tst_QPlaceMatchRequest(); + +private Q_SLOTS: + void constructorTest(); + void placesTest(); + void resultsTest(); + void parametersTest(); + void clearTest(); +}; + +tst_QPlaceMatchRequest::tst_QPlaceMatchRequest() +{ +} + +void tst_QPlaceMatchRequest::constructorTest() +{ + QPlaceMatchRequest request; + QVariantMap params; + params.insert(QLatin1String("key"), QLatin1String("val")); + + QPlace place1; + place1.setName(QLatin1String("place1")); + + QPlace place2; + place2.setName(QLatin1String("place2")); + + QList<QPlace> places; + places << place1 << place2; + + request.setPlaces(places); + request.setParameters(params); + + QPlaceMatchRequest copy(request); + QCOMPARE(copy, request); + QCOMPARE(copy.places(), places); + QCOMPARE(copy.parameters(), params); +} + +void tst_QPlaceMatchRequest::placesTest() +{ + QPlaceMatchRequest request; + QCOMPARE(request.places().count(), 0); + + QPlace place1; + place1.setName(QLatin1String("place1")); + + QPlace place2; + place2.setName(QLatin1String("place2")); + + QList<QPlace> places; + places << place1 << place2; + + request.setPlaces(places); + QCOMPARE(request.places(), places); + + request.setPlaces(QList<QPlace>()); + QCOMPARE(request.places().count(), 0); +} + +void tst_QPlaceMatchRequest::resultsTest() +{ + QPlaceMatchRequest request; + QCOMPARE(request.places().count(), 0); + + QPlace place1; + place1.setName(QLatin1String("place1")); + QPlaceSearchResult result1; + result1.setPlace(place1); + + QPlace place2; + place2.setName(QLatin1String("place2")); + QPlaceSearchResult result2; + result2.setPlace(place2); + + QList<QPlaceSearchResult> results; + results << result1 << result2; + + request.setResults(results); + + QCOMPARE(request.places().count(), 2); + QCOMPARE(request.places().at(0), place1); + QCOMPARE(request.places().at(1), place2); + + request.setResults(QList<QPlaceSearchResult>()); + QCOMPARE(request.places().count(), 0); +} + +void tst_QPlaceMatchRequest::parametersTest() +{ + QPlaceMatchRequest request; + QVERIFY(request.parameters().isEmpty()); + + QVariantMap params; + params.insert(QLatin1String("key"), QLatin1String("value")); + + request.setParameters(params); + QCOMPARE(request.parameters(), params); +} + +void tst_QPlaceMatchRequest::clearTest() +{ + QPlaceMatchRequest request; + QVariantMap params; + params.insert(QLatin1String("key"), QLatin1String("value")); + + QPlace place1; + place1.setName(QLatin1String("place1")); + + QPlace place2; + place2.setName(QLatin1String("place2")); + + QList<QPlace> places; + places << place1 << place2; + + request.setPlaces(places); + request.setParameters(params); + + request.clear(); + QVERIFY(request.places().isEmpty()); + QVERIFY(request.parameters().isEmpty()); +} + +QTEST_APPLESS_MAIN(tst_QPlaceMatchRequest) + +#include "tst_qplacematchrequest.moc" |