2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Ville Tiensuu - ville.tiensuu@ixonos.com
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.
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.
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,
22 #include <QtTest/QtTest>
24 #include "map/mapengine.h"
25 #include "map/mapcommon.h"
27 #include "ui/mainwindow.h"
29 const int DEFAULT_TEST_ZOOMLEVEL = 5;
30 const QPoint DEFAULT_TEST_SCENECOORDINATE = QPoint(12345,54321);
31 const QPoint NEW_TEST_SCENECOORDINATE = QPoint(50000,40000);
33 class TestUseLastPosition: public QObject
38 void testMapEngineMethods();
41 void TestUseLastPosition::testMapEngineMethods()
43 // Create mapengine and start monitoring zoomLevelChanged-signal
44 MapEngine *mapengine = new MapEngine;
45 QSignalSpy mapEngineSpy(mapengine, SIGNAL(zoomLevelChanged(int)));
46 QVERIFY (mapEngineSpy.isValid());
47 QCOMPARE (mapEngineSpy.count(), 0);
49 // Write new zoomlevel and location to settings
50 QSettings settings(DIRECTORY_NAME, FILE_NAME);
51 settings.setValue(MAP_LAST_ZOOMLEVEL, DEFAULT_TEST_ZOOMLEVEL);
52 settings.setValue(MAP_LAST_POSITION,
53 mapengine->convertSceneCoordinateToLatLon(DEFAULT_TEST_ZOOMLEVEL,
54 DEFAULT_TEST_SCENECOORDINATE));
56 // Call mapengines init() and verify that signal will be send
58 QCOMPARE (mapEngineSpy.count(), 1);
60 // Remove zoomlevel and location from settings, call init() again and check that
61 // signals is send again
62 settings.remove(MAP_LAST_ZOOMLEVEL);
63 settings.remove(MAP_LAST_POSITION);
65 QCOMPARE(mapEngineSpy.count(), 2);
67 // Check parameters of sended signals
68 QList<QVariant> parameters = mapEngineSpy.takeFirst();
69 QVERIFY(parameters.at(0).toInt() == DEFAULT_TEST_ZOOMLEVEL);
71 parameters = mapEngineSpy.takeFirst();
72 QVERIFY(parameters.at(0).toInt() == DEFAULT_START_ZOOM_LEVEL);
74 // Call set location with know parameter to get location changed
75 // Store new location and zoomlevel to settings
76 mapengine->setLocation(NEW_TEST_SCENECOORDINATE);
79 // Read settings and verify that zoomlevel is correct
80 MapEngine testengine;// = new mapEngine;
81 QPointF LatLonLocation =
82 settings.value(MAP_LAST_POSITION, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toPointF();
83 QCOMPARE(LatLonLocation, testengine.convertSceneCoordinateToLatLon(DEFAULT_TEST_ZOOMLEVEL,
84 NEW_TEST_SCENECOORDINATE));
87 QTEST_MAIN(TestUseLastPosition)
88 #include "testuselastlocation.moc"