Implemented unit tests for MapRouteItem
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 27 Jul 2010 10:50:43 +0000 (13:50 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 27 Jul 2010 10:50:43 +0000 (13:50 +0300)
 - Reviewed by Jussi Laitinen

tests/map/maprouteitem/maprouteitem.pro [new file with mode: 0644]
tests/map/maprouteitem/testmaprouteitem.cpp [new file with mode: 0644]
tests/tests.pro

diff --git a/tests/map/maprouteitem/maprouteitem.pro b/tests/map/maprouteitem/maprouteitem.pro
new file mode 100644 (file)
index 0000000..2719839
--- /dev/null
@@ -0,0 +1,32 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-07-13T15:37:49
+#
+#-------------------------------------------------
+
+QT       += testlib \
+            gui
+
+CONFIG   += console
+CONFIG   -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += testmaprouteitem.cpp \
+    ../../../src/map/maprouteitem.cpp \
+    ../../../src/routing/route.cpp \
+    ../../../src/coordinates/scenecoordinate.cpp \
+    ../../../src/coordinates/geocoordinate.cpp
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+DEFINES += QT_NO_DEBUG_OUTPUT
+
+INCLUDEPATH += . \
+    ../../../src/
+
+HEADERS += \
+    ../../../src/map/maprouteitem.h \
+    ../../../src/routing/route.h \
+    ../../../src/coordinates/scenecoordinate.h \
+    ../../../src/coordinates/geocoordinate.h
diff --git a/tests/map/maprouteitem/testmaprouteitem.cpp b/tests/map/maprouteitem/testmaprouteitem.cpp
new file mode 100644 (file)
index 0000000..1662401
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+    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 <QtCore/QString>
+#include <QPen>
+#include <QtTest/QtTest>
+
+#include "coordinates/geocoordinate.h"
+#include "coordinates/scenecoordinate.h"
+#include "map/maprouteitem.h"
+#include "routing/route.h"
+
+class TestMapRouteItem : public QObject
+{
+    Q_OBJECT
+
+public:
+    TestMapRouteItem();
+
+private Q_SLOTS:
+    void testCase1();
+
+private:
+    Route route;
+
+    GeoCoordinate coordinates[3];
+};
+
+TestMapRouteItem::TestMapRouteItem()
+{
+    // test points
+    coordinates[0] = GeoCoordinate(12.3456, 54.3210);
+    coordinates[1] = GeoCoordinate(65.5000, 25.0000);
+    coordinates[2] = GeoCoordinate(-23.4567, 43.0987);
+
+    // append points to route
+    route.appendGeometryPoint(coordinates[0]);
+    route.appendGeometryPoint(coordinates[1]);
+    route.appendGeometryPoint(coordinates[2]);
+}
+
+void TestMapRouteItem::testCase1()
+{
+    MapRouteItem item;
+    item.setRoute(&route);
+
+    // check amount of lines
+    QList<QGraphicsItem *> lines = item.childItems();
+    QCOMPARE(lines.count(), 2);
+
+    // test each line
+    for (int i = 0; i < lines.count(); i++) {
+        // check if the item really is a line item
+        QGraphicsLineItem *lineItem = dynamic_cast<QGraphicsLineItem *>(lines.at(i));
+        QVERIFY(lineItem);
+
+        // check begin and end point scene coordinates of the line
+        QLineF line = lineItem->line();
+        QCOMPARE(line.p1(), SceneCoordinate(coordinates[i]).toPointF());
+        QCOMPARE(line.p2(), SceneCoordinate(coordinates[i + 1]).toPointF());
+
+        // check visual properties of the line
+        QPen pen = lineItem->pen();
+        QVERIFY(pen.isCosmetic());
+        QCOMPARE(pen.width(), 5);
+        QCOMPARE(pen.color(), QColor(Qt::red));
+    }
+}
+
+QTEST_APPLESS_MAIN(TestMapRouteItem);
+
+#include "testmaprouteitem.moc"
index ab8322b..579d120 100644 (file)
@@ -9,6 +9,7 @@ SUBDIRS = coordinates/geocoordinate \
           map/friendgroupitem \
           map/mapscene \
           map/friendlocationitem \
+          map/maprouteitem \
           ui/listview \
           ui/friendlistitem \
           ui/sidepanel \