Added testmapengine.cpp and testmapfetcher.cpp.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 29 Mar 2010 09:13:40 +0000 (12:13 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 29 Mar 2010 09:13:40 +0000 (12:13 +0300)
tests/testMap/testmapengine.cpp [new file with mode: 0644]
tests/testMap/testmapfetcher.cpp [new file with mode: 0644]

diff --git a/tests/testMap/testmapengine.cpp b/tests/testMap/testmapengine.cpp
new file mode 100644 (file)
index 0000000..686f1ef
--- /dev/null
@@ -0,0 +1,57 @@
+#include <QtTest/QtTest>
+#include <QPointF>
+#include <QDebug>
+
+#include "../map/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"
diff --git a/tests/testMap/testmapfetcher.cpp b/tests/testMap/testmapfetcher.cpp
new file mode 100644 (file)
index 0000000..bd226df
--- /dev/null
@@ -0,0 +1,68 @@
+#include <QtTest/QtTest>
+#include <QUrl>
+#include <QImage>
+
+#include "../map/mapfetcher.h"
+
+class TestMapFetcher : public QObject
+{
+    Q_OBJECT
+public:
+    TestMapFetcher();
+
+private slots:
+    void testFetchImage();
+    void testSignals();
+
+
+private:
+    MapFetcher *mapFetcher;
+};
+
+TestMapFetcher::TestMapFetcher()
+{
+    mapFetcher = new MapFetcher();
+}
+
+void TestMapFetcher::testFetchImage()
+{
+    QUrl url("");
+    mapFetcher->fetchMapImage(url);
+}
+
+
+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.takeFirst();
+    QCOMPARE(url2, signalArgs2.at(0).toUrl());
+
+    //10 requests
+    qDebug() << "Start:" << QTime::currentTime().toString("hh:mm:ss:zzz");
+    for (int i = 0; i < 10; ++i) {
+        QUrl url(QString("http://tile.openstreetmap.org/7/63/4%1.png").arg(i));
+        mapFetcher->fetchMapImage(url);
+    }
+    QTest::qWait(2000);
+
+}
+
+QTEST_MAIN(TestMapFetcher)
+#include "testmapfetcher.moc"