From 6d51090572d843d781376d0128dddb3c9a0e307c Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Thu, 28 Dec 2017 13:43:03 +0200 Subject: Fix TestWebChannel::testAsyncObject If signal is emitted directly, QSignalSpy::wait() is called too late. In that case the correct information about emitted signal can be checked with QSignalSpy::count(). Task-number: QTBUG-63152 Change-Id: I0c3da52ab17f9138ad1a7a17f5065b8a87911b8f (cherry picked from commit d2f9396f048ef8fdd494626d92b3d7106fb10304) Reviewed-by: Jani Heikkinen --- tests/auto/webchannel/tst_webchannel.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/auto/webchannel') diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index f214b7e..4309647 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -770,6 +770,11 @@ void TestWebChannel::testInfiniteRecursion() void TestWebChannel::testAsyncObject() { + auto waitForSignal = [] (QSignalSpy& spy) { + for (int i=0; (i<5) && (spy.count() == 0); i++) + spy.wait(1000); + }; + QWebChannel channel; channel.connectTo(m_dummyTransport); @@ -788,7 +793,8 @@ void TestWebChannel::testAsyncObject() { QSignalSpy spy(&obj, &TestObject::propChanged); channel.d_func()->publisher->invokeMethod(&obj, method, args); - QVERIFY(spy.wait()); + waitForSignal(spy); + QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString()); } @@ -804,10 +810,13 @@ void TestWebChannel::testAsyncObject() { QSignalSpy spy(&obj, &TestObject::replay); QMetaObject::invokeMethod(&obj, "fire"); - QVERIFY(spy.wait()); + waitForSignal(spy); + QCOMPARE(spy.count(), 1); channel.deregisterObject(&obj); QMetaObject::invokeMethod(&obj, "fire"); - QVERIFY(spy.wait()); + spy.takeFirst(); + waitForSignal(spy); + QCOMPARE(spy.count(), 1); } thread.quit(); -- cgit v1.2.1 From 2661593df95b8a5a56af0a8fd22af5be7f7ea8fb Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Fri, 29 Dec 2017 09:51:58 +0200 Subject: Clean up TestWebChannel::testAsyncObject Task-number: QTBUG-63152 Change-Id: I22df2328f0ab6d2a2d12458dbeaec68bfbe36985 (cherry picked from commit 5a9dd81f260f320b5af108c1a6b3d0b82a04f15d) Reviewed-by: Jani Heikkinen --- tests/auto/webchannel/tst_webchannel.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'tests/auto/webchannel') diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 4309647..a44220f 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -770,11 +770,6 @@ void TestWebChannel::testInfiniteRecursion() void TestWebChannel::testAsyncObject() { - auto waitForSignal = [] (QSignalSpy& spy) { - for (int i=0; (i<5) && (spy.count() == 0); i++) - spy.wait(1000); - }; - QWebChannel channel; channel.connectTo(m_dummyTransport); @@ -793,8 +788,7 @@ void TestWebChannel::testAsyncObject() { QSignalSpy spy(&obj, &TestObject::propChanged); channel.d_func()->publisher->invokeMethod(&obj, method, args); - waitForSignal(spy); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString()); } @@ -810,13 +804,10 @@ void TestWebChannel::testAsyncObject() { QSignalSpy spy(&obj, &TestObject::replay); QMetaObject::invokeMethod(&obj, "fire"); - waitForSignal(spy); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); channel.deregisterObject(&obj); QMetaObject::invokeMethod(&obj, "fire"); - spy.takeFirst(); - waitForSignal(spy); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 2); } thread.quit(); -- cgit v1.2.1