tst_QMessageBox::staticSourceCompat(): improve diagnostic output
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 Pick-to: 6.6 6.5 Change-Id: I23e766d5026cff3e4775db56e58f808809709e4c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit fd710fbba3d24f6192625f586eea57309630f8ac) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5491198cbd
commit
16ab2eba72
@ -472,6 +472,12 @@ void tst_QMessageBox::staticSourceCompat()
|
|||||||
// source compat tests for < 4.2
|
// source compat tests for < 4.2
|
||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
|
#define COMPARE(real, exp) do {\
|
||||||
|
const auto pressed = static_cast<QMessageBox::StandardButton>(real);\
|
||||||
|
const auto expected = static_cast<QMessageBox::StandardButton>(exp);\
|
||||||
|
if (!QTest::qCompare(pressed, expected, #real, #exp, __FILE__, __LINE__)) \
|
||||||
|
return; } while (false)
|
||||||
|
|
||||||
ExecCloseHelper closeHelper;
|
ExecCloseHelper closeHelper;
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
|
||||||
@ -482,37 +488,38 @@ QT_WARNING_DISABLE_DEPRECATED
|
|||||||
|| dialogButtonBoxLayout == QDialogButtonBox::GnomeLayout)
|
|| dialogButtonBoxLayout == QDialogButtonBox::GnomeLayout)
|
||||||
expectedButton = int(QMessageBox::No);
|
expectedButton = int(QMessageBox::No);
|
||||||
}
|
}
|
||||||
QCOMPARE(ret, expectedButton);
|
COMPARE(ret, expectedButton);
|
||||||
QVERIFY(closeHelper.done());
|
QVERIFY(closeHelper.done());
|
||||||
|
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
|
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());
|
QVERIFY(closeHelper.done());
|
||||||
|
|
||||||
#if QT_DEPRECATED_SINCE(6, 2)
|
#if QT_DEPRECATED_SINCE(6, 2)
|
||||||
// The overloads below are valid only before 6.2
|
// The overloads below are valid only before 6.2
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
|
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());
|
QVERIFY(closeHelper.done());
|
||||||
|
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
|
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());
|
QVERIFY(closeHelper.done());
|
||||||
|
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
|
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());
|
QVERIFY(closeHelper.done());
|
||||||
|
|
||||||
// the button text versions
|
// the button text versions
|
||||||
closeHelper.start(Qt::Key_Enter);
|
closeHelper.start(Qt::Key_Enter);
|
||||||
ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
|
ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
|
||||||
QCOMPARE(ret, 1);
|
COMPARE(ret, 1);
|
||||||
QVERIFY(closeHelper.done());
|
QVERIFY(closeHelper.done());
|
||||||
#endif // QT_DEPRECATED_SINCE(6, 2)
|
#endif // QT_DEPRECATED_SINCE(6, 2)
|
||||||
|
#undef COMPARE
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user