[telepathy-qt4/master] Connection: Make constructor protected and added public create method that returns a SharedPtr.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Mar 31 11:40:10 PDT 2009
---
TelepathyQt4/Client/account.cpp | 4 +-
TelepathyQt4/Client/connection.cpp | 24 ++++++++++-----
TelepathyQt4/Client/connection.h | 16 +++++-----
TelepathyQt4/Client/pending-connection.cpp | 17 +++++------
TelepathyQt4/Client/pending-connection.h | 4 +-
tests/dbus/chan-basics.cpp | 15 ++++------
tests/dbus/chan-group.cpp | 15 ++++------
tests/dbus/conn-basics.cpp | 15 ++++------
tests/dbus/conn-requests.cpp | 11 ++----
tests/dbus/conn-roster.cpp | 11 ++----
tests/dbus/contacts.cpp | 29 ++++++++----------
tests/dbus/handles.cpp | 15 ++++------
tests/dbus/streamed-media-chan.cpp | 15 ++++------
tests/dbus/text-chan.cpp | 15 ++++------
tests/pinocchio/conn-basics.cpp | 44 ++++++++++++---------------
tests/pinocchio/handles.cpp | 33 ++++++++------------
16 files changed, 126 insertions(+), 157 deletions(-)
diff --git a/TelepathyQt4/Client/account.cpp b/TelepathyQt4/Client/account.cpp
index 50990fe..b03bd25 100644
--- a/TelepathyQt4/Client/account.cpp
+++ b/TelepathyQt4/Client/account.cpp
@@ -531,8 +531,8 @@ ConnectionPtr Account::connection() const
QString objectPath = mPriv->connectionObjectPath;
QString busName = objectPath.mid(1).replace('/', '.');
if (!mPriv->connection) {
- mPriv->connection = ConnectionPtr(
- new Connection(dbusConnection(), busName, objectPath));
+ mPriv->connection = Connection::create(dbusConnection(),
+ busName, objectPath);
}
return mPriv->connection;
}
diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 36d8a25..081c027 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -453,19 +453,29 @@ const Feature Connection::FeatureSelfContact = Feature(Connection::staticMetaObj
const Feature Connection::FeatureSimplePresence = Feature(Connection::staticMetaObject.className(), 2);
const Feature Connection::FeatureRoster = Feature(Connection::staticMetaObject.className(), 3);
+ConnectionPtr Connection::create(const QString &busName,
+ const QString &objectPath)
+{
+ return ConnectionPtr(new Connection(busName, objectPath));
+}
+
+ConnectionPtr Connection::create(const QDBusConnection &bus,
+ const QString &busName, const QString &objectPath)
+{
+ return ConnectionPtr(new Connection(bus, busName, objectPath));
+}
+
/**
* Construct a new Connection object.
*
* \param busName The connection's well-known or unique bus name
* (sometimes called a "service name")
* \param objectPath The connection's object path
- * \param parent Object parent
*/
Connection::Connection(const QString &busName,
- const QString &objectPath,
- QObject *parent)
+ const QString &objectPath)
: StatefulDBusProxy(QDBusConnection::sessionBus(),
- busName, objectPath, parent),
+ busName, objectPath),
OptionalInterfaceFactory<Connection>(this),
ReadyObject(this, FeatureCore),
mPriv(new Private(this))
@@ -479,13 +489,11 @@ Connection::Connection(const QString &busName,
* \param busName The connection's well-known or unique bus name
* (sometimes called a "service name")
* \param objectPath The connection's object path
- * \param parent Object parent
*/
Connection::Connection(const QDBusConnection &bus,
const QString &busName,
- const QString &objectPath,
- QObject *parent)
- : StatefulDBusProxy(bus, busName, objectPath, parent),
+ const QString &objectPath)
+ : StatefulDBusProxy(bus, busName, objectPath),
OptionalInterfaceFactory<Connection>(this),
ReadyObject(this, FeatureCore),
mPriv(new Private(this))
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index e24a660..5514010 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -80,14 +80,10 @@ public:
StatusUnknown = 0xFFFFFFFF
};
- Connection(const QString &busName,
- const QString &objectPath,
- QObject *parent = 0);
-
- Connection(const QDBusConnection &bus,
- const QString &busName,
- const QString &objectPath,
- QObject *parent = 0);
+ static ConnectionPtr create(const QString &busName,
+ const QString &objectPath);
+ static ConnectionPtr create(const QDBusConnection &bus,
+ const QString &busName, const QString &objectPath);
~Connection();
@@ -182,6 +178,10 @@ Q_SIGNALS:
void selfContactChanged();
protected:
+ Connection(const QString &busName, const QString &objectPath);
+ Connection(const QDBusConnection &bus, const QString &busName,
+ const QString &objectPath);
+
ConnectionInterface *baseInterface() const;
private Q_SLOTS:
diff --git a/TelepathyQt4/Client/pending-connection.cpp b/TelepathyQt4/Client/pending-connection.cpp
index b0c51ba..203356a 100644
--- a/TelepathyQt4/Client/pending-connection.cpp
+++ b/TelepathyQt4/Client/pending-connection.cpp
@@ -50,12 +50,12 @@ namespace Client
struct PendingConnection::Private
{
- Private(ConnectionManager *manager) :
+ Private(const ConnectionManagerPtr &manager) :
manager(manager)
{
}
- ConnectionManager *manager;
+ ConnectionManagerPtr manager;
ConnectionPtr connection;
QString busName;
QDBusObjectPath objectPath;
@@ -78,9 +78,9 @@ struct PendingConnection::Private
* \param protocol Name of the protocol to create the connection for.
* \param parameters Connection parameters.
*/
-PendingConnection::PendingConnection(ConnectionManager *manager,
+PendingConnection::PendingConnection(const ConnectionManagerPtr &manager,
const QString &protocol, const QVariantMap ¶meters)
- : PendingOperation(manager),
+ : PendingOperation(manager.data()),
mPriv(new Private(manager))
{
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
@@ -104,9 +104,9 @@ PendingConnection::~PendingConnection()
*
* \return Connection Manager object.
*/
-ConnectionManager *PendingConnection::manager() const
+ConnectionManagerPtr PendingConnection::manager() const
{
- return qobject_cast<ConnectionManager *>(parent());
+ return mPriv->manager;
}
/**
@@ -125,9 +125,8 @@ ConnectionPtr PendingConnection::connection() const
}
if (!mPriv->connection) {
- mPriv->connection = ConnectionPtr(
- new Connection(mPriv->manager->dbusConnection(),
- mPriv->busName, mPriv->objectPath.path()));
+ mPriv->connection = Connection::create(mPriv->manager->dbusConnection(),
+ mPriv->busName, mPriv->objectPath.path());
}
return mPriv->connection;
diff --git a/TelepathyQt4/Client/pending-connection.h b/TelepathyQt4/Client/pending-connection.h
index eba1df7..8a8ec34 100644
--- a/TelepathyQt4/Client/pending-connection.h
+++ b/TelepathyQt4/Client/pending-connection.h
@@ -48,7 +48,7 @@ class PendingConnection : public PendingOperation
public:
~PendingConnection();
- ConnectionManager *manager() const;
+ ConnectionManagerPtr manager() const;
ConnectionPtr connection() const;
@@ -61,7 +61,7 @@ private Q_SLOTS:
private:
Q_DISABLE_COPY(PendingConnection);
- PendingConnection(ConnectionManager *manager,
+ PendingConnection(const ConnectionManagerPtr &manager,
const QString &protocol, const QVariantMap ¶meters);
struct Private;
diff --git a/tests/dbus/chan-basics.cpp b/tests/dbus/chan-basics.cpp
index 1020a8e..7a2aa4a 100644
--- a/tests/dbus/chan-basics.cpp
+++ b/tests/dbus/chan-basics.cpp
@@ -50,7 +50,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
ExampleEcho2Connection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
ChannelPtr mChan;
QString mChanObjectPath;
uint mHandle;
@@ -198,7 +198,7 @@ void TestChanBasics::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -211,11 +211,11 @@ void TestChanBasics::initTestCase()
QCOMPARE(mConn->isReady(features), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectConnReady(uint, uint))));
@@ -341,7 +341,7 @@ void TestChanBasics::cleanup()
void TestChanBasics::cleanupTestCase()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -349,15 +349,12 @@ void TestChanBasics::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mConnService != 0) {
diff --git a/tests/dbus/chan-group.cpp b/tests/dbus/chan-group.cpp
index 9083d9f..54cefe4 100644
--- a/tests/dbus/chan-group.cpp
+++ b/tests/dbus/chan-group.cpp
@@ -68,7 +68,7 @@ private:
QString mConnName, mConnPath;
ExampleCSHConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
ChannelPtr mChan;
QString mChanObjectPath;
uint mRoomNumber;
@@ -306,7 +306,7 @@ void TestChanGroup::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -318,11 +318,11 @@ void TestChanGroup::initTestCase()
QCOMPARE(mConn->isReady(), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectConnReady(uint, uint))));
@@ -570,7 +570,7 @@ void TestChanGroup::cleanup()
void TestChanGroup::cleanupTestCase()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -578,15 +578,12 @@ void TestChanGroup::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mConnService != 0) {
diff --git a/tests/dbus/conn-basics.cpp b/tests/dbus/conn-basics.cpp
index b81d091..a6c6b1a 100644
--- a/tests/dbus/conn-basics.cpp
+++ b/tests/dbus/conn-basics.cpp
@@ -43,7 +43,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
ContactsConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
};
void TestConnBasics::expectConnReady(uint newStatus, uint newStatusReason)
@@ -120,7 +120,7 @@ void TestConnBasics::init()
{
initImpl();
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -134,11 +134,11 @@ void TestConnBasics::init()
qDebug() << "connection is now ready";
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectConnReady(uint, uint))));
@@ -161,7 +161,7 @@ void TestConnBasics::testSimplePresence()
void TestConnBasics::cleanup()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -169,15 +169,12 @@ void TestConnBasics::cleanup()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
cleanupImpl();
diff --git a/tests/dbus/conn-requests.cpp b/tests/dbus/conn-requests.cpp
index a9f2dfb..6643c27 100644
--- a/tests/dbus/conn-requests.cpp
+++ b/tests/dbus/conn-requests.cpp
@@ -49,7 +49,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
ExampleEcho2Connection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
QString mChanObjectPath;
uint mHandle;
};
@@ -173,7 +173,7 @@ void TestConnRequests::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
QVERIFY(connect(mConn->requestConnect(),
@@ -247,7 +247,7 @@ void TestConnRequests::cleanup()
void TestConnRequests::cleanupTestCase()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -255,15 +255,12 @@ void TestConnRequests::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mConnService != 0) {
diff --git a/tests/dbus/conn-roster.cpp b/tests/dbus/conn-roster.cpp
index 122ac2d..86e9afa 100644
--- a/tests/dbus/conn-roster.cpp
+++ b/tests/dbus/conn-roster.cpp
@@ -46,7 +46,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
ExampleContactListConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
QList<ContactPtr> mContacts;
};
@@ -125,7 +125,7 @@ void TestConnRoster::init()
{
initImpl();
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QVERIFY(connect(mConn->requestConnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -255,7 +255,7 @@ void TestConnRoster::testRoster()
void TestConnRoster::cleanup()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -263,15 +263,12 @@ void TestConnRoster::cleanup()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
cleanupImpl();
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index edc65c0..e077474 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -57,7 +57,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
ContactsConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
QList<ContactPtr> mContacts;
Telepathy::UIntList mInvalidHandles;
};
@@ -153,7 +153,7 @@ void TestContacts::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -166,11 +166,11 @@ void TestContacts::initTestCase()
QCOMPARE(mConn->isReady(features), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectConnReady(uint, uint))));
@@ -185,7 +185,7 @@ void TestContacts::init()
void TestContacts::testSupport()
{
- QCOMPARE(mConn->contactManager()->connection(), mConn);
+ QCOMPARE(mConn->contactManager()->connection(), mConn.data());
QVERIFY(!mConn->contactAttributeInterfaces().isEmpty());
@@ -314,7 +314,7 @@ void TestContacts::testForHandles()
saveContacts.clear();
mContacts.clear();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Unref the handles we created service-side
tp_handle_unref(serviceRepo, handles[0]);
@@ -400,7 +400,7 @@ void TestContacts::testForIdentifiers()
<< mContacts[2]->handle()[0];
mContacts.clear();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Check that their handles are in fact released
foreach (uint handle, saveHandles) {
@@ -517,7 +517,7 @@ void TestContacts::testFeatures()
contacts_connection_change_presences(mConnService, 2, handles.toVector().constData(),
latterStatuses, latterMessages);
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Check that the attributes were updated in the Contact objects
for (int i = 0; i < 3; i++) {
@@ -556,7 +556,7 @@ void TestContacts::testFeatures()
// Make the contacts go out of scope, starting releasing their handles, and finish that
mContacts.clear();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Unref the handles we created service-side
tp_handle_unref(serviceRepo, handles[0]);
@@ -608,7 +608,7 @@ void TestContacts::testFeaturesNotRequested()
// Make the contacts go out of scope, starting releasing their handles, and finish that
mContacts.clear();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Unref the handles we created service-side
tp_handle_unref(serviceRepo, handles[0]);
@@ -723,7 +723,7 @@ void TestContacts::testUpgrade()
saveContacts.clear();
mContacts.clear();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Unref the handles we created service-side
tp_handle_unref(serviceRepo, handles[0]);
@@ -754,7 +754,7 @@ void TestContacts::testSelfContactFallback()
QVERIFY(name != 0);
QVERIFY(connPath != 0);
- Connection *conn = new Connection(name, connPath);
+ ConnectionPtr conn = Connection::create(name, connPath);
g_free(name);
g_free(connPath);
@@ -802,14 +802,11 @@ void TestContacts::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *, QString, QString)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mConnService != 0) {
diff --git a/tests/dbus/handles.cpp b/tests/dbus/handles.cpp
index aa2304d..5df7fa8 100644
--- a/tests/dbus/handles.cpp
+++ b/tests/dbus/handles.cpp
@@ -45,7 +45,7 @@ private Q_SLOTS:
private:
QString mConnName, mConnPath;
SimpleConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
ReferencedHandles mHandles;
};
@@ -135,7 +135,7 @@ void TestHandles::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -147,11 +147,11 @@ void TestHandles::initTestCase()
QCOMPARE(mConn->isReady(), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectConnReady(uint, uint))));
@@ -199,7 +199,7 @@ void TestHandles::testRequestAndRelease()
// Start releasing the handles, RAII style, and complete the asynchronous process doing that
handles = ReferencedHandles();
mLoop->processEvents();
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
// Check that the handles have been released
for (int i = 0; i < 3; i++) {
@@ -223,14 +223,11 @@ void TestHandles::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)),
SLOT(expectConnInvalidated())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mConnService != 0) {
diff --git a/tests/dbus/streamed-media-chan.cpp b/tests/dbus/streamed-media-chan.cpp
index d523986..74ec755 100644
--- a/tests/dbus/streamed-media-chan.cpp
+++ b/tests/dbus/streamed-media-chan.cpp
@@ -61,7 +61,7 @@ private Q_SLOTS:
private:
ExampleCallableConnection *mConnService;
- Connection *mConn;
+ ConnectionPtr mConn;
QString mConnName;
QString mConnPath;
StreamedMediaChannelPtr mChan;
@@ -218,7 +218,7 @@ void TestStreamedMediaChan::onNewChannels(const Telepathy::ChannelDetailsList &c
if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA &&
!requested) {
- mChan = StreamedMediaChannelPtr(new StreamedMediaChannel(mConn,
+ mChan = StreamedMediaChannelPtr(new StreamedMediaChannel(mConn.data(),
details.channel.path(),
details.properties));
mLoop->exit(0);
@@ -258,7 +258,7 @@ void TestStreamedMediaChan::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
QVERIFY(connect(mConn->requestConnect(Connection::FeatureSelfContact),
@@ -552,7 +552,7 @@ void TestStreamedMediaChan::testOutgoingCallNoAnswer()
QCOMPARE(mLoop->exec(), 0);
/* After the initial flurry of D-Bus messages, alice still hasn't answered */
- processDBusQueue(mConn);
+ processDBusQueue(mConn.data());
QVERIFY(connect(mChan.data(),
SIGNAL(groupMembersChanged(
@@ -805,23 +805,20 @@ void TestStreamedMediaChan::cleanup()
void TestStreamedMediaChan::cleanupTestCase()
{
- if (mConn != 0) {
+ if (mConn) {
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
mLoop,
SLOT(quit())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
cleanupTestCaseImpl();
diff --git a/tests/dbus/text-chan.cpp b/tests/dbus/text-chan.cpp
index f7e2d06..233b9e8 100644
--- a/tests/dbus/text-chan.cpp
+++ b/tests/dbus/text-chan.cpp
@@ -77,7 +77,7 @@ private:
ExampleEchoChannel *mTextChanService;
ExampleEcho2Channel *mMessagesChanService;
- Connection *mConn;
+ ConnectionPtr mConn;
TextChannel *mChan;
QString mTextChanPath;
QString mMessagesChanPath;
@@ -145,7 +145,7 @@ void TestTextChan::initTestCase()
g_free(name);
g_free(connPath);
- mConn = new Connection(mConnName, mConnPath);
+ mConn = Connection::create(mConnName, mConnPath);
QCOMPARE(mConn->isReady(), false);
mConn->requestConnect();
@@ -412,14 +412,14 @@ void TestTextChan::commonTest(bool withMessages)
void TestTextChan::testMessages()
{
- mChan = new TextChannel(mConn, mMessagesChanPath, QVariantMap(), this);
+ mChan = new TextChannel(mConn.data(), mMessagesChanPath, QVariantMap(), this);
commonTest(true);
}
void TestTextChan::testLegacyText()
{
- mChan = new TextChannel(mConn, mTextChanPath, QVariantMap(), this);
+ mChan = new TextChannel(mConn.data(), mTextChanPath, QVariantMap(), this);
commonTest(false);
}
@@ -439,7 +439,7 @@ void TestTextChan::cleanup()
void TestTextChan::cleanupTestCase()
{
- if (mConn != 0) {
+ if (mConn) {
// Disconnect and wait for the readiness change
QVERIFY(connect(mConn->requestDisconnect(),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
@@ -447,16 +447,13 @@ void TestTextChan::cleanupTestCase()
QCOMPARE(mLoop->exec(), 0);
if (mConn->isValid()) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
mLoop,
SLOT(quit())));
QCOMPARE(mLoop->exec(), 0);
}
-
- delete mConn;
- mConn = 0;
}
if (mTextChanService != 0) {
diff --git a/tests/pinocchio/conn-basics.cpp b/tests/pinocchio/conn-basics.cpp
index 1a778c1..3712180 100644
--- a/tests/pinocchio/conn-basics.cpp
+++ b/tests/pinocchio/conn-basics.cpp
@@ -12,6 +12,7 @@
#include <tests/pinocchio/lib.h>
using Telepathy::Client::Connection;
+using Telepathy::Client::ConnectionPtr;
using Telepathy::Client::ConnectionManagerInterface;
using Telepathy::Client::DBus::PeerInterface;
using Telepathy::Client::DBus::PropertiesInterface;
@@ -25,7 +26,7 @@ private:
Telepathy::Client::ConnectionManagerInterface* mCM;
QString mConnBusName;
QString mConnObjectPath;
- Connection *mConn;
+ ConnectionPtr mConn;
protected Q_SLOTS:
void expectReady(uint, uint);
@@ -100,13 +101,12 @@ void TestConnBasics::init()
void TestConnBasics::testInitialIntrospection()
{
- mConn = new Connection(mConnBusName, mConnObjectPath);
+ mConn = Connection::create(mConnBusName, mConnObjectPath);
QCOMPARE(static_cast<uint>(mConn->status()),
static_cast<uint>(Connection::StatusUnknown));
- delete mConn;
- mConn = NULL;
+ mConn.reset();
}
@@ -135,7 +135,7 @@ void TestConnBasics::expectReady(uint newStatus, uint newStatusReason)
void TestConnBasics::testConnect()
{
- mConn = new Connection(mConnBusName, mConnObjectPath);
+ mConn = Connection::create(mConnBusName, mConnObjectPath);
QCOMPARE(mConn->isReady(), false);
QCOMPARE(static_cast<uint>(mConn->status()),
@@ -156,11 +156,11 @@ void TestConnBasics::testConnect()
QCOMPARE(mConn->isReady(), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectReady(uint, uint))));
@@ -200,14 +200,13 @@ void TestConnBasics::testConnect()
QCOMPARE(static_cast<uint>(mConn->statusReason()),
static_cast<uint>(Telepathy::ConnectionStatusReasonRequested));
- delete mConn;
- mConn = NULL;
+ mConn.reset();
}
void TestConnBasics::testAlreadyConnected()
{
- mConn = new Connection(mConnBusName, mConnObjectPath);
+ mConn = Connection::create(mConnBusName, mConnObjectPath);
qDebug() << "calling Connect()";
QVERIFY(connect(mConn->requestConnect(),
@@ -224,11 +223,11 @@ void TestConnBasics::testAlreadyConnected()
QCOMPARE(mConn->isReady(), true);
if (mConn->status() != Connection::StatusConnected) {
- QVERIFY(connect(mConn,
+ QVERIFY(connect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
SLOT(expectReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn,
+ QVERIFY(disconnect(mConn.data(),
SIGNAL(statusChanged(uint, uint)),
this,
SLOT(expectReady(uint, uint))));
@@ -236,14 +235,14 @@ void TestConnBasics::testAlreadyConnected()
}
// delete proxy, make a new one
- delete mConn;
- mConn = new Connection(mConnBusName, mConnObjectPath);
+ mConn.reset();
+ mConn = Connection::create(mConnBusName, mConnObjectPath);
// Wait for introspection to run (readiness changes to Full immediately)
- QVERIFY(connect(mConn, SIGNAL(statusChanged(uint, uint)),
+ QVERIFY(connect(mConn.data(), SIGNAL(statusChanged(uint, uint)),
this, SLOT(expectReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(mConn, SIGNAL(statusChanged(uint, uint)),
+ QVERIFY(disconnect(mConn.data(), SIGNAL(statusChanged(uint, uint)),
this, SLOT(expectReady(uint, uint))));
QVERIFY(connect(mConn->requestDisconnect(),
@@ -252,14 +251,13 @@ void TestConnBasics::testAlreadyConnected()
SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
- delete mConn;
- mConn = NULL;
+ mConn.reset();
}
void TestConnBasics::testInterfaceFactory()
{
- mConn = new Connection(QDBusConnection::sessionBus(),
+ mConn = Connection::create(QDBusConnection::sessionBus(),
mConnBusName, mConnObjectPath);
QCOMPARE(static_cast<uint>(mConn->status()),
@@ -277,8 +275,7 @@ void TestConnBasics::testInterfaceFactory()
notListed = mConn->optionalInterface<PeerInterface>(Connection::BypassInterfaceCheck);
QVERIFY(notListed != NULL);
- delete mConn;
- mConn = NULL;
+ mConn.reset();
}
@@ -290,14 +287,13 @@ void TestConnBasics::cleanup()
void TestConnBasics::testSpecifiedBus()
{
- mConn = new Connection(QDBusConnection::sessionBus(),
+ mConn = Connection::create(QDBusConnection::sessionBus(),
mConnBusName, mConnObjectPath);
QCOMPARE(static_cast<uint>(mConn->status()),
static_cast<uint>(Connection::StatusUnknown));
- delete mConn;
- mConn = NULL;
+ mConn.reset();
}
diff --git a/tests/pinocchio/handles.cpp b/tests/pinocchio/handles.cpp
index 5ce9700..711ad52 100644
--- a/tests/pinocchio/handles.cpp
+++ b/tests/pinocchio/handles.cpp
@@ -27,11 +27,11 @@ private:
ConnectionManagerInterface *mCM;
// Bus connection 1, proxy a
- Connection *mConn1a;
+ ConnectionPtr mConn1a;
// Bus connection 1, proxy b
- Connection *mConn1b;
+ ConnectionPtr mConn1b;
// Bus connection 2
- Connection *mConn2;
+ ConnectionPtr mConn2;
// Temporary storage to move ReferencedHandles away from their self-destructive parents in the
// finished() handlers
@@ -107,12 +107,12 @@ void TestHandles::initTestCase()
QString objectPath = reply.argumentAt<1>().path();
// Get a few connections connected
- mConn1a = new Connection(busName, objectPath);
- mConn1b = new Connection(busName, objectPath);
+ mConn1a = Connection::create(busName, objectPath);
+ mConn1b = Connection::create(busName, objectPath);
QDBusConnection privateBus =
QDBusConnection::connectToBus(QDBusConnection::SessionBus,
"tpqt4_handles_test_private_bus");
- mConn2 = new Connection(privateBus, busName, objectPath);
+ mConn2 = Connection::create(privateBus, busName, objectPath);
// Connecting one connects them all
QVERIFY(connect(mConn1a->requestConnect(),
@@ -121,19 +121,19 @@ void TestHandles::initTestCase()
SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
- Connection *connections[3] = {mConn1a, mConn1b, mConn2};
+ ConnectionPtr connections[3] = {mConn1a, mConn1b, mConn2};
for (int i = 0; i < 3; ++i) {
- Connection *conn = connections[i];
+ ConnectionPtr conn = connections[i];
if (conn->status() == Connection::StatusConnected) {
qDebug() << conn << "Already ready";
continue;
}
- QVERIFY(connect(conn, SIGNAL(statusChanged(uint, uint)),
+ QVERIFY(connect(conn.data(), SIGNAL(statusChanged(uint, uint)),
this, SLOT(expectConnReady(uint, uint))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(conn, SIGNAL(statusChanged(uint, uint)),
+ QVERIFY(disconnect(conn.data(), SIGNAL(statusChanged(uint, uint)),
this, SLOT(expectConnReady(uint, uint))));
}
}
@@ -183,7 +183,7 @@ void TestHandles::testBasics()
// Check that the closure is consistent with what we asked for
QVERIFY(pending->isRequest());
QCOMPARE(pending->namesRequested(), ids);
- QCOMPARE(pending->connection(), mConn1a);
+ QCOMPARE(pending->connection(), mConn1a.data());
QCOMPARE(pending->handleType(), static_cast<uint>(Telepathy::HandleTypeContact));
// Finish the request and extract the resulting ReferencedHandles
@@ -196,14 +196,14 @@ void TestHandles::testBasics()
mHandles = ReferencedHandles();
// Check that the ReferencedHandles are what we asked for
- QCOMPARE(handles.connection(), mConn1a);
+ QCOMPARE(handles.connection(), mConn1a.data());
QCOMPARE(handles.handleType(), static_cast<uint>(Telepathy::HandleTypeContact));
QVERIFY(handles == shouldBe);
// Check that a copy of the received ReferencedHandles is also what we asked for (it's supposed
// to be equivalent with one that we already verified as being that)
ReferencedHandles copy = handles;
- QCOMPARE(copy.connection(), mConn1a);
+ QCOMPARE(copy.connection(), mConn1a.data());
QCOMPARE(copy.handleType(), static_cast<uint>(Telepathy::HandleTypeContact));
QVERIFY(copy == handles);
@@ -314,13 +314,6 @@ void TestHandles::cleanupTestCase()
SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
- delete mConn1a;
- mConn1a = NULL;
- delete mConn1b;
- mConn1b = NULL;
- delete mConn2;
- mConn2 = NULL;
-
delete mCM;
mCM = NULL;
--
1.5.6.5
More information about the telepathy-commits
mailing list