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.

Task-number: QTBUG-24262
Change-Id: I82d09002307c0b500bf60cd5b583674321b37609
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Rohan McGovern 2012-02-14 12:55:49 +10:00 committed by Qt by Nokia
parent 4dabe78387
commit e88f9a92b7

View File

@ -89,7 +89,9 @@ public:
private slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
void makeVoidCall();
void makeStringCall();
@ -194,39 +196,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 +213,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 +232,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 +251,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 +627,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 +653,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 +677,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 +757,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 +779,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 +802,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);
}