summaryrefslogtreecommitdiff
path: root/tests/auto/qplacemanager
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2011-12-23 13:12:53 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-13 05:25:46 +0100
commita9c5420c21f25442d272fd07f8127b01d2bfd73c (patch)
tree80fd74aca8d63756e0656ff4fb658d22ae733c03 /tests/auto/qplacemanager
parent94e991e335706374003ce0a1596a0ec9ca7f47e7 (diff)
downloadqtlocation-a9c5420c21f25442d272fd07f8127b01d2bfd73c.tar.gz
Implement cross-referencing of Places
Cross referenceing means we can detect whether a place from one plugin/manager is already in another plugin/manager Change-Id: Ice1834446a61e30e02f869e1d383f6d8698b8db6 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/auto/qplacemanager')
-rw-r--r--tests/auto/qplacemanager/tst_qplacemanager.cpp109
1 files changed, 109 insertions, 0 deletions
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"