Modified MapView::mouseDoubleClickEvent.
[situare] / tests / map / mapview / testmapview.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@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
24 #include "map/mapview.h"
25
26 class TestMapView: public QObject
27 {
28     Q_OBJECT
29 public:
30     TestMapView();
31
32 private slots:
33     void init();
34     void cleanup();
35     void doubleClick();
36     void zoomLevelChange_data();
37     void zoomLevelChange();
38
39 private:
40     MapView *m_mapView;
41 };
42
43 /**
44   * @brief Constructor for setting pointer to MapView to NULL
45   */
46 TestMapView::TestMapView() : m_mapView(NULL)
47 {
48
49 }
50
51 /**
52   * @brief Test case initialization
53   */
54 void TestMapView::init()
55 {
56     m_mapView = new MapView();
57     QVERIFY(m_mapView);
58 }
59
60 /**
61   * @brief Test case cleanup
62   */
63 void TestMapView::cleanup()
64 {
65     delete m_mapView;
66     m_mapView = 0;
67 }
68
69 /**
70   * @brief Test view double click
71   */
72 void TestMapView::doubleClick()
73 {
74     QSignalSpy doubleClickSpy(m_mapView, SIGNAL(zoomIn()));
75     QVERIFY(doubleClickSpy.isValid());
76
77     QTest::mouseDClick(m_mapView, Qt::Key_Tab);
78     QCOMPARE(doubleClickSpy.count(), 1);
79 }
80
81 /**
82   * @brief Test data for zoom level change test
83   */
84 void TestMapView::zoomLevelChange_data()
85 {
86     QTest::addColumn<int>("zoomLevel");
87     QTest::addColumn<qreal>("result");
88
89     QTest::newRow("zoom 18") << 18 << 1.0;
90     QTest::newRow("zoom 17") << 17 << 0.5;
91     QTest::newRow("zoom 16") << 16 << 0.25;
92     QTest::newRow("zoom 15") << 15 << 0.125;
93 }
94
95 /**
96   * @brief Test view zoom level scaling
97   */
98 void TestMapView::zoomLevelChange()
99 {
100     QFETCH(int, zoomLevel);
101     QFETCH(qreal, result);
102
103     m_mapView->setZoomLevel(zoomLevel);
104     QTest::qWait(300);
105     QCOMPARE(m_mapView->transform().m11(), result);
106     QCOMPARE(m_mapView->transform().m22(), result);
107 }
108
109 QTEST_MAIN(TestMapView)
110 #include "testmapview.moc"