Fixed seg fault on logout.
[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
28 namespace TestOwnLocation  //  Test data for function is defined in namespace
29 {
30     const qreal xCoordinate = 65.525;
31     const qreal yCoordinate = 25.345;
32     const QPointF testLocationPoint(65.525, 25.345);
33     const QPointF defaultLocationPoint(UNDEFINED, UNDEFINED);
34     const int MAP_OWN_LOCATION_ICON_SIZE = 24;
35     const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
36     const int itemIgnoresTransformationsFlagValue = 0x20;
37 }
38
39 using namespace TestOwnLocation;
40
41
42 /**
43 * @brief Class that test OwnLocationItem
44 *
45 * @author Ville Tiensuu
46 */
47 class TestOwnLocationItem: public QObject
48  {
49      Q_OBJECT
50  private slots:
51
52     /**
53     * @brief Test method for constructors.
54     *
55     * Tests that default position is set correctly.
56     * Tests that item has pixmap set.
57     * Tests that Z-value is set correctly.
58     * Tests that offset is set correctly.
59     * Tests that ItemIgnoresTransformations flag is set.
60     */
61      void testConstructors();
62  };
63
64  void TestOwnLocationItem::testConstructors()
65  {
66
67      OwnLocationItem ownLocationItem;
68
69      // Test Pixmap
70      QPixmap pixmap;
71      QCOMPARE (pixmap.isNull(), true);
72
73      pixmap = ownLocationItem.pixmap();
74      QCOMPARE (pixmap.isNull(), false);
75
76      // Test Position
77      QCOMPARE(ownLocationItem.pos(), defaultLocationPoint);
78
79      // Test Z-value
80      QCOMPARE(static_cast<int>(ownLocationItem.zValue()), static_cast<int>(GPSLocationItemZValue));
81
82      // Test Offset
83      QCOMPARE(ownLocationItem.offset(),
84               QPointF(-ownLocationItem.pixmap().width()/2, -41));
85
86      // Test ItemIgnoresTransformations Flags
87      QGraphicsItem::GraphicsItemFlags ownLocationItemFlags = ownLocationItem.flags();
88      QCOMPARE(ownLocationItemFlags, itemIgnoresTransformationsFlagValue);
89  }
90
91  QTEST_MAIN(TestOwnLocationItem)
92  #include "testownlocationitem.moc"