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 "qgstest.h"
19 
20 #include "qgsscalerangewidget.h"
21 #include "qgsapplication.h"
22 #include "qgslogger.h"
23 
24 #include <QObject>
25 #include <QLineEdit>
26 #include <QComboBox>
27 #include <QtTest/QSignalSpy>
28 
29 #include <memory>
30 
31 /**
32  * @ingroup UnitTests
33  * This is a unit test for the scale range widget
34  *
35  * \see QgsScaleRangeWidget
36  */
37 class TestQgsScaleRangeWidget : public QObject
38 {
39     Q_OBJECT
40   private slots:
41     void initTestCase();// will be called before the first testfunction is executed.
42     void cleanupTestCase();// will be called after the last testfunction was executed.
43     void init();// will be called before each testfunction is executed.
44     void cleanup();// will be called after every testfunction.
45     void test_setScaleRange();
46   private:
47     std::unique_ptr<QgsScaleRangeWidget> widget;
48 };
49 
initTestCase()50 void TestQgsScaleRangeWidget::initTestCase()
51 {
52   QgsApplication::init();
53   QgsApplication::initQgis();
54 }
55 
cleanupTestCase()56 void TestQgsScaleRangeWidget::cleanupTestCase()
57 {
58   QgsApplication::exitQgis();
59 }
60 
init()61 void TestQgsScaleRangeWidget::init()
62 {
63   widget.reset( new QgsScaleRangeWidget() );
64 }
65 
cleanup()66 void TestQgsScaleRangeWidget::cleanup()
67 {
68 }
69 
test_setScaleRange()70 void TestQgsScaleRangeWidget::test_setScaleRange()
71 {
72   // Test that setting scale range is always honoured
73   // rather than being limited by previously set
74   // max or min.
75   // See https://github.com/qgis/QGIS/issues/23389
76 
77   widget->setScaleRange( 6, 4 );
78   QCOMPARE( widget->minimumScale(), 6.0 );
79   QCOMPARE( widget->maximumScale(), 4.0 );
80 
81   widget->setScaleRange( 10.0, 8 );
82   QCOMPARE( widget->minimumScale(), 10.0 );
83   QCOMPARE( widget->maximumScale(), 8.0 );
84 
85   widget->setScaleRange( 4, 2 );
86   QCOMPARE( widget->minimumScale(), 4.0 );
87   QCOMPARE( widget->maximumScale(), 2.0 );
88 
89   // TODO: test passing min > max
90 
91 }
92 
93 QGSTEST_MAIN( TestQgsScaleRangeWidget )
94 #include "testqgsscalerangewidget.moc"
95