From 332961f7484aec324f1db586dafac0c34127d409 Mon Sep 17 00:00:00 2001 From: alisovenko Date: Mon, 6 Feb 2017 14:12:57 +0300 Subject: [PATCH] Add test for map edit tool. Test the correctness of getting default z. --- tests/src/gui/CMakeLists.txt | 1 + tests/src/gui/testqgsmaptooledit.cpp | 83 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tests/src/gui/testqgsmaptooledit.cpp diff --git a/tests/src/gui/CMakeLists.txt b/tests/src/gui/CMakeLists.txt index cb3eaeefd2e..25018ed7005 100644 --- a/tests/src/gui/CMakeLists.txt +++ b/tests/src/gui/CMakeLists.txt @@ -119,6 +119,7 @@ MACRO (ADD_QGIS_TEST testname testsrc) ENDMACRO (ADD_QGIS_TEST) ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp) +ADD_QGIS_TEST(edittooltest testqgsmaptooledit.cpp) # a simple app for testing GUI of renderers # These tests are old and are never run so removed for now. diff --git a/tests/src/gui/testqgsmaptooledit.cpp b/tests/src/gui/testqgsmaptooledit.cpp new file mode 100644 index 00000000000..e3d8b3fe569 --- /dev/null +++ b/tests/src/gui/testqgsmaptooledit.cpp @@ -0,0 +1,83 @@ +/*************************************************************************** + testqgsmaptooledit.cpp + -------------------------------------- + Date : 6.2.2017 + Copyright : (C) 2017 Alexander Lisovenko + Email : alexander.lisovenko@gmail.com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include + +#include "qgstest.h" +#include +#include +#include +#include +#include + +class TestQgsMapToolEdit : public QObject +{ + Q_OBJECT + public: + TestQgsMapToolEdit() + : mCanvas( 0 ) + {} + + private slots: + void initTestCase(); // will be called before the first testfunction is executed. + void cleanupTestCase(); // will be called after the last testfunction was executed. + void init(); // will be called before each testfunction is executed. + void cleanup(); // will be called after every testfunction. + + void checkDefaultZValue(); + + private: + QgsMapCanvas* mCanvas; + +}; + +void TestQgsMapToolEdit::initTestCase() +{ + QgsApplication::init(); + QgsApplication::initQgis(); + QgsApplication::showSettings(); +} + +void TestQgsMapToolEdit::cleanupTestCase() +{ + QgsApplication::exitQgis(); +} + +void TestQgsMapToolEdit::init() +{ + mCanvas = new QgsMapCanvas(); +} + +void TestQgsMapToolEdit::cleanup() +{ + delete mCanvas; +} + +void TestQgsMapToolEdit::checkDefaultZValue() +{ + QSettings settings; + settings.remove( "/qgis/digitizing/default_z_value" ); + + QgsMapToolEdit* tool = new QgsMapToolEdit( mCanvas ); + QCOMPARE( tool->defaultZValue(), Qgis::DEFAULT_Z_COORDINATE ); + + double z_value_for_test = Qgis::DEFAULT_Z_COORDINATE + 1; + settings.setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), z_value_for_test ); + + + QCOMPARE( tool->defaultZValue(), z_value_for_test ); +} + +QGSTEST_MAIN( TestQgsMapToolEdit ) +#include "testqgsmaptooledit.moc"