[Telepathy-commits] [telepathy-qt4/master] Skeleton test for Contacts
Olli Salli
olli.salli at collabora.co.uk
Wed Jan 28 22:46:13 PST 2009
---
tests/dbus/Makefile.am | 5 +
tests/dbus/contacts.cpp | 221 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 226 insertions(+), 0 deletions(-)
create mode 100644 tests/dbus/contacts.cpp
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 2f60126..35eacca 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -41,6 +41,7 @@ TESTS += \
test-cm-basics \
test-conn-basics \
test-conn-requests \
+ test-contacts \
test-handles \
test-stateful-proxy
@@ -48,6 +49,7 @@ BUILT_SOURCES += \
_gen/cm-basics.cpp.moc.hpp \
_gen/conn-basics.cpp.moc.hpp \
_gen/conn-requests.cpp.moc.hpp \
+ _gen/contacts.cpp.moc.hpp \
_gen/handles.cpp.moc.hpp \
_gen/stateful-proxy.cpp.moc.hpp
@@ -62,6 +64,9 @@ test_conn_basics_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
test_conn_requests_SOURCES = conn-requests.cpp
test_conn_requests_LDADD = $(LDADD) $(top_builddir)/tests/lib/echo2/libtp-glib-echo2-tests.la
+test_contacts_SOURCES = contacts.cpp
+test_contacts_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
+
test_handles_SOURCES = handles.cpp
test_handles_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
new file mode 100644
index 0000000..f523a0d
--- /dev/null
+++ b/tests/dbus/contacts.cpp
@@ -0,0 +1,221 @@
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+#include <QtTest/QtTest>
+
+#include <TelepathyQt4/Client/Connection>
+#include <TelepathyQt4/Client/Contact>
+#include <TelepathyQt4/Client/ContactManager>
+#include <TelepathyQt4/Client/PendingContacts>
+#include <TelepathyQt4/Client/PendingVoidMethodCall>
+#include <TelepathyQt4/Debug>
+
+#include <telepathy-glib/debug.h>
+
+#include <tests/lib/contacts-conn.h>
+#include <tests/lib/test.h>
+
+using namespace Telepathy::Client;
+
+class TestContacts : public Test
+{
+ Q_OBJECT
+
+public:
+ TestContacts(QObject *parent = 0)
+ : Test(parent), mConnService(0), mConn(0)
+ {
+ }
+
+protected Q_SLOTS:
+ void expectConnReady(uint newStatus, uint newStatusReason);
+ void expectConnInvalidated();
+
+private Q_SLOTS:
+ void initTestCase();
+ void init();
+
+ void cleanup();
+ void cleanupTestCase();
+
+private:
+ QString mConnName, mConnPath;
+ ContactsConnection *mConnService;
+ Connection *mConn;
+};
+
+void TestContacts::expectConnReady(uint newStatus, uint newStatusReason)
+{
+ switch (newStatus) {
+ case Connection::StatusDisconnected:
+ qWarning() << "Disconnected";
+ mLoop->exit(1);
+ break;
+ case Connection::StatusConnecting:
+ /* do nothing */
+ break;
+ case Connection::StatusConnected:
+ qDebug() << "Ready";
+ mLoop->exit(0);
+ break;
+ default:
+ qWarning().nospace() << "What sort of status is "
+ << newStatus << "?!";
+ mLoop->exit(2);
+ break;
+ }
+}
+
+void TestContacts::expectConnInvalidated()
+{
+ mLoop->exit(0);
+}
+
+void TestContacts::initTestCase()
+{
+ initTestCaseImpl();
+
+ g_type_init();
+ g_set_prgname("contacts");
+ tp_debug_set_flags("all");
+
+ gchar *name;
+ gchar *connPath;
+ GError *error = 0;
+
+ mConnService = CONTACTS_CONNECTION(g_object_new(
+ CONTACTS_TYPE_CONNECTION,
+ "account", "me at example.com",
+ "protocol", "simple",
+ 0));
+ QVERIFY(mConnService != 0);
+ QVERIFY(tp_base_connection_register(TP_BASE_CONNECTION(mConnService), "simple", &name,
+ &connPath, &error));
+ QVERIFY(error == 0);
+
+ QVERIFY(name != 0);
+ QVERIFY(connPath != 0);
+
+ mConnName = name;
+ mConnPath = connPath;
+
+ g_free(name);
+ g_free(connPath);
+
+ mConn = new Connection(mConnName, mConnPath);
+ QCOMPARE(mConn->isReady(), false);
+
+ mConn->requestConnect();
+
+ QVERIFY(connect(mConn->becomeReady(),
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+ QCOMPARE(mLoop->exec(), 0);
+ QCOMPARE(mConn->isReady(), true);
+
+ if (mConn->status() != Connection::StatusConnected) {
+ QVERIFY(connect(mConn,
+ SIGNAL(statusChanged(uint, uint)),
+ SLOT(expectConnReady(uint, uint))));
+ QCOMPARE(mLoop->exec(), 0);
+ QVERIFY(disconnect(mConn,
+ SIGNAL(statusChanged(uint, uint)),
+ this,
+ SLOT(expectConnReady(uint, uint))));
+ QCOMPARE(mConn->status(), static_cast<uint>(Connection::StatusConnected));
+ }
+}
+
+void TestContacts::init()
+{
+ initImpl();
+}
+
+#if 0
+void TestHandles::testRequestAndRelease()
+{
+ // Test identifiers
+ QStringList ids = QStringList() << "alice" << "bob" << "chris";
+
+ // Request handles for the identifiers and wait for the request to process
+ PendingHandles *pending = mConn->requestHandles(Telepathy::HandleTypeContact, ids);
+ QVERIFY(connect(pending,
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(expectPendingHandlesFinished(Telepathy::Client::PendingOperation*))));
+ QCOMPARE(mLoop->exec(), 0);
+ QVERIFY(disconnect(pending,
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ this,
+ SLOT(expectPendingHandlesFinished(Telepathy::Client::PendingOperation*))));
+ ReferencedHandles handles = mHandles;
+ mHandles = ReferencedHandles();
+
+ // Verify that the closure indicates correctly which names we requested
+ QCOMPARE(pending->namesRequested(), ids);
+
+ // Verify by directly poking the service that the handles correspond to the requested IDs
+ TpHandleRepoIface *serviceRepo =
+ tp_base_connection_get_handles(TP_BASE_CONNECTION(mConnService), TP_HANDLE_TYPE_CONTACT);
+ for (int i = 0; i < 3; i++) {
+ uint handle = handles[i];
+ QCOMPARE(QString::fromUtf8(tp_handle_inspect(serviceRepo, handle)), ids[i]);
+ }
+
+ // Save the handles to a non-referenced normal container
+ Telepathy::UIntList saveHandles = handles.toList();
+
+ // Start releasing the handles, RAII style, and complete the asynchronous process doing that
+ handles = ReferencedHandles();
+ mLoop->processEvents();
+
+ // Make sure the service side has processed the release as well, by calling a method
+ QVERIFY(connect(mConn->requestConnect(),
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+ QCOMPARE(mLoop->exec(), 0);
+
+ // Check that the handles have been released
+ for (int i = 0; i < 3; i++) {
+ uint handle = saveHandles[0];
+ QVERIFY(!tp_handle_is_valid(serviceRepo, handle, NULL));
+ }
+}
+#endif
+
+void TestContacts::cleanup()
+{
+ cleanupImpl();
+}
+
+void TestContacts::cleanupTestCase()
+{
+ if (mConn) {
+ // Disconnect and wait for the readiness change
+ QVERIFY(connect(mConn->requestDisconnect(),
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+ QCOMPARE(mLoop->exec(), 0);
+
+ if (mConn->isValid()) {
+ QVERIFY(connect(mConn,
+ SIGNAL(invalidated(Telepathy::Client::DBusProxy *, QString, QString)),
+ SLOT(expectConnInvalidated())));
+ QCOMPARE(mLoop->exec(), 0);
+ }
+
+ delete mConn;
+ mConn = 0;
+ }
+
+ if (mConnService != 0) {
+ g_object_unref(mConnService);
+ mConnService = 0;
+ }
+
+ cleanupTestCaseImpl();
+}
+
+QTEST_MAIN(TestContacts)
+#include "_gen/contacts.cpp.moc.hpp"
--
1.5.6.5
More information about the telepathy-commits
mailing list