From 3d6f0b8671622149348ebbedd9b986eb7d91636b Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Mon, 18 Dec 2023 18:57:01 +0100 Subject: [PATCH] tst_QMessageBox::staticSourceCompat(): improve diagnostic output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test function casts QMessageBox::StandardButton variables to integers, to pass them as arguments and verify expected buttons. In case of a test failure, this makes it hard to figure out, why a test was failing. Add a local macro to cast int values back to the enum before calling qCompare(). That way the enum keys will be displayed in the logs. Task-number: QTBUG-118489 Change-Id: I23e766d5026cff3e4775db56e58f808809709e4c Reviewed-by: Tor Arne Vestbø (cherry picked from commit fd710fbba3d24f6192625f586eea57309630f8ac) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 16ab2eba720b1428e34c76381a0f09b6b70bf9e3) (cherry picked from commit 145e5d57879158eb5af5689a5182a18b69865e01) --- .../dialogs/qmessagebox/tst_qmessagebox.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 661c007fc06..02e3cfd05a0 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -470,6 +470,12 @@ void tst_QMessageBox::staticSourceCompat() // source compat tests for < 4.2 QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED +#define COMPARE(real, exp) do {\ + const auto pressed = static_cast(real);\ + const auto expected = static_cast(exp);\ + if (!QTest::qCompare(pressed, expected, #real, #exp, __FILE__, __LINE__)) \ + return; } while (false) + ExecCloseHelper closeHelper; closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No); @@ -480,35 +486,35 @@ QT_WARNING_DISABLE_DEPRECATED || dialogButtonBoxLayout == QDialogButtonBox::GnomeLayout) expectedButton = int(QMessageBox::No); } - QCOMPARE(ret, expectedButton); + COMPARE(ret, expectedButton); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); - QCOMPARE(ret, int(QMessageBox::Yes)); + COMPARE(ret, int(QMessageBox::Yes)); QVERIFY(closeHelper.done()); #if QT_DEPRECATED_SINCE(6, 2) // The overloads below are valid only before 6.2 closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default); - QCOMPARE(ret, int(QMessageBox::No)); + COMPARE(ret, int(QMessageBox::No)); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape); - QCOMPARE(ret, int(QMessageBox::Yes)); + COMPARE(ret, int(QMessageBox::Yes)); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default); - QCOMPARE(ret, int(QMessageBox::No)); + COMPARE(ret, int(QMessageBox::No)); QVERIFY(closeHelper.done()); // the button text versions closeHelper.start(Qt::Key_Enter); ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1); - QCOMPARE(ret, 1); + COMPARE(ret, 1); QVERIFY(closeHelper.done()); if (0) { // don't run these tests since the dialog won't close! @@ -523,6 +529,7 @@ QT_WARNING_DISABLE_DEPRECATED QVERIFY(closeHelper.done()); } #endif // QT_DEPRECATED_SINCE(6, 2) +#undef COMPARE QT_WARNING_POP }