Skip to content
Permalink
Browse files
Add test for QgsScaleRangeWidget::setScaleRange
Closes #15463 as this test guards after the fix for that bug
(minScale visibility corrupted upon project load)
  • Loading branch information
strk committed May 26, 2017
1 parent 2a9095d commit c0531bcd896741eca4cfd8c83138b5b0181e94df
Showing with 93 additions and 0 deletions.
  1. +1 −0 tests/src/gui/CMakeLists.txt
  2. +92 −0 tests/src/gui/testqgsscalerangewidget.cpp
@@ -138,6 +138,7 @@ ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp)
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
ADD_QGIS_TEST(scalerangewidget testqgsscalerangewidget.cpp)
ADD_QGIS_TEST(spinbox testqgsspinbox.cpp)
ADD_QGIS_TEST(sqlcomposerdialog testqgssqlcomposerdialog.cpp)
ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp)
@@ -0,0 +1,92 @@
/***************************************************************************
testqgsscalerangewidget.cpp
---------------------------
begin : May 2017
copyright : (C) 2017 by Sandro Santilli
email : strk at kbt dot io
***************************************************************************/

/***************************************************************************
* *
* 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 "qgsscalerangewidget.h"
#include "qgsapplication.h"
#include "qgslogger.h"

#include <QObject>
#include <QLineEdit>
#include <QComboBox>
#include <QtTest/QSignalSpy>
#include <QtTest/QtTest>

#include <memory>

/** @ingroup UnitTests
* This is a unit test for the scale range widget
*
* @see QgsScaleRangeWidget
*/
class TestQgsScaleRangeWidget : public QObject
{
Q_OBJECT
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 test_setScaleRange();
private:
std::unique_ptr<QgsScaleRangeWidget> widget;
};

void TestQgsScaleRangeWidget::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsScaleRangeWidget::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsScaleRangeWidget::init()
{
widget.reset( new QgsScaleRangeWidget() );
}

void TestQgsScaleRangeWidget::cleanup()
{
}

void TestQgsScaleRangeWidget::test_setScaleRange()
{
// Test that setting scale range is always honoured
// rather than being limited by previously set
// max or min.
// See https://issues.qgis.org/issues/15463

widget->setScaleRange( 4.0, 6.0 );
QCOMPARE( widget->minimumScale(), 4.0 );
QCOMPARE( widget->maximumScale(), 6.0 );

widget->setScaleRange( 8.0, 10.0 );
QCOMPARE( widget->minimumScale(), 8.0 );
QCOMPARE( widget->maximumScale(), 10.0 );

widget->setScaleRange( 2.0, 4.0 );
QCOMPARE( widget->minimumScale(), 2.0 );
QCOMPARE( widget->maximumScale(), 4.0 );

// TODO: test passing min > max

}

QTEST_MAIN( TestQgsScaleRangeWidget )
#include "testqgsscalerangewidget.moc"

0 comments on commit c0531bc

Please sign in to comment.