Fixed unit tests
[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         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include <QtGui>
24 #include <QtTest/QtTest>
25 #include <QDebug>
26 #include <QList>
27
28 #include "map/friendlocationitem.h"
29 #include "map/mapscene.h"
30 #include "map/maptile.h"
31 #include "map/mapengine.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
34 #include "map/baselocationitem.h"
35 #include "user/user.h"
36 #include "map/friendlocationitem.h"
37
38 namespace Testfriendlocation  //  Test data for function is defined in namespace
39 {
40     const QPointF defaultPosition(UNDEFINED, UNDEFINED);
41     const QString userID("ABC123");
42     const QUrl url("http://www.test.com/test.png");
43     const int itemIgnoresTransformationsFlagValue = 0x20;  
44 }
45
46 using namespace Testfriendlocation;
47
48 /**
49   * @brief Class that test FriendLocationItem
50   *
51   * @author Ville Tiensuu - ville.tiensuu@ixonos.com
52   * @author Sami Rämö - sami.ramo@ixonos.com
53   */
54 class TestFriendLocationItem: public QObject
55 {
56     Q_OBJECT
57
58 private slots:
59     /**
60       * @brief Test method for constructors.
61       *
62       * Creates instance of FriendLocationItem
63       * Tests that Z-values are set correctly.
64       * Tests that ItemIgnoresTransformations flag is set.
65       * Tests that default position is set.
66       * Tests that user ID is set
67       */
68     void constructor();
69
70     /**
71       * @brief Test grouping functionality
72       */
73     void grouping();
74
75     /**
76       * @brief Tests that friend location item is possible to set visible and unvisible
77       */
78     void setProfileImage();
79 };
80
81 void TestFriendLocationItem::constructor()
82 {
83     FriendLocationItem friendLocation(userID);
84
85     // Test Z-value
86     QCOMPARE(static_cast<int>(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL);
87
88     // Test ItemIgnoresTransformations Flags
89     QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags();
90     QCOMPARE(friendLocationItemFlags, itemIgnoresTransformationsFlagValue);
91
92     // test default position
93     QCOMPARE(friendLocation.pos(), defaultPosition);
94
95     // test user ID
96     QCOMPARE(friendLocation.userId(), userID);
97
98     // test isPartOfGroup default value
99     QCOMPARE(friendLocation.isPartOfGroup(), false);
100 }
101
102 void TestFriendLocationItem::grouping()
103 {
104     FriendLocationItem friendLocation(userID);
105
106     // test defaults
107     QCOMPARE(friendLocation.isPartOfGroup(), false);
108     QCOMPARE(friendLocation.isVisible(), true);
109
110     // group item
111     friendLocation.setPartOfGroup(true);
112
113     // flag should be set and item should be hidden
114     QCOMPARE(friendLocation.isPartOfGroup(), true);
115     QCOMPARE(friendLocation.isVisible(), false);
116
117     // back to ungrouped state
118     friendLocation.setPartOfGroup(false);
119
120     // test
121     QCOMPARE(friendLocation.isPartOfGroup(), false);
122     QCOMPARE(friendLocation.isVisible(), true);
123 }
124
125 void TestFriendLocationItem::setProfileImage()
126 {
127     FriendLocationItem friendLocation(userID);
128
129     //default pixmap and URL should be empty
130     QCOMPARE(friendLocation.pixmap().isNull(), true);
131     QCOMPARE(friendLocation.profileImageUrl().isEmpty(), true);
132
133     QPixmap friendIcon("situare_user.gif");
134     friendLocation.setProfileImage(friendIcon, url);
135
136     // picture should be set
137     QCOMPARE(friendLocation.pixmap().isNull(), false);
138
139     // Test Offset
140     QCOMPARE(friendLocation.offset(),
141              QPointF(-friendIcon.width() / 2, -friendIcon.height() / 2));
142
143     // test url
144     QCOMPARE(friendLocation.profileImageUrl(), url);
145 }
146
147 QTEST_MAIN(TestFriendLocationItem)
148 #include "testfriendlocationitem.moc"