Skip to content

Commit c0531bc

Browse files
committedMay 26, 2017
Add test for QgsScaleRangeWidget::setScaleRange
Closes #15463 as this test guards after the fix for that bug (minScale visibility corrupted upon project load)
1 parent 2a9095d commit c0531bc

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
 

‎tests/src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
138138
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
139139
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp)
140140
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
141+
ADD_QGIS_TEST(scalerangewidget testqgsscalerangewidget.cpp)
141142
ADD_QGIS_TEST(spinbox testqgsspinbox.cpp)
142143
ADD_QGIS_TEST(sqlcomposerdialog testqgssqlcomposerdialog.cpp)
143144
ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/***************************************************************************
2+
testqgsscalerangewidget.cpp
3+
---------------------------
4+
begin : May 2017
5+
copyright : (C) 2017 by Sandro Santilli
6+
email : strk at kbt dot io
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsscalerangewidget.h"
19+
#include "qgsapplication.h"
20+
#include "qgslogger.h"
21+
22+
#include <QObject>
23+
#include <QLineEdit>
24+
#include <QComboBox>
25+
#include <QtTest/QSignalSpy>
26+
#include <QtTest/QtTest>
27+
28+
#include <memory>
29+
30+
/** @ingroup UnitTests
31+
* This is a unit test for the scale range widget
32+
*
33+
* @see QgsScaleRangeWidget
34+
*/
35+
class TestQgsScaleRangeWidget : public QObject
36+
{
37+
Q_OBJECT
38+
private slots:
39+
void initTestCase();// will be called before the first testfunction is executed.
40+
void cleanupTestCase();// will be called after the last testfunction was executed.
41+
void init();// will be called before each testfunction is executed.
42+
void cleanup();// will be called after every testfunction.
43+
void test_setScaleRange();
44+
private:
45+
std::unique_ptr<QgsScaleRangeWidget> widget;
46+
};
47+
48+
void TestQgsScaleRangeWidget::initTestCase()
49+
{
50+
QgsApplication::init();
51+
QgsApplication::initQgis();
52+
}
53+
54+
void TestQgsScaleRangeWidget::cleanupTestCase()
55+
{
56+
QgsApplication::exitQgis();
57+
}
58+
59+
void TestQgsScaleRangeWidget::init()
60+
{
61+
widget.reset( new QgsScaleRangeWidget() );
62+
}
63+
64+
void TestQgsScaleRangeWidget::cleanup()
65+
{
66+
}
67+
68+
void TestQgsScaleRangeWidget::test_setScaleRange()
69+
{
70+
// Test that setting scale range is always honoured
71+
// rather than being limited by previously set
72+
// max or min.
73+
// See https://issues.qgis.org/issues/15463
74+
75+
widget->setScaleRange( 4.0, 6.0 );
76+
QCOMPARE( widget->minimumScale(), 4.0 );
77+
QCOMPARE( widget->maximumScale(), 6.0 );
78+
79+
widget->setScaleRange( 8.0, 10.0 );
80+
QCOMPARE( widget->minimumScale(), 8.0 );
81+
QCOMPARE( widget->maximumScale(), 10.0 );
82+
83+
widget->setScaleRange( 2.0, 4.0 );
84+
QCOMPARE( widget->minimumScale(), 2.0 );
85+
QCOMPARE( widget->maximumScale(), 4.0 );
86+
87+
// TODO: test passing min > max
88+
89+
}
90+
91+
QTEST_MAIN( TestQgsScaleRangeWidget )
92+
#include "testqgsscalerangewidget.moc"

0 commit comments

Comments
 (0)