diff options
author | Rohan McGovern <rohan.mcgovern@nokia.com> | 2012-02-14 02:55:49 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-23 11:22:34 (GMT) |
commit | 1d9c7af9fb8391babe6cab70692c43d8f123d047 (patch) | |
tree | 03823542f15df060e7d6287c3797de62a6eca0cb | |
parent | e7320d22ec04c6d14a38b2bc4172d7c0823f88b5 (diff) | |
download | Qt-1d9c7af9fb8391babe6cab70692c43d8f123d047.zip Qt-1d9c7af9fb8391babe6cab70692c43d8f123d047.tar.gz Qt-1d9c7af9fb8391babe6cab70692c43d8f123d047.tar.bz2 |
Stabilize tst_qdbusabstractinterface and make it XFAIL
This test was written incorrectly in a way which happened to allow it to
pass most of the time (but not all the time).
Reset the state of test objects between each test function, and mark the
broken functions with QEXPECT_FAIL and a link to a task.
Replace the unusual WaitForPinger construct with the usual
QTRY_VERIFY/QTRY_COMPARE method of verifying asynchronous operations.
(cherry picked from commit e88f9a92b7ab05ea9bc25083de7dee1b67dd673e)
Task-number: QTBUG-24262
Change-Id: I7a1f265695c15c0f7b1867a8608827c951a6e3b9
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index 84d2051..5ba581e 100644 --- a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -46,6 +46,8 @@ #include <QtDBus> +#include "../../shared/util.h" + #include "interface.h" #include "pinger.h" @@ -89,7 +91,9 @@ public: private slots: void initTestCase(); - void cleanupTestCase(); + + void init(); + void cleanup(); void makeVoidCall(); void makeStringCall(); @@ -194,39 +198,6 @@ private: QProcess proc; }; -class WaitForQPinger: public QObject -{ - Q_OBJECT -public: - WaitForQPinger(); - bool ok(); -public Q_SLOTS: - void ownerChange(const QString &name) - { - if (name == serviceName) - loop.quit(); - } - -private: - QEventLoop loop; -}; - -WaitForQPinger::WaitForQPinger() -{ - QDBusConnection con = QDBusConnection::sessionBus(); - if (!ok()) { - connect(con.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), - SLOT(ownerChange(QString))); - QTimer::singleShot(2000, &loop, SLOT(quit())); - loop.exec(); - } -} - -bool WaitForQPinger::ok() -{ - return QDBusConnection::sessionBus().isConnected() && - QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName); -} tst_QDBusAbstractInterface::tst_QDBusAbstractInterface() { @@ -244,6 +215,16 @@ void tst_QDBusAbstractInterface::initTestCase() QDBusConnection con = QDBusConnection::sessionBus(); QVERIFY(con.isConnected()); con.registerObject("/", &targetObj, QDBusConnection::ExportScriptableContents); +} + +void tst_QDBusAbstractInterface::init() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + + // verify service isn't registered by something else + // (e.g. a left over qpinger from a previous test run) + QVERIFY(!con.interface()->isServiceRegistered(serviceName)); // start peer server #ifdef Q_OS_WIN @@ -253,9 +234,8 @@ void tst_QDBusAbstractInterface::initTestCase() #endif QVERIFY(proc.waitForStarted()); - WaitForQPinger w; - QVERIFY(w.ok()); - //QTest::qWait(2000); + // verify service is now registered + QTRY_VERIFY(con.interface()->isServiceRegistered(serviceName)); // get peer server address QDBusMessage req = QDBusMessage::createMethodCall(serviceName, objectPath, interfaceName, "address"); @@ -273,10 +253,24 @@ void tst_QDBusAbstractInterface::initTestCase() QVERIFY(rpl2.arguments().at(0).toBool()); } -void tst_QDBusAbstractInterface::cleanupTestCase() +void tst_QDBusAbstractInterface::cleanup() { - proc.close(); - proc.kill(); + QDBusConnection::disconnectFromPeer("peer"); + + // Kill peer, resetting the object exported by a separate process + proc.terminate(); + QVERIFY(proc.waitForFinished() || proc.state() == QProcess::NotRunning); + + // Reset the object exported by this process + targetObj.m_stringProp = QString(); + targetObj.m_variantProp = QDBusVariant(); + targetObj.m_complexProp = RegisteredType(); + + // Wait until the service is certainly not registered + QDBusConnection con = QDBusConnection::sessionBus(); + if (con.isConnected()) { + QTRY_VERIFY(!con.interface()->isServiceRegistered(serviceName)); + } } void tst_QDBusAbstractInterface::makeVoidCall() @@ -635,6 +629,7 @@ void tst_QDBusAbstractInterface::stringPropWritePeer() QString expectedValue = "This is a value"; QVERIFY(p->setProperty("stringProp", expectedValue)); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_stringProp, expectedValue); } @@ -660,6 +655,7 @@ void tst_QDBusAbstractInterface::variantPropWritePeer() QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47)); QVERIFY(p->setProperty("variantProp", qVariantFromValue(expectedValue))); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant()); } @@ -683,6 +679,7 @@ void tst_QDBusAbstractInterface::complexPropWritePeer() RegisteredType expectedValue = RegisteredType("This is a value"); QVERIFY(p->setProperty("complexProp", qVariantFromValue(expectedValue))); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_complexProp, expectedValue); } @@ -762,6 +759,7 @@ void tst_QDBusAbstractInterface::stringPropDirectWritePeer() QString expectedValue = "This is a value"; p->setStringProp(expectedValue); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_stringProp, expectedValue); } @@ -783,6 +781,7 @@ void tst_QDBusAbstractInterface::variantPropDirectWritePeer() QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47)); p->setVariantProp(expectedValue); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_variantProp.variant().userType(), expectedValue.variant().userType()); QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant()); } @@ -805,6 +804,7 @@ void tst_QDBusAbstractInterface::complexPropDirectWritePeer() RegisteredType expectedValue = RegisteredType("This is a value"); p->setComplexProp(expectedValue); + QEXPECT_FAIL("", "QTBUG-24262 peer tests are broken", Abort); QCOMPARE(targetObj.m_complexProp, expectedValue); } |