|
| 1 | +/*************************************************************************** |
| 2 | + testqgssettings.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : 17.02.2018 |
| 5 | + Copyright : (C) 2018 by Denis Rouzaud |
| 6 | + Email : denis.rouzaud@gmail.com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | +#include <QObject> |
| 16 | + |
| 17 | + |
| 18 | +#include "qgssettings.h" |
| 19 | +#include "qgsunittypes.h" |
| 20 | +#include "qgstest.h" |
| 21 | + |
| 22 | + |
| 23 | +/** |
| 24 | + * \ingroup UnitTests |
| 25 | + * This is a unit test for the operations on curve geometries |
| 26 | + */ |
| 27 | +class TestQgsSettings : public QObject |
| 28 | +{ |
| 29 | + Q_OBJECT |
| 30 | + |
| 31 | + private slots: |
| 32 | + void enumSettingValue(); |
| 33 | +}; |
| 34 | + |
| 35 | + |
| 36 | +void TestQgsSettings::enumSettingValue() |
| 37 | +{ |
| 38 | + QgsSettings settings; |
| 39 | + |
| 40 | + // assign to inexisting value |
| 41 | + settings.setValue( QStringLiteral( "qgis/testing/my_value_for_units" ), -1 ); |
| 42 | + // just to be sure it really doesn't exist |
| 43 | + QVERIFY( static_cast<int>( QgsUnitTypes::LayoutMeters ) != -1 ); |
| 44 | + |
| 45 | + // standard method returns invalid value |
| 46 | + int v1 = settings.value( QStringLiteral( "qgis/testing/my_value_for_units" ), QgsUnitTypes::LayoutMeters ).toInt(); |
| 47 | + QCOMPARE( v1, -1 ); |
| 48 | + |
| 49 | + // enum method returns default value if current setting is incorrect |
| 50 | + QgsUnitTypes::LayoutUnit v2 = settings.enumSettingValue( QStringLiteral( "qgis/testing/my_value_for_units" ), QgsUnitTypes::LayoutMeters ); |
| 51 | + QCOMPARE( v2, QgsUnitTypes::LayoutMeters ); |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +QGSTEST_MAIN( TestQgsSettings ) |
| 56 | +#include "testqgssettings.moc" |
0 commit comments