Skip to content
Permalink
Browse files

complete test for qgsEnumKeyToValue

  • Loading branch information
3nids committed Sep 10, 2020
1 parent 0b2abff commit 86c4aaa6def9756a985d44137bba48b3d0b4e23b
Showing with 9 additions and 1 deletion.
  1. +9 −1 tests/src/core/testqgis.cpp
@@ -410,8 +410,16 @@ void TestQgis::testQgsEnumValueToKey()
}
void TestQgis::testQgsEnumKeyToValue()
{
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QStringLiteral( "LayerRole" ), QgsMapLayerModel::LayerIdRole ), QgsMapLayerModel::LayerRole );
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QStringLiteral( "AdditionalRole" ), QgsMapLayerModel::LayerIdRole ), QgsMapLayerModel::AdditionalRole );
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QStringLiteral( "UnknownKey" ), QgsMapLayerModel::LayerIdRole ), QgsMapLayerModel::LayerIdRole );
// try with int values as string keys
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QString::number( QgsMapLayerModel::AdditionalRole ), QgsMapLayerModel::LayerIdRole, true ), QgsMapLayerModel::AdditionalRole );
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QString::number( QgsMapLayerModel::AdditionalRole ), QgsMapLayerModel::LayerIdRole, false ), QgsMapLayerModel::LayerIdRole );
// also try with an invalid int value
QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayerModel::ItemDataRole>();
int invalidValue = QgsMapLayerModel::LayerIdRole + 100;
QVERIFY( !metaEnum.valueToKey( invalidValue ) );
QCOMPARE( qgsEnumKeyToValue<QgsMapLayerModel::ItemDataRole>( QString::number( invalidValue ), QgsMapLayerModel::LayerIdRole ), QgsMapLayerModel::LayerIdRole );
}

void TestQgis::testQgsFlagValueToKeys()

0 comments on commit 86c4aaa

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