989d715feedf7d427b8e6e99b1f4f07388e3548a
[situare] / tests / map / friendlocationitem / testfriendlocationitem.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Ville Tiensuu - ville.tiensuu@ixonos.com
6
7     Situare is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     version 2 as published by the Free Software Foundation.
10
11     Situare is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with Situare; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19     USA.
20 */
21
22 #include <QtGui>
23 #include <QtTest/QtTest>
24 #include <QDebug>
25 #include <QList>
26
27 #include "map/friendlocationitem.h"
28 #include "map/mapscene.h"
29 #include "map/maptile.h"
30 #include "map/mapengine.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
33 #include "map/baselocationitem.h"
34 #include "user/user.h"
35 #include "map/friendlocationitem.h"
36
37 namespace Testfriendlocation  //  Test data for function is defined in namespace
38 {
39     const qreal xCoordinate = 65.525;
40     const qreal yCoordinate = 25.345;
41     const QPointF testLocationPoint(65.525, 25.345);
42     const QPointF defaultLocationPoint(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
43     const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
44     const int itemIgnoresTransformationsFlagValue = 0x20;  
45 }
46
47 using namespace Testfriendlocation;
48
49
50 /**
51 * @brief Class that test FriendLocationItem
52 *
53 * @author Ville Tiensuu
54 */
55 class TestFriendLocationItem: public QObject
56  {
57      Q_OBJECT
58  private slots:
59
60     /**
61     * @brief Test method for constructors.
62     *        Creates instance of FriendLocationItem
63     *        Tests that Z-values are set correctly.
64     *        Tests that offses are set correctly.
65     *        Tests that ItemIgnoresTransformations flag is set.
66     */
67      void testConstructor();
68
69      /**
70      * @brief Tests that friend location item is possible to set visible and unvisible
71      */
72      void testHideAndShowPosition();
73
74      /**
75      * @brief  Tests that it is possible to set and get userId for friend location item
76      */
77      void testSetUserId();
78  };
79
80  void TestFriendLocationItem::testConstructor()
81  {    
82      QPixmap friendIcon("situare_user.gif");
83      FriendLocationItem friendLocation(friendIcon);
84
85      // Test Pixmap
86      QPixmap pixmap;
87      QCOMPARE (pixmap.isNull(), true);
88
89      pixmap = friendLocation.pixmap();
90      QCOMPARE (pixmap.isNull(), false);
91
92      // Test Z-value
93      QCOMPARE(static_cast<int>(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL);
94
95      // Test Offset
96      QCOMPARE(friendLocation.offset(),
97               QPointF(-friendLocation.pixmap().width()/2, -friendLocation.pixmap().height()/2));
98
99      // Test ItemIgnoresTransformations Flags
100      QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags();
101      QCOMPARE(friendLocationItemFlags, itemIgnoresTransformationsFlagValue);
102
103  }
104
105  void TestFriendLocationItem::testHideAndShowPosition()
106  {
107      QPixmap friendIcon(":/res/images/situare_user.jpg");
108      FriendLocationItem friendLocation(friendIcon);
109      QCOMPARE(friendLocation.isVisible(), true);
110
111      friendLocation.hideLocation();
112      QCOMPARE(friendLocation.isVisible(), false);
113
114      friendLocation.showLocation();
115      QCOMPARE(friendLocation.isVisible(), true);
116  } 
117
118  void TestFriendLocationItem::testSetUserId()
119  {
120      QPixmap friendIcon("situare_user.jpg");
121      FriendLocationItem friendLocation(friendIcon);
122
123      QString userIdentity = "110022";
124      friendLocation.setUserId(userIdentity);
125      QCOMPARE(friendLocation.userId(), userIdentity);
126  }
127
128  QTEST_MAIN(TestFriendLocationItem)
129  #include "testfriendlocationitem.moc"