added base class for own and friend locations. added new class for
[situare] / tests / map / ownlocationitem / testownlocationitem.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 <QtTest/QtTest>
23 #include <QDebug>
24 #include <QList>
25
26 #include "map/ownlocationitem.h"
27 #include "map/mapscene.h"
28 #include "map/maptile.h"
29 #include "map/mapengine.h"
30 #include "map/mapcommon.h"
31 #include "map/mapview.h"
32 #include "map/baselocationitem.h"
33 #include "user/user.h"
34 #include "map/friendlocationitem.h"
35
36 namespace TestOwnLocation  //  Test data for function is defined in namespace
37 {   
38     const qreal xCoordinate = 65.525;
39     const qreal yCoordinate = 25.345;
40     const QPointF testLocationPoint(65.525, 25.345);
41     const QPointF defaultLocationPoint(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
42     const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
43     const int itemIgnoresTransformationsFlagValue = 0x20;
44 }
45
46 using namespace TestOwnLocation;
47
48
49 /**
50 * @brief Class that test OwnLocationItem
51 *
52 * @author Ville Tiensuu
53 */
54 class TestOwnLocationItem: public QObject
55  {
56      Q_OBJECT
57  private slots:
58
59     /**
60     * @brief Test method for constructors.
61     *        Creates instance of OwnLocationItem using three different constructors and tests
62     *        that positions are set correctly.
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 testConstructors();
68
69      /**
70      * @brief Creates instance of OwnLocationItem.
71      *        Sets test position for location item in geographic coordinates.
72      *        Reads position from location item in scene coordinates and
73      *        verifies that it correctly formed.
74      */
75      void testSetAndGetPosition();
76
77      /**
78      * @brief Creates instance of OwnLocationItem.
79      *        Verifies that instance is visible.
80      *        Hides instance and verifies that it is not visible.
81      */
82      void testHideAndShowPosition();
83  };
84
85  void TestOwnLocationItem::testConstructors()
86  {
87
88      OwnLocationItem ownLocationItem(defaultLocationPoint);
89
90      // Test Pixmap
91      QPixmap pixmap;
92      QCOMPARE (pixmap.isNull(), true);
93
94      pixmap = ownLocationItem.pixmap();
95      QCOMPARE (pixmap.isNull(), false);
96
97
98      // Test Position
99      QCOMPARE(ownLocationItem.position(),
100               MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint));
101
102      // Test Z-value
103      QCOMPARE(static_cast<int>(ownLocationItem.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
104
105
106      // Test Offset
107 //     QCOMPARE(ownLocationItem.offset(),
108 //              QPoint(-ownLocationItem.pixmap().width(), -ownLocationItem.pixmap().height()));
109
110
111      // Test ItemIgnoresTransformations Flags
112      QGraphicsItem::GraphicsItemFlags ownLocationItemFlags = ownLocationItem.flags();
113      QCOMPARE(ownLocationItemFlags, itemIgnoresTransformationsFlagValue);
114
115  }
116
117  void TestOwnLocationItem::testSetAndGetPosition()
118  {
119      OwnLocationItem ownLocation(defaultLocationPoint);
120
121      QCOMPARE(ownLocation.position(),
122               MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint));
123
124      ownLocation.setPosition(testLocationPoint);
125
126      QCOMPARE(ownLocation.position(),
127               MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
128
129  }
130
131  void TestOwnLocationItem::testHideAndShowPosition()
132  {
133      OwnLocationItem ownLocation(defaultLocationPoint);
134      QCOMPARE(ownLocation.isVisible(), true);     
135
136      ownLocation.hideLocation();
137      QCOMPARE(ownLocation.isVisible(), false);
138
139      ownLocation.showLocation();
140      QCOMPARE(ownLocation.isVisible(), true);
141  }
142
143  QTEST_MAIN(TestOwnLocationItem)
144  #include "testownlocationitem.moc"