From ea1e2d80095310d71525415066aaaf0a25b341f3 Mon Sep 17 00:00:00 2001 From: Ville Tiensuu Date: Mon, 3 May 2010 15:41:48 +0300 Subject: [PATCH] added missing test files --- .../map/friendlocationitem/friendlocationitem.pro | 40 +++++ .../friendlocationitem/testfriendlocationitem.cpp | 155 ++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 tests/map/friendlocationitem/friendlocationitem.pro create mode 100644 tests/map/friendlocationitem/testfriendlocationitem.cpp diff --git a/tests/map/friendlocationitem/friendlocationitem.pro b/tests/map/friendlocationitem/friendlocationitem.pro new file mode 100644 index 0000000..2ff9492 --- /dev/null +++ b/tests/map/friendlocationitem/friendlocationitem.pro @@ -0,0 +1,40 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Apr 27 14:52:31 2010 +###################################################################### + +CONFIG += qtestlib +QT += network +TEMPLATE = app +TARGET = friendlocation +DEPENDPATH += . +INCLUDEPATH += . \ + ../../../src/ + +RESOURCES += ../../../images.qrc + +# Input +SOURCES += testfriendlocationitem.cpp \ + ../../../src/map/mapscene.cpp \ + ../../../src/map/maptile.cpp \ + ../../../src/map/mapengine.cpp \ + ../../../src/map/mapfetcher.cpp \ + ../../../src/map/ownlocationitem.cpp \ + ../../../src/map/mapview.cpp \ + ../../../src/map/mapzoompanel.cpp \ + ../../../src/map/mapbutton.cpp \ + ../../../src/map/baselocationitem.cpp \ + ../../../src/user/user.cpp \ + ../../../src/map/friendlocationitem.cpp + +HEADERS += ../../../src/map/ownlocationitem.h \ + ../../../src/map/mapscene.h \ + ../../../src/map/maptile.h \ + ../../../src/map/mapengine.h \ + ../../../src/map/mapfetcher.h \ + ../../../src/map/mapcommon.h \ + ../../../src/map/mapview.h \ + ../../../src/map/mapzoompanel.h \ + ../../../src/map/mapbutton.h \ + ../../../src/map/baselocationitem.h \ + ../../../src/user/user.h \ + ../../../src/map/friendlocationitem.h diff --git a/tests/map/friendlocationitem/testfriendlocationitem.cpp b/tests/map/friendlocationitem/testfriendlocationitem.cpp new file mode 100644 index 0000000..3283e25 --- /dev/null +++ b/tests/map/friendlocationitem/testfriendlocationitem.cpp @@ -0,0 +1,155 @@ +/* + 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 +#include +#include +#include + +#include "map/friendlocationitem.h" +#include "map/mapscene.h" +#include "map/maptile.h" +#include "map/mapengine.h" +#include "map/mapcommon.h" +#include "map/mapview.h" +#include "map/baselocationitem.h" +#include "user/user.h" +#include "map/friendlocationitem.h" + +namespace Testfriendlocation // 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 Testfriendlocation; + + +/** +* @brief Class that test FriendLocationItem +* +* @author Ville Tiensuu +*/ +class TestFriendLocationItem: public QObject + { + Q_OBJECT + private slots: + + /** + * @brief Test method for constructors. + * Creates instance of FriendLocationItem + * Tests that position is set correctly. + * Tests that location is set correctly. + * Tests that Z-values are set correctly. + * Tests that offses are set correctly. + * Tests that ItemIgnoresTransformations flag is set. + */ + void testConstructor(); + + /** + * @brief Test that position of friend location item is set and get correctly + */ + void testSetAndGetPosition(); + + /** + * @brief Tests that friend location item is possible to set visible and unvisible + */ + void testHideAndShowPosition(); + + /** + * @brief Tests that it is possible to set and get userId for friend location item + */ + void testSetUserId(); + }; + + void TestFriendLocationItem::testConstructor() + { + QPixmap friendIcon(":/res/images/situare_user.jpg"); + FriendLocationItem friendLocation(friendIcon,defaultLocationPoint); + + // Test Pixmap + QPixmap pixmap; + QCOMPARE (pixmap.isNull(), true); + + pixmap = friendLocation.pixmap(); + QCOMPARE (pixmap.isNull(), false); + + // Test Position + QCOMPARE(friendLocation.position(), + MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint)); + + // Test Z-value + QCOMPARE(static_cast(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL); + + // Test Offset + QCOMPARE(friendLocation.offset(), + QPointF(-friendLocation.pixmap().width()/2, -friendLocation.pixmap().height()/2)); + + // Test ItemIgnoresTransformations Flags + QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags(); + QCOMPARE(friendLocationItemFlags, itemIgnoresTransformationsFlagValue); + + } + + void TestFriendLocationItem::testSetAndGetPosition() + { + QPixmap friendIcon(":/res/images/situare_user.jpg"); + FriendLocationItem friendLocation(friendIcon, defaultLocationPoint); + + QCOMPARE(friendLocation.position(), + MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint)); + + friendLocation.setPosition(testLocationPoint); + + QCOMPARE(friendLocation.position(), + MapEngine::convertLatLonToSceneCoordinate(testLocationPoint)); + + } + + void TestFriendLocationItem::testHideAndShowPosition() + { + QPixmap friendIcon(":/res/images/situare_user.jpg"); + FriendLocationItem friendLocation(friendIcon, defaultLocationPoint); + QCOMPARE(friendLocation.isVisible(), true); + + friendLocation.hideLocation(); + QCOMPARE(friendLocation.isVisible(), false); + + friendLocation.showLocation(); + QCOMPARE(friendLocation.isVisible(), true); + } + + void TestFriendLocationItem::testSetUserId() + { + QPixmap friendIcon(":/res/images/situare_user.jpg"); + FriendLocationItem friendLocation(friendIcon, defaultLocationPoint); + + QString userIdentity = "110022"; + friendLocation.setUserId(userIdentity); + QCOMPARE(friendLocation.userId(), userIdentity); + } + + QTEST_MAIN(TestFriendLocationItem) + #include "testfriendlocationitem.moc" -- 1.7.9.5