From 46ef4c8b869698e34ca5e9bd6081dc21435dd74b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Aug 2024 21:19:38 -0700 Subject: [PATCH] tst_moc: fix the order of arguments in QCOMPARE in checkEnum QCOMPARE is (actual, expected). Take the opportunity to test out-of-range returns from QMetaEnum too. Change-Id: I8a96935cf6c742259c9dfffd17e9575a6d4cf90a Reviewed-by: Fabian Kosmale (cherry picked from commit e3e44e2294c06f243838dfa28ec4f350c5e6ffbb) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/tools/moc/tst_moc.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 4fcb44f00c6..28485721e61 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -4130,16 +4130,19 @@ void tst_Moc::optionsFileError() } static void checkEnum(const QMetaEnum &enumerator, const QByteArray &name, - const QList> &keys, + const QList> &keys, const QMetaType underlyingType = QMetaType::fromType()) { - QCOMPARE(name, QByteArray{enumerator.name()}); - QCOMPARE(keys.size(), enumerator.keyCount()); - QCOMPARE(underlyingType, enumerator.metaType().underlyingType()); + QCOMPARE(enumerator.name(), QByteArrayView{name}); + QCOMPARE(enumerator.keyCount(), keys.size()); + QCOMPARE(enumerator.metaType().underlyingType(), underlyingType); for (int i = 0; i < enumerator.keyCount(); ++i) { - QCOMPARE(keys[i].first, QByteArray{enumerator.key(i)}); - QCOMPARE(keys[i].second, enumerator.value(i)); + QCOMPARE(QByteArray{enumerator.key(i)}, keys[i].first); + QCOMPARE(enumerator.value(i), keys[i].second); } + // out of range + QVERIFY(!enumerator.key(keys.size())); + QCOMPARE(enumerator.value(keys.size()), -1); } class EnumFromNamespaceClass : public QObject