Fixed ownLocationItem unit test to reflect recent changes to the
[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(UNDEFINED, UNDEFINED);
42     const int MAP_OWN_LOCATION_ICON_SIZE = 24;
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 TestOwnLocation;
48
49
50 /**
51 * @brief Class that test OwnLocationItem
52 *
53 * @author Ville Tiensuu
54 */
55 class TestOwnLocationItem: public QObject
56  {
57      Q_OBJECT
58  private slots:
59
60     /**
61     * @brief Test method for constructors.
62     *
63     * Tests that default position is set correctly.
64     * Tests that item has pixmap set.
65     * Tests that Z-value is set correctly.
66     * Tests that offset is set correctly.
67     * Tests that ItemIgnoresTransformations flag is set.
68     */
69      void testConstructors();
70  };
71
72  void TestOwnLocationItem::testConstructors()
73  {
74
75      OwnLocationItem ownLocationItem;
76
77      // Test Pixmap
78      QPixmap pixmap;
79      QCOMPARE (pixmap.isNull(), true);
80
81      pixmap = ownLocationItem.pixmap();
82      QCOMPARE (pixmap.isNull(), false);
83
84      // Test Position
85      QCOMPARE(ownLocationItem.pos(), defaultLocationPoint);
86
87      // Test Z-value
88      QCOMPARE(static_cast<int>(ownLocationItem.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
89
90      // Test Offset
91      QCOMPARE(ownLocationItem.offset(),
92               QPointF(-ownLocationItem.pixmap().width()/2, -41));
93
94      // Test ItemIgnoresTransformations Flags
95      QGraphicsItem::GraphicsItemFlags ownLocationItemFlags = ownLocationItem.flags();
96      QCOMPARE(ownLocationItemFlags, itemIgnoresTransformationsFlagValue);
97  }
98
99  QTEST_MAIN(TestOwnLocationItem)
100  #include "testownlocationitem.moc"