[telepathy-qt4/master] roster-groups example: Added initial test cases for roster groups support.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Wed Jul 22 15:38:46 PDT 2009


---
 tests/dbus/Makefile.am            |    5 +
 tests/dbus/conn-roster-groups.cpp |  204 +++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/conn-roster-groups.cpp

diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index fc3950f..edf0326 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -61,6 +61,7 @@ TESTS += \
     test-conn-basics \
     test-conn-requests \
     test-conn-roster \
+    test-conn-roster-groups \
     test-contacts \
     test-handles \
     test-stateful-proxy \
@@ -74,6 +75,7 @@ BUILT_SOURCES += \
     _gen/conn-basics.cpp.moc.hpp \
     _gen/conn-requests.cpp.moc.hpp \
     _gen/conn-roster.cpp.moc.hpp \
+    _gen/conn-roster-groups.cpp.moc.hpp \
     _gen/contacts.cpp.moc.hpp \
     _gen/handles.cpp.moc.hpp \
     _gen/stateful-proxy.cpp.moc.hpp \
@@ -100,6 +102,9 @@ test_conn_requests_LDADD = $(LDADD) $(top_builddir)/tests/lib/echo2/libtp-glib-e
 test_conn_roster_SOURCES = conn-roster.cpp
 test_conn_roster_LDADD = $(LDADD) $(top_builddir)/tests/lib/contactlist/libexample-cm-contactlist.la
 
+test_conn_roster_groups_SOURCES = conn-roster-groups.cpp
+test_conn_roster_groups_LDADD = $(LDADD) $(top_builddir)/tests/lib/contactlist/libexample-cm-contactlist.la
+
 test_contacts_SOURCES = contacts.cpp
 test_contacts_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
 
diff --git a/tests/dbus/conn-roster-groups.cpp b/tests/dbus/conn-roster-groups.cpp
new file mode 100644
index 0000000..7a57e3c
--- /dev/null
+++ b/tests/dbus/conn-roster-groups.cpp
@@ -0,0 +1,204 @@
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+#include <QtTest/QtTest>
+
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/Contact>
+#include <TelepathyQt4/ContactManager>
+#include <TelepathyQt4/PendingReady>
+#include <TelepathyQt4/Debug>
+
+#include <telepathy-glib/debug.h>
+
+#include <tests/lib/contactlist/conn.h>
+#include <tests/lib/test.h>
+
+using namespace Tp;
+
+class TestConnRosterGroups : public Test
+{
+    Q_OBJECT
+
+public:
+    TestConnRosterGroups(QObject *parent = 0)
+        : Test(parent), mConnService(0)
+    { }
+
+protected Q_SLOTS:
+    void onGroupAdded(const QString &group);
+    void expectConnInvalidated();
+
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+
+    void testRosterGroups();
+
+    void cleanup();
+    void cleanupTestCase();
+
+private:
+    QString mConnName, mConnPath;
+    ExampleContactListConnection *mConnService;
+    ConnectionPtr mConn;
+
+    QString mGroupAdded;
+};
+
+void TestConnRosterGroups::onGroupAdded(const QString &group)
+{
+    mGroupAdded = group;
+    mLoop->exit(0);
+}
+
+void TestConnRosterGroups::expectConnInvalidated()
+{
+    mLoop->exit(0);
+}
+
+void TestConnRosterGroups::initTestCase()
+{
+    initTestCaseImpl();
+
+    g_type_init();
+    g_set_prgname("conn-basics");
+    tp_debug_set_flags("all");
+    dbus_g_bus_get(DBUS_BUS_STARTER, 0);
+
+    gchar *name;
+    gchar *connPath;
+    GError *error = 0;
+
+    mConnService = EXAMPLE_CONTACT_LIST_CONNECTION(g_object_new(
+            EXAMPLE_TYPE_CONTACT_LIST_CONNECTION,
+            "account", "me at example.com",
+            "protocol", "contactlist",
+            0));
+    QVERIFY(mConnService != 0);
+    QVERIFY(tp_base_connection_register(TP_BASE_CONNECTION(mConnService),
+                "contacts", &name, &connPath, &error));
+    QVERIFY(error == 0);
+
+    QVERIFY(name != 0);
+    QVERIFY(connPath != 0);
+
+    mConnName = name;
+    mConnPath = connPath;
+
+    g_free(name);
+    g_free(connPath);
+}
+
+void TestConnRosterGroups::init()
+{
+    initImpl();
+
+    mConn = Connection::create(mConnName, mConnPath);
+
+    QVERIFY(connect(mConn->requestConnect(),
+                    SIGNAL(finished(Tp::PendingOperation*)),
+                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mConn->isReady(), true);
+    QCOMPARE(mConn->status(), static_cast<uint>(Connection::StatusConnected));
+
+}
+
+void TestConnRosterGroups::testRosterGroups()
+{
+    Features features = Features() << Connection::FeatureRoster << Connection::FeatureRosterGroups;
+    QVERIFY(connect(mConn->becomeReady(features),
+            SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mConn->isReady(features), true);
+
+    ContactManager *contactManager = mConn->contactManager();
+
+    QStringList expectedGroups;
+    expectedGroups << "Cambridge" << "Francophones" << "Montreal";
+    expectedGroups.sort();
+    QStringList groups = contactManager->allKnownGroups();
+    groups.sort();
+    QCOMPARE(groups, expectedGroups);
+
+    // Cambridge
+    {
+        QStringList expectedContacts;
+        expectedContacts << "geraldine at example.com" << "helen at example.com"
+            << "guillaume at example.com" << "sjoerd at example.com";
+        expectedContacts.sort();
+        QStringList contacts;
+        foreach (const ContactPtr &contact, contactManager->groupContacts("Cambridge")) {
+            contacts << contact->id();
+        }
+        contacts.sort();
+        QCOMPARE(contacts, expectedContacts);
+    }
+
+    // Francophones
+    {
+        QStringList expectedContacts;
+        expectedContacts << "olivier at example.com" << "geraldine at example.com"
+            << "guillaume at example.com";
+        expectedContacts.sort();
+        QStringList contacts;
+        foreach (const ContactPtr &contact, contactManager->groupContacts("Francophones")) {
+            contacts << contact->id();
+        }
+        contacts.sort();
+        QCOMPARE(contacts, expectedContacts);
+    }
+
+    // Montreal
+    {
+        QStringList expectedContacts;
+        expectedContacts << "olivier at example.com";
+        expectedContacts.sort();
+        QStringList contacts;
+        foreach (const ContactPtr &contact, contactManager->groupContacts("Montreal")) {
+            contacts << contact->id();
+        }
+        contacts.sort();
+        QCOMPARE(contacts, expectedContacts);
+    }
+
+    QVERIFY(contactManager->groupContacts("foo").isEmpty());
+}
+
+void TestConnRosterGroups::cleanup()
+{
+    if (mConn) {
+        // Disconnect and wait for the readiness change
+        QVERIFY(connect(mConn->requestDisconnect(),
+                        SIGNAL(finished(Tp::PendingOperation*)),
+                        SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
+        QCOMPARE(mLoop->exec(), 0);
+
+        if (mConn->isValid()) {
+            QVERIFY(connect(mConn.data(),
+                            SIGNAL(invalidated(Tp::DBusProxy *,
+                                               const QString &, const QString &)),
+                            SLOT(expectConnInvalidated())));
+            QCOMPARE(mLoop->exec(), 0);
+        }
+    }
+
+    cleanupImpl();
+}
+
+void TestConnRosterGroups::cleanupTestCase()
+{
+    if (mConnService != 0) {
+        g_object_unref(mConnService);
+        mConnService = 0;
+    }
+
+    cleanupTestCaseImpl();
+}
+
+QTEST_MAIN(TestConnRosterGroups)
+#include "_gen/conn-roster-groups.cpp.moc.hpp"
-- 
1.5.6.5




More information about the telepathy-commits mailing list