diff options
author | Edward Welbourne <[email protected]> | 2025-06-06 13:34:30 +0200 |
---|---|---|
committer | Edward Welbourne <[email protected]> | 2025-06-30 21:40:41 +0200 |
commit | f4101d6a4c4e8279cea42729ce4fc7fb63af3ad7 (patch) | |
tree | f8324d1ce2ab908826585af1cd85dba1a8387ea5 /src/testlib | |
parent | 1654aa311d2030cdcd4101907108c47a5c95e618 (diff) |
Convert qtestlog.cpp to use QVariant::get_if<>(QVariant *)
Pick-to: 6.10 6.9
Change-Id: I30aefa3dafa0975e53f6a7fb253a37032bb9492a
Reviewed-by: Thiago Macieira <[email protected]>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestlog.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 982e7584643..8a94aa0e19f 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -190,8 +190,8 @@ namespace QTest { if (tp != type) return false; #if QT_CONFIG(regularexpression) - if (pattern.userType() == QMetaType::QRegularExpression) - return pattern.toRegularExpression().match(message).hasMatch(); + if (const auto *regex = get_if<QRegularExpression>(&pattern)) + return regex->match(message).hasMatch(); #endif return stringsMatch(pattern.toString(), message); } @@ -257,12 +257,12 @@ namespace QTest { // failOnWarning can be called multiple times per test function, so let // each call cause a failure if required. for (const auto &pattern : failOnWarningList) { - if (pattern.metaType() == QMetaType::fromType<QString>()) { - if (message != pattern.toString()) + if (const auto *text = get_if<QString>(&pattern)) { + if (message != *text) continue; #if QT_CONFIG(regularexpression) - } else if (pattern.metaType() == QMetaType::fromType<QRegularExpression>()) { - if (!message.contains(pattern.toRegularExpression())) + } else if (const auto *regex = get_if<QRegularExpression>(&pattern)) { + if (!message.contains(*regex)) continue; #endif } @@ -396,12 +396,11 @@ void QTestLog::printUnhandledIgnoreMessages() QString message; QTest::IgnoreResultList *list = QTest::ignoreResultList; while (list) { - if (list->pattern.userType() == QMetaType::QString) { - message = "Did not receive message: \"%1\""_L1.arg(list->pattern.toString()); + if (const auto *text = get_if<QString>(&list->pattern)) { + message = "Did not receive message: \"%1\""_L1.arg(*text); #if QT_CONFIG(regularexpression) - } else { - message = "Did not receive any message matching: \"%1\""_L1.arg( - list->pattern.toRegularExpression().pattern()); + } else if (const auto *regex = get_if<QRegularExpression>(&list->pattern)) { + message = "Did not receive any message matching: \"%1\""_L1.arg(regex->pattern()); #endif } for (auto &logger : QTest::loggers->allLoggers()) |