diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-10-30 13:02:03 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-10-31 19:36:00 +0200 |
commit | e90705687f5faba41d9a8544c875d8c6b1cedbdc (patch) | |
tree | 8b82b8142355b14f0e31cc71f0f0c0679c434a1e /tests/auto | |
parent | 7c41f31efa651cd3cbba33b3220cc810da8b174e (diff) |
QMetaEnum: refactor keysToValue
- Show warning messages for malformed keys string
- Use QBAV instead of QL1SV, some methods in the public API may get
QU8SV overloads in later commits
- Extend unittests; also rename the unittest, it's really testing
key(s)ToValue()
Change-Id: Iec944ef4c2c5d18ab038cb933e954cf50c912523
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index aed8e48afe..362f2707e7 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -312,8 +312,8 @@ private slots: void normalizedType_data(); void normalizedType(); void customPropertyType(); - void checkScope_data(); - void checkScope(); + void keysToValue_data(); + void keysToValue(); // Also keyToValue() void propertyNotify(); void propertyConstant(); void propertyFinal(); @@ -2339,7 +2339,7 @@ void tst_QMetaObject::customPropertyType() QCOMPARE(prop.metaType().id(), QMetaType::QVariantList); } -void tst_QMetaObject::checkScope_data() +void tst_QMetaObject::keysToValue_data() { QTest::addColumn<QObject *>("object"); QTest::addColumn<QByteArray>("name"); @@ -2353,7 +2353,7 @@ void tst_QMetaObject::checkScope_data() } -void tst_QMetaObject::checkScope() +void tst_QMetaObject::keysToValue() { QFETCH(QObject *, object); QFETCH(QByteArray, name); @@ -2419,6 +2419,28 @@ void tst_QMetaObject::checkScope() QCOMPARE(mf.keysToValue("MyNamespace::" + name + "::MyFlag2|MyNamespace::" + name + "::MyFlag2", &ok), 2); QCOMPARE(ok, true); QCOMPARE(QLatin1String(mf.valueToKeys(3)), QLatin1String("MyFlag1|MyFlag2")); + + // Test flags with extra '|' + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression(u"QMetaEnum::keysToValue: malformed keys string, ends with '|'.+"_s)); + QCOMPARE(mf.keysToValue("MyFlag1|MyFlag2|", &ok), -1); + QCOMPARE(ok, false); + + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression(u"QMetaEnum::keysToValue: malformed keys string, starts with '|'.+"_s)); + QCOMPARE(mf.keysToValue("|MyFlag1|MyFlag2|", &ok), -1); + QCOMPARE(ok, false); + + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression( + u"QMetaEnum::keysToValue: malformed keys string, has two consecutive '|'.+"_s)); + QCOMPARE(mf.keysToValue("MyFlag1||MyFlag2", &ok), -1); + QCOMPARE(ok, false); + + // Test empty string + QTest::ignoreMessage(QtWarningMsg, "QMetaEnum::keysToValue: empty keys string."); + QCOMPARE(mf.keysToValue("", &ok), -1); + QCOMPARE(ok, false); } void tst_QMetaObject::propertyNotify() |