+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@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 <QList>
+
+#include "map/ownlocationitem.h"
+#include "map/mapscene.h"
+#include "map/maptile.h"
+#include "map/mapengine.h"
+#include "map/mapcommon.h"
+#include "map/mapview.h"
+
+namespace TestOwnLocation // Test data for function is defined in namespace
+{
+ const qreal xCoordinate = 65.525;
+ const qreal yCoordinate = 25.345;
+ const QPointF testLocationPoint(65.525, 25.345);
+ const QPointF defaultLocationPoint(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
+ const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
+ const int itemIgnoresTransformationsFlagValue = 0x20;
+}
+
+using namespace TestOwnLocation;
+
+
+/**
+* @brief Class that test OwnLocationItem
+*
+* @author Ville Tiensuu
+*/
+class TestOwnLocationItem: public QObject
+ {
+ Q_OBJECT
+ private slots:
+
+ /**
+ * @brief Test method for constructors.
+ * Creates instance of OwnLocationItem using three different constructors and tests
+ * that positions are set correctly.
+ * Tests that Z-values are set correctly.
+ * Tests that offses are set correctly.
+ * Tests that ItemIgnoresTransformations flag is set.
+ */
+ void testConstructors();
+
+ /**
+ * @brief Creates instance of OwnLocationItem.
+ * Sets test position for location item in geographic coordinates.
+ * Reads position from location item in scene coordinates and
+ * verifies that it correctly formed.
+ */
+ void testSetAndGetPosition();
+
+ /**
+ * @brief Creates instance of OwnLocationItem.
+ * Verifies that instance is visible.
+ * Hides instance and verifies that it is not visible.
+ */
+ void testHideAndShowPosition();
+ };
+
+ void TestOwnLocationItem::testConstructors()
+ {
+ OwnLocationItem ownLocationItem1;
+ OwnLocationItem ownLocationItem2(xCoordinate, yCoordinate);
+ OwnLocationItem ownLocationItem3(testLocationPoint);
+
+ // Test Positions
+ QCOMPARE(ownLocationItem1.position(),
+ MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint));
+
+ QCOMPARE(ownLocationItem2.position(),
+ MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
+
+ QCOMPARE(ownLocationItem3.position(),
+ MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
+
+ // Test Z-values
+ QCOMPARE(static_cast<int>(ownLocationItem1.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
+ QCOMPARE(static_cast<int>(ownLocationItem2.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
+ QCOMPARE(static_cast<int>(ownLocationItem3.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
+
+ // Test Offsets
+ QCOMPARE(ownLocationItem1.offset(), locationIconOffset);
+ QCOMPARE(ownLocationItem2.offset(), locationIconOffset);
+ QCOMPARE(ownLocationItem3.offset(), locationIconOffset);
+
+ // Test ItemIgnoresTransformations Flags
+ QGraphicsItem::GraphicsItemFlags ownLocationItem1Flags = ownLocationItem1.flags();
+ QGraphicsItem::GraphicsItemFlags ownLocationItem2Flags = ownLocationItem1.flags();
+ QGraphicsItem::GraphicsItemFlags ownLocationItem3Flags = ownLocationItem1.flags();
+
+ QCOMPARE(ownLocationItem1Flags, itemIgnoresTransformationsFlagValue);
+ QCOMPARE(ownLocationItem2Flags, itemIgnoresTransformationsFlagValue);
+ QCOMPARE(ownLocationItem3Flags, itemIgnoresTransformationsFlagValue);
+ }
+
+ void TestOwnLocationItem::testSetAndGetPosition()
+ {
+ OwnLocationItem ownLocation;
+ ownLocation.setPosition(testLocationPoint);
+
+ QCOMPARE(ownLocation.position(),
+ MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
+ }
+
+ void TestOwnLocationItem::testHideAndShowPosition()
+ {
+ OwnLocationItem ownLocation;
+
+ QCOMPARE(ownLocation.isVisible(), true);
+
+ ownLocation.hideOwnLocation();
+
+ QCOMPARE(ownLocation.isVisible(), false);
+
+ }
+
+ QTEST_MAIN(TestOwnLocationItem)
+ #include "testownlocationitem.moc"