|
| 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