From 6180e496c2dcc6057826c039b67e8b2fd92fe1de Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Wed, 17 Aug 2022 16:06:54 +0200 Subject: tst_qmessagebox: port away from deprecated methods * Wrap some tests that specifically test deprecated APIs into #ifdefery * Refactor some tests to use available methods Task-number: QTBUG-104858 Change-Id: I03e318004ce1c2718ee574bf11e00df9bc04bcaa Reviewed-by: Volker Hilsheimer --- .../dialogs/qmessagebox/tst_qmessagebox.cpp | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'tests/auto/widgets/dialogs') diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 5dbb47ce59..ae73ec4d5d 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -416,6 +416,8 @@ QT_WARNING_DISABLE_DEPRECATED QCOMPARE(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)); @@ -448,22 +450,21 @@ QT_WARNING_DISABLE_DEPRECATED QCOMPARE(ret, 1); QVERIFY(closeHelper.done()); } +#endif // QT_DEPRECATED_SINCE(6, 2) QT_WARNING_POP } void tst_QMessageBox::instanceSourceCompat() { -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - QMessageBox mb("Application name here", - "Saving the file will overwrite the original file on the disk.\n" - "Do you really want to save?", - QMessageBox::Information, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No, - QMessageBox::Cancel | QMessageBox::Escape); - mb.setButtonText(QMessageBox::Yes, "Save"); - mb.setButtonText(QMessageBox::No, "Discard"); + QMessageBox mb(QMessageBox::Information, + "Application name here", + "Saving the file will overwrite the original file on the disk.\n" + "Do you really want to save?", + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + mb.setDefaultButton(QMessageBox::Yes); + mb.setEscapeButton(QMessageBox::Cancel); + mb.button(QMessageBox::Yes)->setText("Save"); + mb.button(QMessageBox::No)->setText("Discard"); mb.addButton("&Revert", QMessageBox::RejectRole); mb.addButton("&Zoo", QMessageBox::ActionRole); @@ -479,7 +480,6 @@ QT_WARNING_DISABLE_DEPRECATED closeHelper.start(QKeyCombination(Qt::ALT | Qt::Key_Z).toCombined(), &mb); QCOMPARE(mb.exec(), 1); #endif -QT_WARNING_POP } void tst_QMessageBox::detailsText() @@ -557,6 +557,7 @@ void tst_QMessageBox::incorrectDefaultButton() QMessageBox::question(nullptr, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save); QVERIFY(closeHelper.done()); +#if QT_DEPRECATED_SINCE(6, 2) closeHelper.start(Qt::Key_Escape); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); @@ -566,6 +567,7 @@ QT_WARNING_DISABLE_DEPRECATED QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok); QT_WARNING_POP QVERIFY(closeHelper.done()); +#endif } void tst_QMessageBox::updateSize() -- cgit v1.2.3