Skip to content
Permalink
Browse files

add test for QgsSettings::enumSettingValue

  • Loading branch information
3nids committed Feb 17, 2018
1 parent 1198dba commit bda67ada90f52e5fcc800b64d94d3816e32d6106
Showing with 59 additions and 1 deletion.
  1. +2 −1 src/core/qgssettings.h
  2. +1 −0 tests/src/core/CMakeLists.txt
  3. +56 −0 tests/src/core/testqgssettings.cpp
@@ -221,8 +221,9 @@ class CORE_EXPORT QgsSettings : public QObject
#ifndef SIP_RUN

/**
* Return the setting value for a setting defined on an enum.
* Return the setting value for a setting based on an enum.
* This forces the output to be a valid and existing entry of the enum.
* Hence if the setting value is incorrect, the given default value is returned.
* \note The enum needs to be declared with Q_ENUM
*/
template <class T>
@@ -165,6 +165,7 @@ SET(TESTS
testqgsrectangle.cpp
testqgsrenderers.cpp
testqgsrulebasedrenderer.cpp
testqgssettings.cpp
testqgsshapeburst.cpp
testqgssimplemarker.cpp
testqgssnappingutils.cpp
@@ -0,0 +1,56 @@
/***************************************************************************
testqgssettings.cpp
--------------------------------------
Date : 17.02.2018
Copyright : (C) 2018 by Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* 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 <QObject>


#include "qgssettings.h"
#include "qgsunittypes.h"
#include "qgstest.h"


/**
* \ingroup UnitTests
* This is a unit test for the operations on curve geometries
*/
class TestQgsSettings : public QObject
{
Q_OBJECT

private slots:
void enumSettingValue();
};


void TestQgsSettings::enumSettingValue()
{
QgsSettings settings;

// assign to inexisting value
settings.setValue( QStringLiteral( "qgis/testing/my_value_for_units" ), -1 );
// just to be sure it really doesn't exist
QVERIFY( static_cast<int>( QgsUnitTypes::LayoutMeters ) != -1 );

// standard method returns invalid value
int v1 = settings.value( QStringLiteral( "qgis/testing/my_value_for_units" ), QgsUnitTypes::LayoutMeters ).toInt();
QCOMPARE( v1, -1 );

// enum method returns default value if current setting is incorrect
QgsUnitTypes::LayoutUnit v2 = settings.enumSettingValue( QStringLiteral( "qgis/testing/my_value_for_units" ), QgsUnitTypes::LayoutMeters );
QCOMPARE( v2, QgsUnitTypes::LayoutMeters );
}


QGSTEST_MAIN( TestQgsSettings )
#include "testqgssettings.moc"

0 comments on commit bda67ad

Please sign in to comment.
You can’t perform that action at this time.