--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@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 <QtTest/QtTest>
+
+#include "map/mapengine.h"
+
+class TestMapEngine: public QObject
+{
+ Q_OBJECT
+private slots:
+ void convertTileNumberToSceneCoordinate();
+// void setViewLocation();
+ void convertLatLonToSceneCoordinate_data();
+ void convertLatLonToSceneCoordinate();
+ void calculateRect();
+ void setLocation();
+// void removeTilesOutOfBounds();
+ void calculateTileGrid();
+ void convert();
+};
+
+/**
+* @brief Test converting tile numbers to scene coordinates
+*
+* Different zoom levels are also tested
+*/
+void TestMapEngine::convertTileNumberToSceneCoordinate()
+{
+ QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(0,0)), QPoint(0,0));
+ QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(1,2)), QPoint(256,512));
+ QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
+}
+
+/**
+* @brief DUMMY TESTCASE!
+*
+* @todo Actual test should be added when there is something to be tested
+*/
+//void TestMapEngine::setViewLocation()
+//{
+// MapEngine mapEngine;
+// mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
+//}
+
+/**
+ * @brief Test data for converting latitude and longitude coordinates to scene coordinates
+ */
+void TestMapEngine::convertLatLonToSceneCoordinate_data()
+{
+ QTest::addColumn<QPointF>("coordinate");
+ QTest::addColumn<QPointF>("result");
+
+ QTest::newRow("top left") << QPointF(-180, 85.0511) << QPointF(0, 0);
+ QTest::newRow("bottom right") << QPointF(180, -85.0511) << QPointF(67108863, 67108863);
+}
+
+/**
+* @brief Test converting real world cordinates to scene coordinates
+* @todo Implement
+*/
+void TestMapEngine::convertLatLonToSceneCoordinate()
+{
+ QFETCH(QPointF, coordinate);
+ QFETCH(QPointF, result);
+
+ QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
+}
+
+void TestMapEngine::calculateRect()
+{
+ MapEngine engine;
+ engine.viewResized(QSize(800, 480));
+ engine.setZoomLevel(14);
+
+ int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+
+ QRect grid1 = QRect(-1, 0, 6, 4);
+ QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
+
+ QRect grid2 = QRect(-3, -2, 6, 4);
+ QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
+
+ QRect grid3 = QRect(1017, 498, 6, 4);
+ QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
+
+ engine.viewResized(QSize(1280, 1024));
+
+ QRect grid4 = QRect(1016, 497, 8, 7);
+ QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
+}
+
+void TestMapEngine::setLocation()
+{
+ MapEngine engine;
+ engine.setZoomLevel(14);
+ engine.viewResized(QSize(800, 480));
+
+ int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+
+ QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
+ QTest::qWait(1000);
+ fetchImageSpy.clear();
+
+ engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
+ QTest::qWait(1000);
+ QCOMPARE(fetchImageSpy.count(), 6*4);
+ fetchImageSpy.clear();
+
+ //Move one tile right and one down = 9 new tiles
+ engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
+ QTest::qWait(1000);
+ QCOMPARE(fetchImageSpy.count(), 9);
+ fetchImageSpy.clear();
+}
+
+void TestMapEngine::convert()
+{
+ int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - 14);
+
+ QPoint tileNumber = QPoint(1020, 500);
+ QPointF sceneCoordinate = QPointF(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
+ QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
+
+ QCOMPARE(tileNumber, tile);
+}
+
+void TestMapEngine::calculateTileGrid()
+{
+ MapEngine engine;
+
+ engine.viewResized(QSize(800, 480));
+ engine.setZoomLevel(14);
+
+ int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+
+ engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
+}
+
+//void TestMapEngine::removeTilesOutOfBounds()
+//{
+// MapEngine engine;
+// engine.viewResized(QSize(800, 480));
+// engine.setZoomLevel(14);
+//
+// int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
+//
+// engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
+// qDebug() << "Scene items: " << engine.scene()->items().count();
+// QTest::qWait(1000);
+// //Move one tile right and one tile down
+// engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
+// QCOMPARE(engine.scene()->items().count(), 15);
+//}
+
+QTEST_MAIN(TestMapEngine)
+#include "testmapengine.moc"
--- /dev/null
+# #####################################################################
+# Automatically generated by qmake (2.01a) Fri Mar 26 15:09:16 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += . \
+ ../../../src/
+#DEFINES += QT_NO_DEBUG_OUTPUT
+
+# Input
+SOURCES += testmapengine.cpp \
+ ../../../src/map/mapengine.cpp \
+ ../../../src/map/mapscene.cpp \
+ ../../../src/map/maptile.cpp \
+ ../../../src/map/mapview.cpp \
+ ../../../src/map/mapfetcher.cpp
+HEADERS += ../../../src/map/mapengine.h \
+ ../../../src/map/mapscene.h \
+ ../../../src/map/maptile.h \
+ ../../../src/map/mapview.h \
+ ../../../src/map/mapfetcher.h \
+ ../../../src/common.h
+RESOURCES +=
+
+# use don't use OpenGL when building in scratchbox
+!maemo5 {
+ QT += opengl
+ message(OpenGL built in)
+ message(Make sure you have OpenGL development headers installed)
+ message(install headers with: sudo apt-get install libgl-dev libglu-dev)
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@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 <QtTest/QtTest>
+#include <QDebug>
+
+#include "map/mapscene.h"
+#include "map/maptile.h"
+#include "map/mapengine.h"
+
+class TestMapScene : public QObject
+{
+ Q_OBJECT
+private slots:
+ void addMapTile();
+};
+
+/**
+* @brief Test adding map tiles
+*
+* Does check that the map tile is found in right coordinates
+*/
+void TestMapScene::addMapTile()
+{
+ MapScene mapScene;
+
+ // First test:
+ // Zoom level is 18, so no stretching should occure
+ // Top-left corner x = 256, y = 512
+ // Bottom-right corner x + 255, y + 255
+ MapTile *mapTile = new MapTile();
+ mapTile->setZoomLevel(18);
+ mapTile->setTileNumber(QPoint(1, 2));
+ mapTile->setPixmap(QPixmap("maptile.png"));
+
+ mapScene.addMapTile(mapTile);
+
+ // Check around top-left and bottom-right corners
+ int x = 256;
+ int y = 512;
+ int s = 255; //side length -1
+ QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
+
+ // Second test:
+ // Zoom level is 16, so stretching is also tested
+ // Top-left corner x = 2048, y = 3072
+ // Bottom-right corner x + 1023, y + 1023
+ mapTile->setZoomLevel(16);
+ mapTile->setTileNumber(QPoint(2, 3));
+
+ // Check around top-left and bottom-right corners
+ x = 2048;
+ y = 3072;
+ s = 1023; //side length -1
+ QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
+}
+
+QTEST_MAIN(TestMapScene)
+#include "testmapscene.moc"
--- /dev/null
+# #####################################################################
+# Automatically generated by qmake (2.01a) Mon Mar 29 10:06:28 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += . \
+ ../../../src/
+
+# Input
+SOURCES += testmapscene.cpp \
+ ../../../src/map/mapscene.cpp \
+ ../../../src/map/maptile.cpp
+HEADERS += ../../../src/map/mapscene.h \
+ ../../../src/map/maptile.h
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@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 <QtTest/QtTest>
+
+#include "map/maptile.h"
+
+class TestMapTile : public QObject
+{
+ Q_OBJECT
+private slots:
+ void zoomLevel();
+ void tileNumber();
+ void position_data();
+ void position();
+ void positionUnsetValues();
+ void sceneLevel_data();
+ void sceneLevel();
+};
+
+/**
+* @brief Test setting zoomlevel
+*/
+void TestMapTile::zoomLevel()
+{
+ MapTile mapTile;
+ mapTile.setZoomLevel(13);
+ QVERIFY(mapTile.zoomLevel() == 13);
+
+}
+
+/**
+* @brief Test setting tile numbers
+*/
+void TestMapTile::tileNumber()
+{
+ MapTile mapTile;
+ mapTile.setTileNumber(QPoint(24, 17));
+ QVERIFY(mapTile.tileNumber() == QPoint(24, 17));
+}
+
+/**
+* @brief Data for position test
+*/
+void TestMapTile::position_data()
+{
+ QTest::addColumn<int>("zoomLevel");
+ QTest::addColumn<QPoint>("tileNumber");
+ QTest::addColumn<QPointF>("result");
+
+ QTest::newRow("allowed values") << 16 << QPoint(24, 17) << QPointF(24576, 17408); //ok
+ QTest::newRow("x position negative") << 16 << QPoint(-1, 0) << QPointF(-1, -1); //fail
+ QTest::newRow("y position negative") << 16 << QPoint(0, -1) << QPointF(-1, -1); //fail
+
+ QTest::newRow("min zoom") << 0 << QPoint(0, 0) << QPointF(0, 0); //ok
+ QTest::newRow("min zoom - 1") << -1 << QPoint(0, 0) << QPointF(-1, -1); //fail
+ QTest::newRow("min zoom & x out of range (upper limit)") << 0 << QPoint(1, 0) << QPointF(-1, -1); //fail
+ QTest::newRow("min zoom & y out of range (upper limit)") << 0 << QPoint(0, 1) << QPointF(-1, -1); //fail
+ QTest::newRow("min zoom, x & y out of range (upper limit)") << 0 << QPoint(1, 1) << QPointF(-1, -1); //fail
+
+ QTest::newRow("max zoom") << 18 << QPoint(2, 3) << QPointF(512, 768); //ok
+ QTest::newRow("max zoom + 1") << 19 << QPoint(2, 3) << QPointF(-1, -1); //fail
+ QTest::newRow("max zoom & x out of range (upper limit)") << 18 << QPoint(262144, 0) << QPointF(-1, -1); //fail
+ QTest::newRow("max zoom & y out of range (upper limit)") << 18 << QPoint(0, 262144) << QPointF(-1, -1); //fail
+ QTest::newRow("max zoom, x & y out of range(upper limit) ") << 18 << QPoint(262144, 262144) << QPointF(-1, -1); //fail
+}
+
+/**
+* @brief Test position correctness
+*/
+void TestMapTile::position()
+{
+ QFETCH(int, zoomLevel);
+ QFETCH(QPoint, tileNumber);
+ QFETCH(QPointF, result);
+
+ MapTile mapTile;
+ mapTile.setZoomLevel(zoomLevel);
+ mapTile.setTileNumber(tileNumber);
+ QCOMPARE(mapTile.pos(), result);
+}
+
+/**
+* @brief Test position correctness when some values are not set
+*/
+void TestMapTile::positionUnsetValues()
+{
+ MapTile mapTile;
+
+ // zoom level and tile numbers unset
+ QCOMPARE(mapTile.pos(), QPointF(-1, -1));
+
+ // only tile numbers set
+ mapTile.setTileNumber(QPoint(24, 17));
+ QCOMPARE(mapTile.pos(), QPointF(-1, -1));
+
+ // both set
+ mapTile.setZoomLevel(16);
+ QCOMPARE(mapTile.pos(), QPointF(24576, 17408));
+
+ // only zoom level set
+ MapTile anotherMapTile;
+ anotherMapTile.setZoomLevel(14);
+ QCOMPARE(anotherMapTile.pos(), QPointF(-1, -1));
+}
+
+/**
+ * @brief Data for test of setting zValues
+ */
+void TestMapTile::sceneLevel_data()
+{
+ QTest::addColumn<int>("tileZoomLevel");
+ QTest::addColumn<int>("viewZoomLevel");
+ QTest::addColumn<qreal>("result");
+
+ QTest::newRow("tile zoom 15, view zoom 17") << 15 << 17 << 15.0 + 19;
+ QTest::newRow("tile zoom 15, view zoom 16") << 15 << 16 << 15.0 + 19;
+ QTest::newRow("tile zoom 15, view zoom 15") << 15 << 15 << 15.0 + 19;
+ QTest::newRow("tile zoom 15, view zoom 14") << 15 << 14 << 13.5 + 19;
+ QTest::newRow("tile zoom 15, view zoom 13") << 15 << 13 << 11.5 + 19;
+ QTest::newRow("tile zoom 15, view zoom 12") << 15 << 12 << 9.5 + 19;
+ QTest::newRow("tile zoom 18, view zoom 1") << 18 << 1 << -15.5 + 19;
+ QTest::newRow("tile zoom 18, view zoom 0") << 18 << 0 << -17.5 + 19;
+}
+
+/**
+ * @brief Test setting zValues (drawing order)
+ */
+void TestMapTile::sceneLevel()
+{
+ QFETCH(int, tileZoomLevel);
+ QFETCH(int, viewZoomLevel);
+ QFETCH(qreal, result);
+
+ MapTile tile;
+ tile.setZoomLevel(tileZoomLevel);
+ tile.setSceneLevel(viewZoomLevel);
+ QCOMPARE(tile.zValue(), result);
+}
+
+QTEST_MAIN(TestMapTile)
+#include "testmaptile.moc"
--- /dev/null
+# #####################################################################
+# Automatically generated by qmake (2.01a) Mon Mar 29 10:06:28 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += . \
+ ../../../src/
+
+# Input
+SOURCES += testmaptile.cpp \
+ ../../../src/map/maptile.cpp
+HEADERS += ../../../src/map/maptile.h
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@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 <QtTest/QtTest>
+
+#include "map/mapview.h"
+
+class TestMapView: public QObject
+{
+ Q_OBJECT
+public:
+ TestMapView();
+
+private slots:
+ void init();
+ void cleanup();
+ void zoomLevelChange_data();
+ void zoomLevelChange();
+
+private:
+ MapView *m_mapView;
+};
+
+/**
+ * @brief Constructor for setting pointer to MapView to NULL
+ */
+TestMapView::TestMapView() : m_mapView(NULL)
+{
+
+}
+
+/**
+ * @brief Test case initialization
+ */
+void TestMapView::init()
+{
+ m_mapView = new MapView();
+ QVERIFY(m_mapView);
+}
+
+/**
+ * @brief Test case cleanup
+ */
+void TestMapView::cleanup()
+{
+ delete m_mapView;
+ m_mapView = 0;
+}
+
+/**
+ * @brief Test data for zoom level change test
+ */
+void TestMapView::zoomLevelChange_data()
+{
+ QTest::addColumn<int>("zoomLevel");
+ QTest::addColumn<qreal>("result");
+
+ QTest::newRow("zoom 18") << 18 << 1.0;
+ QTest::newRow("zoom 17") << 17 << 0.5;
+ QTest::newRow("zoom 16") << 16 << 0.25;
+ QTest::newRow("zoom 15") << 15 << 0.125;
+}
+
+/**
+ * @brief Test view zoom level scaling
+ */
+void TestMapView::zoomLevelChange()
+{
+ QFETCH(int, zoomLevel);
+ QFETCH(qreal, result);
+
+ m_mapView->setZoomLevel(zoomLevel);
+ QTest::qWait(300);
+ QCOMPARE(m_mapView->transform().m11(), result);
+ QCOMPARE(m_mapView->transform().m22(), result);
+}
+
+QTEST_MAIN(TestMapView)
+#include "testmapview.moc"
--- /dev/null
+# #####################################################################
+# Automatically generated by qmake (2.01a) Fri Mar 26 15:22:56 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += opengl
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += . \
+ ../../../src/
+
+# Input
+SOURCES += testmapview.cpp \
+ ../../../src/map/mapview.cpp
+HEADERS += ../../../src/map/mapview.h
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Sami Rämö - sami.ramo@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 <QtTest/QtTest>
-
-#include "map/mapengine.h"
-
-class TestMapEngine: public QObject
-{
- Q_OBJECT
-private slots:
- void convertTileNumberToSceneCoordinate();
-// void setViewLocation();
- void convertLatLonToSceneCoordinate_data();
- void convertLatLonToSceneCoordinate();
- void calculateRect();
- void setLocation();
-// void removeTilesOutOfBounds();
- void calculateTileGrid();
- void convert();
-};
-
-/**
-* @brief Test converting tile numbers to scene coordinates
-*
-* Different zoom levels are also tested
-*/
-void TestMapEngine::convertTileNumberToSceneCoordinate()
-{
- QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(0,0)), QPoint(0,0));
- QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(1,2)), QPoint(256,512));
- QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
-}
-
-/**
-* @brief DUMMY TESTCASE!
-*
-* @todo Actual test should be added when there is something to be tested
-*/
-//void TestMapEngine::setViewLocation()
-//{
-// MapEngine mapEngine;
-// mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
-//}
-
-/**
- * @brief Test data for converting latitude and longitude coordinates to scene coordinates
- */
-void TestMapEngine::convertLatLonToSceneCoordinate_data()
-{
- QTest::addColumn<QPointF>("coordinate");
- QTest::addColumn<QPointF>("result");
-
- QTest::newRow("top left") << QPointF(-180, 85.0511) << QPointF(0, 0);
- QTest::newRow("bottom right") << QPointF(180, -85.0511) << QPointF(67108863, 67108863);
-}
-
-/**
-* @brief Test converting real world cordinates to scene coordinates
-* @todo Implement
-*/
-void TestMapEngine::convertLatLonToSceneCoordinate()
-{
- QFETCH(QPointF, coordinate);
- QFETCH(QPointF, result);
-
- QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
-}
-
-void TestMapEngine::calculateRect()
-{
- MapEngine engine;
- engine.viewResized(QSize(800, 480));
- engine.setZoomLevel(14);
-
- int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
- QRect grid1 = QRect(-1, 0, 6, 4);
- QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
-
- QRect grid2 = QRect(-3, -2, 6, 4);
- QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
-
- QRect grid3 = QRect(1017, 498, 6, 4);
- QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
-
- engine.viewResized(QSize(1280, 1024));
-
- QRect grid4 = QRect(1016, 497, 8, 7);
- QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
-}
-
-void TestMapEngine::setLocation()
-{
- MapEngine engine;
- engine.setZoomLevel(14);
- engine.viewResized(QSize(800, 480));
-
- int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
- QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
- QTest::qWait(1000);
- fetchImageSpy.clear();
-
- engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
- QTest::qWait(1000);
- QCOMPARE(fetchImageSpy.count(), 6*4);
- fetchImageSpy.clear();
-
- //Move one tile right and one down = 9 new tiles
- engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
- QTest::qWait(1000);
- QCOMPARE(fetchImageSpy.count(), 9);
- fetchImageSpy.clear();
-}
-
-void TestMapEngine::convert()
-{
- int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - 14);
-
- QPoint tileNumber = QPoint(1020, 500);
- QPointF sceneCoordinate = QPointF(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
- QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
-
- QCOMPARE(tileNumber, tile);
-}
-
-void TestMapEngine::calculateTileGrid()
-{
- MapEngine engine;
-
- engine.viewResized(QSize(800, 480));
- engine.setZoomLevel(14);
-
- int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
- engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
-}
-
-//void TestMapEngine::removeTilesOutOfBounds()
-//{
-// MapEngine engine;
-// engine.viewResized(QSize(800, 480));
-// engine.setZoomLevel(14);
-//
-// int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
-//
-// engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
-// qDebug() << "Scene items: " << engine.scene()->items().count();
-// QTest::qWait(1000);
-// //Move one tile right and one tile down
-// engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
-// QCOMPARE(engine.scene()->items().count(), 15);
-//}
-
-QTEST_MAIN(TestMapEngine)
-#include "testmapengine.moc"
+++ /dev/null
-# #####################################################################
-# Automatically generated by qmake (2.01a) Fri Mar 26 15:09:16 2010
-# #####################################################################
-CONFIG += qtestlib
-QT += network
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += . \
- ../../../src/
-#DEFINES += QT_NO_DEBUG_OUTPUT
-
-# Input
-SOURCES += testmapengine.cpp \
- ../../../src/map/mapengine.cpp \
- ../../../src/map/mapscene.cpp \
- ../../../src/map/maptile.cpp \
- ../../../src/map/mapview.cpp \
- ../../../src/map/mapfetcher.cpp
-HEADERS += ../../../src/map/mapengine.h \
- ../../../src/map/mapscene.h \
- ../../../src/map/maptile.h \
- ../../../src/map/mapview.h \
- ../../../src/map/mapfetcher.h \
- ../../../src/common.h
-RESOURCES +=
-
-# use don't use OpenGL when building in scratchbox
-!maemo5 {
- QT += opengl
- message(OpenGL built in)
- message(Make sure you have OpenGL development headers installed)
- message(install headers with: sudo apt-get install libgl-dev libglu-dev)
-}
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Sami Rämö - sami.ramo@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 <QtTest/QtTest>
-#include <QDebug>
-
-#include "map/mapscene.h"
-#include "map/maptile.h"
-#include "map/mapengine.h"
-
-class TestMapScene : public QObject
-{
- Q_OBJECT
-private slots:
- void addMapTile();
-};
-
-/**
-* @brief Test adding map tiles
-*
-* Does check that the map tile is found in right coordinates
-*/
-void TestMapScene::addMapTile()
-{
- MapScene mapScene;
-
- // First test:
- // Zoom level is 18, so no stretching should occure
- // Top-left corner x = 256, y = 512
- // Bottom-right corner x + 255, y + 255
- MapTile *mapTile = new MapTile();
- mapTile->setZoomLevel(18);
- mapTile->setTileNumber(QPoint(1, 2));
- mapTile->setPixmap(QPixmap("maptile.png"));
-
- mapScene.addMapTile(mapTile);
-
- // Check around top-left and bottom-right corners
- int x = 256;
- int y = 512;
- int s = 255; //side length -1
- QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
- QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
- QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
-
- // Second test:
- // Zoom level is 16, so stretching is also tested
- // Top-left corner x = 2048, y = 3072
- // Bottom-right corner x + 1023, y + 1023
- mapTile->setZoomLevel(16);
- mapTile->setTileNumber(QPoint(2, 3));
-
- // Check around top-left and bottom-right corners
- x = 2048;
- y = 3072;
- s = 1023; //side length -1
- QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
- QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
- QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
- QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
-}
-
-QTEST_MAIN(TestMapScene)
-#include "testmapscene.moc"
+++ /dev/null
-# #####################################################################
-# Automatically generated by qmake (2.01a) Mon Mar 29 10:06:28 2010
-# #####################################################################
-CONFIG += qtestlib
-QT += network
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += . \
- ../../../src/
-
-# Input
-SOURCES += testmapscene.cpp \
- ../../../src/map/mapscene.cpp \
- ../../../src/map/maptile.cpp
-HEADERS += ../../../src/map/mapscene.h \
- ../../../src/map/maptile.h
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Sami Rämö - sami.ramo@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 <QtTest/QtTest>
-
-#include "map/maptile.h"
-
-class TestMapTile : public QObject
-{
- Q_OBJECT
-private slots:
- void zoomLevel();
- void tileNumber();
- void position_data();
- void position();
- void positionUnsetValues();
- void sceneLevel_data();
- void sceneLevel();
-};
-
-/**
-* @brief Test setting zoomlevel
-*/
-void TestMapTile::zoomLevel()
-{
- MapTile mapTile;
- mapTile.setZoomLevel(13);
- QVERIFY(mapTile.zoomLevel() == 13);
-
-}
-
-/**
-* @brief Test setting tile numbers
-*/
-void TestMapTile::tileNumber()
-{
- MapTile mapTile;
- mapTile.setTileNumber(QPoint(24, 17));
- QVERIFY(mapTile.tileNumber() == QPoint(24, 17));
-}
-
-/**
-* @brief Data for position test
-*/
-void TestMapTile::position_data()
-{
- QTest::addColumn<int>("zoomLevel");
- QTest::addColumn<QPoint>("tileNumber");
- QTest::addColumn<QPointF>("result");
-
- QTest::newRow("allowed values") << 16 << QPoint(24, 17) << QPointF(24576, 17408); //ok
- QTest::newRow("x position negative") << 16 << QPoint(-1, 0) << QPointF(-1, -1); //fail
- QTest::newRow("y position negative") << 16 << QPoint(0, -1) << QPointF(-1, -1); //fail
-
- QTest::newRow("min zoom") << 0 << QPoint(0, 0) << QPointF(0, 0); //ok
- QTest::newRow("min zoom - 1") << -1 << QPoint(0, 0) << QPointF(-1, -1); //fail
- QTest::newRow("min zoom & x out of range (upper limit)") << 0 << QPoint(1, 0) << QPointF(-1, -1); //fail
- QTest::newRow("min zoom & y out of range (upper limit)") << 0 << QPoint(0, 1) << QPointF(-1, -1); //fail
- QTest::newRow("min zoom, x & y out of range (upper limit)") << 0 << QPoint(1, 1) << QPointF(-1, -1); //fail
-
- QTest::newRow("max zoom") << 18 << QPoint(2, 3) << QPointF(512, 768); //ok
- QTest::newRow("max zoom + 1") << 19 << QPoint(2, 3) << QPointF(-1, -1); //fail
- QTest::newRow("max zoom & x out of range (upper limit)") << 18 << QPoint(262144, 0) << QPointF(-1, -1); //fail
- QTest::newRow("max zoom & y out of range (upper limit)") << 18 << QPoint(0, 262144) << QPointF(-1, -1); //fail
- QTest::newRow("max zoom, x & y out of range(upper limit) ") << 18 << QPoint(262144, 262144) << QPointF(-1, -1); //fail
-}
-
-/**
-* @brief Test position correctness
-*/
-void TestMapTile::position()
-{
- QFETCH(int, zoomLevel);
- QFETCH(QPoint, tileNumber);
- QFETCH(QPointF, result);
-
- MapTile mapTile;
- mapTile.setZoomLevel(zoomLevel);
- mapTile.setTileNumber(tileNumber);
- QCOMPARE(mapTile.pos(), result);
-}
-
-/**
-* @brief Test position correctness when some values are not set
-*/
-void TestMapTile::positionUnsetValues()
-{
- MapTile mapTile;
-
- // zoom level and tile numbers unset
- QCOMPARE(mapTile.pos(), QPointF(-1, -1));
-
- // only tile numbers set
- mapTile.setTileNumber(QPoint(24, 17));
- QCOMPARE(mapTile.pos(), QPointF(-1, -1));
-
- // both set
- mapTile.setZoomLevel(16);
- QCOMPARE(mapTile.pos(), QPointF(24576, 17408));
-
- // only zoom level set
- MapTile anotherMapTile;
- anotherMapTile.setZoomLevel(14);
- QCOMPARE(anotherMapTile.pos(), QPointF(-1, -1));
-}
-
-/**
- * @brief Data for test of setting zValues
- */
-void TestMapTile::sceneLevel_data()
-{
- QTest::addColumn<int>("tileZoomLevel");
- QTest::addColumn<int>("viewZoomLevel");
- QTest::addColumn<qreal>("result");
-
- QTest::newRow("tile zoom 15, view zoom 17") << 15 << 17 << 15.0 + 19;
- QTest::newRow("tile zoom 15, view zoom 16") << 15 << 16 << 15.0 + 19;
- QTest::newRow("tile zoom 15, view zoom 15") << 15 << 15 << 15.0 + 19;
- QTest::newRow("tile zoom 15, view zoom 14") << 15 << 14 << 13.5 + 19;
- QTest::newRow("tile zoom 15, view zoom 13") << 15 << 13 << 11.5 + 19;
- QTest::newRow("tile zoom 15, view zoom 12") << 15 << 12 << 9.5 + 19;
- QTest::newRow("tile zoom 18, view zoom 1") << 18 << 1 << -15.5 + 19;
- QTest::newRow("tile zoom 18, view zoom 0") << 18 << 0 << -17.5 + 19;
-}
-
-/**
- * @brief Test setting zValues (drawing order)
- */
-void TestMapTile::sceneLevel()
-{
- QFETCH(int, tileZoomLevel);
- QFETCH(int, viewZoomLevel);
- QFETCH(qreal, result);
-
- MapTile tile;
- tile.setZoomLevel(tileZoomLevel);
- tile.setSceneLevel(viewZoomLevel);
- QCOMPARE(tile.zValue(), result);
-}
-
-QTEST_MAIN(TestMapTile)
-#include "testmaptile.moc"
+++ /dev/null
-# #####################################################################
-# Automatically generated by qmake (2.01a) Mon Mar 29 10:06:28 2010
-# #####################################################################
-CONFIG += qtestlib
-QT += network
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += . \
- ../../../src/
-
-# Input
-SOURCES += testmaptile.cpp \
- ../../../src/map/maptile.cpp
-HEADERS += ../../../src/map/maptile.h
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Sami Rämö - sami.ramo@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 <QtTest/QtTest>
-
-#include "map/mapview.h"
-
-class TestMapView: public QObject
-{
- Q_OBJECT
-public:
- TestMapView();
-
-private slots:
- void init();
- void cleanup();
- void zoomLevelChange_data();
- void zoomLevelChange();
-
-private:
- MapView *m_mapView;
-};
-
-/**
- * @brief Constructor for setting pointer to MapView to NULL
- */
-TestMapView::TestMapView() : m_mapView(NULL)
-{
-
-}
-
-/**
- * @brief Test case initialization
- */
-void TestMapView::init()
-{
- m_mapView = new MapView();
- QVERIFY(m_mapView);
-}
-
-/**
- * @brief Test case cleanup
- */
-void TestMapView::cleanup()
-{
- delete m_mapView;
- m_mapView = 0;
-}
-
-/**
- * @brief Test data for zoom level change test
- */
-void TestMapView::zoomLevelChange_data()
-{
- QTest::addColumn<int>("zoomLevel");
- QTest::addColumn<qreal>("result");
-
- QTest::newRow("zoom 18") << 18 << 1.0;
- QTest::newRow("zoom 17") << 17 << 0.5;
- QTest::newRow("zoom 16") << 16 << 0.25;
- QTest::newRow("zoom 15") << 15 << 0.125;
-}
-
-/**
- * @brief Test view zoom level scaling
- */
-void TestMapView::zoomLevelChange()
-{
- QFETCH(int, zoomLevel);
- QFETCH(qreal, result);
-
- m_mapView->setZoomLevel(zoomLevel);
- QTest::qWait(300);
- QCOMPARE(m_mapView->transform().m11(), result);
- QCOMPARE(m_mapView->transform().m22(), result);
-}
-
-QTEST_MAIN(TestMapView)
-#include "testmapview.moc"
+++ /dev/null
-# #####################################################################
-# Automatically generated by qmake (2.01a) Fri Mar 26 15:22:56 2010
-# #####################################################################
-CONFIG += qtestlib
-QT += opengl
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += . \
- ../../../src/
-
-# Input
-SOURCES += testmapview.cpp \
- ../../../src/map/mapview.cpp
-HEADERS += ../../../src/map/mapview.h