[telepathy-qt4/master] client-handler test: Added initial ClientHandler test.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue May 5 08:20:43 PDT 2009


---
 tests/dbus/Makefile.am        |    5 +
 tests/dbus/client-handler.cpp |  169 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 174 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/client-handler.cpp

diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 0efed5b..c8affad 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -38,6 +38,7 @@ if ENABLE_TP_GLIB_TESTS
 TESTS += \
     test-chan-basics \
     test-chan-group \
+    test-client-handler \
     test-cm-basics \
     test-conn-basics \
     test-conn-requests \
@@ -51,6 +52,7 @@ TESTS += \
 BUILT_SOURCES += \
     _gen/chan-basics.cpp.moc.hpp \
     _gen/chan-group.cpp.moc.hpp \
+    _gen/client-handler.cpp.moc.hpp \
     _gen/cm-basics.cpp.moc.hpp \
     _gen/conn-basics.cpp.moc.hpp \
     _gen/conn-requests.cpp.moc.hpp \
@@ -69,6 +71,9 @@ test_chan_basics_LDADD = $(LDADD) $(top_builddir)/tests/lib/echo2/libtp-glib-ech
 test_chan_group_SOURCES = chan-group.cpp
 test_chan_group_LDADD = $(LDADD) $(top_builddir)/tests/lib/csh/libtp-glib-csh-tests.la
 
+test_client_handler_SOURCES = client-handler.cpp
+test_client_handler_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
+
 test_cm_basics_SOURCES = cm-basics.cpp
 test_cm_basics_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
 
diff --git a/tests/dbus/client-handler.cpp b/tests/dbus/client-handler.cpp
new file mode 100644
index 0000000..3bd6269
--- /dev/null
+++ b/tests/dbus/client-handler.cpp
@@ -0,0 +1,169 @@
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+#include <QtDBus/QtDBus>
+#include <QtTest/QtTest>
+
+#include <QDateTime>
+#include <QString>
+#include <QVariantMap>
+
+#include <TelepathyQt4/Account>
+#include <TelepathyQt4/AbstractClientHandler>
+#include <TelepathyQt4/Channel>
+#include <TelepathyQt4/ChannelRequest>
+#include <TelepathyQt4/ClientRegistrar>
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/PendingClientOperation>
+#include <TelepathyQt4/Types>
+
+#include <telepathy-glib/debug.h>
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+#include <tests/lib/test.h>
+
+using namespace Tp;
+
+class MyHandler : public AbstractClientHandler
+{
+public:
+    MyHandler(const ChannelClassList &channelFilter,
+            bool bypassApproval = false,
+            bool listenRequests = false)
+        : AbstractClientHandler(channelFilter, listenRequests),
+          mBypassApproval(bypassApproval)
+    {
+    }
+
+    ~MyHandler()
+    {
+    }
+
+    bool bypassApproval() const
+    {
+        return mBypassApproval;
+    }
+
+    QList<ChannelPtr> handledChannels() const
+    {
+        return mHandledChannels;
+    }
+
+    void handleChannels(PendingClientOperation *operation,
+            const AccountPtr &account,
+            const ConnectionPtr &connection,
+            const QList<ChannelPtr> &channels,
+            const QList<ChannelRequestPtr> &requestsSatisfied,
+            const QDateTime &userActionTime,
+            const QVariantMap &handlerInfo)
+    {
+        mHandleChannelsAccount = account;
+        mHandleChannelsConnection = connection;
+        mHandleChannelsChannels = channels;
+        mHandleChannelsRequestsSatisfied = requestsSatisfied;
+        mHandleChannelsUserActionTime = userActionTime;
+        mHandleChannelsHandlerInfo = handlerInfo;
+        mHandledChannels.append(channels);
+        operation->setFinished();
+    }
+
+    void addRequest(const ChannelRequestPtr &request)
+    {
+        mAddRequestRequest = request;
+    }
+
+    void removeRequest(const ChannelRequestPtr &request,
+            const QString &errorName, const QString &errorMessage)
+    {
+        mRemoveRequestRequest = request;
+        mRemoveRequestErrorName = errorName;
+        mRemoveRequestErrorMessage = errorMessage;
+    }
+
+    bool mBypassApproval;
+    AccountPtr mHandleChannelsAccount;
+    ConnectionPtr mHandleChannelsConnection;
+    QList<ChannelPtr> mHandleChannelsChannels;
+    QList<ChannelRequestPtr> mHandleChannelsRequestsSatisfied;
+    QDateTime mHandleChannelsUserActionTime;
+    QVariantMap mHandleChannelsHandlerInfo;
+    QList<ChannelPtr> mHandledChannels;
+    ChannelRequestPtr mAddRequestRequest;
+    ChannelRequestPtr mRemoveRequestRequest;
+    QString mRemoveRequestErrorName;
+    QString mRemoveRequestErrorMessage;
+};
+
+class TestClientHandler : public Test
+{
+    Q_OBJECT
+
+public:
+    TestClientHandler(QObject *parent = 0)
+        : Test(parent)
+    { }
+
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+
+    void testRegister();
+
+    void cleanup();
+    void cleanupTestCase();
+
+private:
+    ClientRegistrarPtr mClientRegistrar;
+};
+
+void TestClientHandler::initTestCase()
+{
+    initTestCaseImpl();
+
+    g_type_init();
+    g_set_prgname("client-handler");
+    tp_debug_set_flags("all");
+    dbus_g_bus_get(DBUS_BUS_STARTER, 0);
+
+    mClientRegistrar = ClientRegistrar::create("foo");
+}
+
+void TestClientHandler::init()
+{
+    initImpl();
+}
+
+void TestClientHandler::testRegister()
+{
+    ChannelClassList filters;
+    QMap<QString, QDBusVariant> filter;
+    filter.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
+                  QDBusVariant(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT));
+    filter.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
+                  QDBusVariant(Tp::HandleTypeContact));
+    filters.append(filter);
+    SharedPtr<MyHandler> myHandler = SharedPtr<MyHandler>(
+            new MyHandler(filters));
+    mClientRegistrar->registerClient(AbstractClientPtr::dynamicCast(myHandler));
+
+    QDBusConnection bus = mClientRegistrar->dbusConnection();
+    QDBusConnectionInterface *iface = bus.interface();
+    QStringList registeredServicesNames = iface->registeredServiceNames();
+    QVERIFY(registeredServicesNames.contains(
+                "org.freedesktop.Telepathy.Client.foo"));
+}
+
+void TestClientHandler::cleanup()
+{
+    cleanupImpl();
+}
+
+void TestClientHandler::cleanupTestCase()
+{
+    cleanupTestCaseImpl();
+}
+
+QTEST_MAIN(TestClientHandler)
+#include "_gen/client-handler.cpp.moc.hpp"
-- 
1.5.6.5




More information about the telepathy-commits mailing list