Skip to content

Commit

Permalink
tst_QDialogButtonBox: Port away from QAbstractButton::animateClick()
Browse files Browse the repository at this point in the history
Use QAbstractButton::click(). Refactor and polish the tests
to use QTRY_VERIFY() instead of qWait(), speeding them up.

Pick-to: 5.15
Task-number: QTBUG-81845
Change-Id: I119bede8143ec1db5f5250517dee38b576d5a8d2
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
FriedemannKleint committed Apr 29, 2020
1 parent 05a38c0 commit 512be78
Showing 1 changed file with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,29 +599,28 @@ void tst_QDialogButtonBox::testSignals_data()
void tst_QDialogButtonBox::testSignals()
{
QFETCH(QDialogButtonBox::ButtonRole, buttonToClick);
QFETCH(int, clicked2Count);
QDialogButtonBox buttonBox;
qRegisterMetaType<QAbstractButton *>("QAbstractButton*");
QSignalSpy clicked2(&buttonBox, SIGNAL(clicked(QAbstractButton*)));
QSignalSpy accept(&buttonBox, SIGNAL(accepted()));
QSignalSpy reject(&buttonBox, SIGNAL(rejected()));
QSignalSpy helpRequested(&buttonBox, SIGNAL(helpRequested()));
QSignalSpy clicked2(&buttonBox, &QDialogButtonBox::clicked);
QSignalSpy accept(&buttonBox, &QDialogButtonBox::accepted);
QSignalSpy reject(&buttonBox, &QDialogButtonBox::rejected);
QSignalSpy helpRequested(&buttonBox, &QDialogButtonBox::helpRequested);

QPushButton *clickMe = 0;
QAbstractButton *clickMe = nullptr;
for (int i = QDialogButtonBox::AcceptRole; i < QDialogButtonBox::NRoles; ++i) {
QPushButton *button = buttonBox.addButton(QString::number(i),
QDialogButtonBox::ButtonRole(i));
auto button = buttonBox.addButton(QString::number(i),
QDialogButtonBox::ButtonRole(i));

if (i == buttonToClick)
clickMe = button;
}
if (clickMe) {
clickMe->animateClick(0);
QTest::qWait(100);
}
if (clickMe)
clickMe->click();

QTEST(clicked2.count(), "clicked2Count");
QTRY_COMPARE(clicked2.count(), clicked2Count);
if (clicked2.count() > 0)
QCOMPARE(qvariant_cast<QAbstractButton *>(clicked2.at(0).at(0)), (QAbstractButton *)clickMe);
QCOMPARE(qvariant_cast<QAbstractButton *>(clicked2.at(0).at(0)), clickMe);

QTEST(accept.count(), "acceptCount");
QTEST(reject.count(), "rejectCount");
Expand All @@ -630,47 +629,46 @@ void tst_QDialogButtonBox::testSignals()

void tst_QDialogButtonBox::testSignalOrder()
{
const qint64 longLongZero = 0;
buttonClicked1TimeStamp = acceptTimeStamp
= rejectTimeStamp = helpRequestedTimeStamp = timeStamp = 0;
= rejectTimeStamp = helpRequestedTimeStamp = timeStamp = 0LL;
QDialogButtonBox buttonBox;
connect(&buttonBox, SIGNAL(clicked(QAbstractButton*)),
this, SLOT(buttonClicked1(QAbstractButton*)));
connect(&buttonBox, SIGNAL(accepted()), this, SLOT(acceptClicked()));
connect(&buttonBox, SIGNAL(rejected()), this, SLOT(rejectClicked()));
connect(&buttonBox, SIGNAL(helpRequested()), this, SLOT(helpRequestedClicked()));
connect(&buttonBox, &QDialogButtonBox::clicked,
this, &tst_QDialogButtonBox::buttonClicked1);
connect(&buttonBox, &QDialogButtonBox::accepted, this, &tst_QDialogButtonBox::acceptClicked);
connect(&buttonBox, &QDialogButtonBox::rejected, this, &tst_QDialogButtonBox::rejectClicked);
connect(&buttonBox, &QDialogButtonBox::helpRequested, this, &tst_QDialogButtonBox::helpRequestedClicked);

QPushButton *acceptButton = buttonBox.addButton("OK", QDialogButtonBox::AcceptRole);
QPushButton *rejectButton = buttonBox.addButton("Cancel", QDialogButtonBox::RejectRole);
QPushButton *actionButton = buttonBox.addButton("Action This", QDialogButtonBox::ActionRole);
QPushButton *helpButton = buttonBox.addButton("Help Me!", QDialogButtonBox::HelpRole);

// Try accept
acceptButton->animateClick(0);
QTest::qWait(100);
QCOMPARE(rejectTimeStamp, longLongZero);
QCOMPARE(helpRequestedTimeStamp, longLongZero);
acceptButton->click();
QTRY_VERIFY(acceptTimeStamp > 0LL);
QCOMPARE(rejectTimeStamp, 0LL);
QCOMPARE(helpRequestedTimeStamp, 0LL);

QVERIFY(buttonClicked1TimeStamp < acceptTimeStamp);
acceptTimeStamp = 0;

rejectButton->animateClick(0);
QTest::qWait(100);
QCOMPARE(acceptTimeStamp, longLongZero);
QCOMPARE(helpRequestedTimeStamp, longLongZero);
rejectButton->click();
QTRY_VERIFY(rejectTimeStamp > 0LL);
QCOMPARE(acceptTimeStamp, 0LL);
QCOMPARE(helpRequestedTimeStamp, 0LL);
QVERIFY(buttonClicked1TimeStamp < rejectTimeStamp);

rejectTimeStamp = 0;
actionButton->animateClick(0);
QTest::qWait(100);
QCOMPARE(acceptTimeStamp, longLongZero);
QCOMPARE(rejectTimeStamp, longLongZero);
QCOMPARE(helpRequestedTimeStamp, longLongZero);

helpButton->animateClick(0);
actionButton->click();
QTest::qWait(100);
QCOMPARE(acceptTimeStamp, longLongZero);
QCOMPARE(rejectTimeStamp, longLongZero);
QCOMPARE(acceptTimeStamp, 0LL);
QCOMPARE(rejectTimeStamp, 0LL);
QCOMPARE(helpRequestedTimeStamp, 0LL);

helpButton->click();
QTRY_VERIFY(helpRequestedTimeStamp > 0LL);
QCOMPARE(acceptTimeStamp, 0LL);
QCOMPARE(rejectTimeStamp, 0LL);
QVERIFY(buttonClicked1TimeStamp < helpRequestedTimeStamp);
}

Expand Down Expand Up @@ -774,13 +772,13 @@ void tst_QDialogButtonBox::testRemove()
{
// Make sure that removing a button and clicking it, doesn't trigger any latent signals
QDialogButtonBox buttonBox;
QSignalSpy clicked(&buttonBox, SIGNAL(clicked(QAbstractButton*)));
QSignalSpy clicked(&buttonBox, &QDialogButtonBox::clicked);

QAbstractButton *button = buttonBox.addButton(QDialogButtonBox::Ok);

buttonBox.removeButton(button);

button->animateClick(0);
button->click();
QTest::qWait(100);
QCOMPARE(clicked.count(), 0);
delete button;
Expand Down Expand Up @@ -833,7 +831,7 @@ void tst_QDialogButtonBox::task191642_default()

QDialog dlg;
QPushButton *def = new QPushButton(&dlg);
QSignalSpy clicked(def, SIGNAL(clicked(bool)));
QSignalSpy clicked(def, &QPushButton::clicked);
def->setDefault(true);
QDialogButtonBox *bb = new QDialogButtonBox(&dlg);
bb->addButton(QDialogButtonBox::Ok);
Expand Down

0 comments on commit 512be78

Please sign in to comment.