INCLUDEPATH += . \
src/tests/testmap/ \
src/map/
-SOURCES += src/main.cpp \
-src/map/mapfetcher.cpp \
+SOURCES += src/map/mapfetcher.cpp \
src/map/mapengine.cpp \
-# tests/testmap/testmapfetcher.cpp \
+ tests/testmap/testmapfetcher.cpp \
# tests/testmap/testmapengine.cpp \
src/ui/mainwindow.cpp \
tests/testmap/networkaccessmanagermock.cpp \
m_manager->setCache(diskCache);
- connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*))); //Change to QNetworkReply
+ connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
}
void MapFetcher::fetchMapImage(const QUrl &url)
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#include <QNetworkAccessManager>
-
-class NetworkAccessManagerMock : public QNetworkAccessManager
-{
- Q_OBJECT
-
-public:
- NetworkAccessManagerMock();
-
- void get(const QNetworkRequest &request);
-};
-
-NetworkAccessManagerMock::NetworkAccessManagerMock()
- : QNetworkAccessManager()
-{
-
-}
-
-void NetworkAccessManagerMock::get(const QNetworkRequest &request)
-{
- QNetworkReply *reply = new QNetworkReply();
-}
-
-
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#include <QNetworkReply>
-
-class NetworkReplyMock : public QNetworkReply
-{
- Q_OBJECT
-
-public:
- NetworkReplyMock();
-};
-
-NetworkReplyMock::NetworkReplyMock()
- : QNetworkReply()
-{
-
-}
+++ /dev/null
-#include <QtTest/QtTest>
-#include <QPointF>
-#include <QDebug>
-
-#include "mapengine.h"
-
-/**
-* @brief Test class for MapEngine.
-*
-* @class TestMapEngine testmapengine.cpp "tests/testmapengine.cpp"
-*/
-class TestMapEngine : public QObject
-{
- Q_OBJECT
-public:
- TestMapEngine();
-
-private slots:
- void coordinatesToTiles();
- void longitudeFromTiles();
- void latitudeFromTiles();
-
-private:
- MapEngine *mapEngine;
-};
-
-TestMapEngine::TestMapEngine()
-{
- mapEngine = new MapEngine();
-}
-
-
-void TestMapEngine::coordinatesToTiles()
-{
- //QPoint point1 = mapEngine->coordinateToTile(47.629, 7.262, 1);
- QPoint point1 = MapEngine::latLonToTile(47.629, 7.262, 1);
- QCOMPARE(point1, QPoint(1, 0));
- /*QPoint point2 = mapEngine->coordinateToTile(65.013379, 25.472059, 13);
- QCOMPARE(point2, QPoint(4675, 2131));
- QPoint point3 = mapEngine->coordinateToTile(65.013379, 25.472059, 10);
- QCOMPARE(point3, QPoint(584, 266));*/
-}
-
-void TestMapEngine::longitudeFromTiles()
-{
- qreal longitude = mapEngine->tileXToLongitude(4675, 13);
- QCOMPARE(longitude, 25.47059);
-}
-
-void TestMapEngine::latitudeFromTiles()
-{
-
-}
-
-QTEST_MAIN(TestMapEngine)
-#include "testmapengine.moc"
+++ /dev/null
-#include <QtTest/QtTest>
-#include <QUrl>
-#include <QImage>
-#include <QNetworkAccessManager>
-
-#include "mapfetcher.h"
-
-class TestMapFetcher : public QObject
-{
- Q_OBJECT
-public:
- TestMapFetcher();
-
-
-private slots:
- void testFetchImage();
- //void testDownloadFinished();
- void testSignals();
-
-
-private:
- MapFetcher *mapFetcher;
-};
-
-TestMapFetcher::TestMapFetcher()
-{
- mapFetcher = new MapFetcher();
-}
-
-void TestMapFetcher::testFetchImage()
-{
- QUrl url("");
- mapFetcher->fetchMapImage(url);
-}
-
-/*void TestMapFetcher::testDownloadFinished()
-{
- NetworkReplyDummy *reply = new NetworkReplyDummy();
- reply->setError(QNetworkReply::ConnectionRefusedError, QString("Connection refused"));
-
- QSignalSpy errorSpy(mapFetcher, SIGNAL(error(QString)));
- mapFetcher->downloadFinished(reply);
- QTest::qWait(500);
-
- QCOMPARE(errorSpy.count(), 1);
-
- QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
- //QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
-}*/
-
-void TestMapFetcher::testSignals()
-{
- QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
- QSignalSpy imageReceivedErrorSpy(mapFetcher, SIGNAL(error(QString)));
-
- QVERIFY(imageReceivedSpy.isValid());
-
- //Incorrect URL
- QUrl url1("http://tile.openstreetmap.org/7/63/22.gi");
- mapFetcher->fetchMapImage(url1);
- QTest::qWait(1000);
- QCOMPARE(imageReceivedErrorSpy.count(), 1);
- QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
- qDebug() << signalArgs1.at(0).toString();
-
- /*//Correct URL
- QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
- mapFetcher->fetchMapImage(url2);
- QTest::qWait(1000);
- QCOMPARE(imageReceivedSpy.count(), 1);
- QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
- QCOMPARE(url2, signalArgs2.at(0).toUrl());
-
- //20 requests immediately
- for (int i = 1; i < 3; ++i) {
- for (int j = 0; j < 10; ++j) {
- QUrl url(QString("http://tile.openstreetmap.org/7/53/%1%2.png").arg(i).arg(j));
- mapFetcher->fetchMapImage(url);
- }
- }
- QTest::qWait(400);
-
- //50 requests immediately
- for (int i = 1; i < 6; ++i) {
- for (int j = 0; j < 10; ++j) {
- QUrl url(QString("http://tile.openstreetmap.org/7/63/%1%2.png").arg(i).arg(j));
- mapFetcher->fetchMapImage(url);
- }
- }
-
- QTest::qWait(2000);*/
-
-}
-
-QTEST_MAIN(TestMapFetcher)
-#include "testmapfetcher.moc"
void TestMapFetcher::testFetchImageCorrectURL()
{
-// QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
-//
-// QVERIFY(imageReceivedSpy.isValid());
-//
-// //Correct URL
-// QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
-// mapFetcher->fetchMapImage(url2);
-// QTest::qWait(2000);
-// QCOMPARE(imageReceivedSpy.count(), 1);
-// QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
-// QCOMPARE(url2, signalArgs2.at(0).toUrl());
+ QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
+
+ QVERIFY(imageReceivedSpy.isValid());
+
+ //Correct URL
+ QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
+ mapFetcher->fetchMapImage(url2);
+ QTest::qWait(2000);
+ QCOMPARE(imageReceivedSpy.count(), 1);
+ QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
+ QCOMPARE(url2, signalArgs2.at(0).toUrl());
}
void TestMapFetcher::testFetchCorruptedImage()