Changed MapView::setZoomLevel to public, updated MapView unit tests
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 13 Apr 2010 11:56:20 +0000 (14:56 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 13 Apr 2010 11:56:20 +0000 (14:56 +0300)
src/map/mapview.h
tests/testmap/testmapview/testmapview.cpp
tests/testmap/testmapview/testmapview.pro

index 97c31cf..fda5892 100644 (file)
@@ -68,6 +68,13 @@ public slots:
     */
     void centerToSceneCoordinates(QPointF sceneCoordinate);
 
+    /**
+    * @brief Set zoom level of the view
+    *
+    * @param zoomLevel Zoom level
+    */
+    void setZoomLevel(int zoomLevel);
+
 protected:
     void resizeEvent(QResizeEvent *event);
 
@@ -91,13 +98,6 @@ private slots:
     void mousePressEvent(QMouseEvent *event);
 
     /**
-    * @brief Set zoom level of the view
-    *
-    * @param zoomLevel Zoom level
-    */
-    void setZoomLevel(int zoomLevel);
-
-    /**
     * @brief Timer events for smooth zoom effect
     *
     * @param event
index e6e08cf..3641eb4 100644 (file)
 class TestMapView: public QObject
 {
     Q_OBJECT
+public:
+    TestMapView();
+
 private slots:
-//    void dummyTestCase();
+    void init();
+    void cleanup();
+    void zoomLevelChange_data();
+    void zoomLevelChange();
+
+private:
+    MapView *m_mapView;
 };
 
-/**
-* @brief DUMMY TESTCASE!
-* @todo Implement test(s) when there is something to be tested
-*/
-//void TestMapView::dummyTestCase()
-//{
-//    QVERIFY(true);
-//}
+TestMapView::TestMapView() : m_mapView(0)
+{
+
+}
+
+void TestMapView::init()
+{
+    m_mapView = new MapView();
+    QVERIFY(m_mapView);
+}
+
+void TestMapView::cleanup()
+{
+    delete m_mapView;
+    m_mapView = 0;
+}
+
+void TestMapView::zoomLevelChange_data()
+{
+    QTest::addColumn<int>("zoomLevel");
+    QTest::addColumn<qreal>("result");
+
+    QTest::newRow("zoom 18") << 18 << 1.0;
+    QTest::newRow("zoom 17") << 17 << 0.5;
+    QTest::newRow("zoom 16") << 16 << 0.25;
+    QTest::newRow("zoom 15") << 15 << 0.125;
+}
+
+void TestMapView::zoomLevelChange()
+{
+    QFETCH(int, zoomLevel);
+    QFETCH(qreal, result);
+
+    m_mapView->setZoomLevel(zoomLevel);
+    QTest::qWait(300);
+    QCOMPARE(m_mapView->transform().m11(), result);
+    QCOMPARE(m_mapView->transform().m22(), result);
+}
 
 QTEST_MAIN(TestMapView)
 #include "testmapview.moc"
index fbd09d9..86c3ec2 100644 (file)
@@ -2,6 +2,7 @@
 # Automatically generated by qmake (2.01a) Fri Mar 26 15:22:56 2010
 # #####################################################################
 CONFIG += qtestlib
+QT += opengl
 TEMPLATE = app
 TARGET = 
 DEPENDPATH += .