summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-01 14:30:15 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-02 16:40:15 +0100
commit25c3f4dd8b9360cb531f0fc3a653094ce1e9b042 (patch)
tree346379e737f9b949cd2052c67d1f9dd403dcf37e
parent9f8f181fd943f1e96f898c736ee4977d310b94a1 (diff)
test plugin: make TestChannelManager implement CapsChannelManagerdata-forms
...and give back a new data form in the represent_client function. Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--plugins/test.c76
-rw-r--r--tests/twisted/Makefile.am1
-rw-r--r--tests/twisted/dataforms.py30
3 files changed, 105 insertions, 2 deletions
diff --git a/plugins/test.c b/plugins/test.c
index add4ba5fb..026091db9 100644
--- a/plugins/test.c
+++ b/plugins/test.c
@@ -5,10 +5,12 @@
#include <telepathy-glib/telepathy-glib.h>
#include <wocky/wocky-disco-identity.h>
+#include <wocky/wocky-data-form.h>
#include "extensions/extensions.h"
#include <gabble/plugin.h>
+#include <gabble/caps-channel-manager.h>
#define DEBUG(msg, ...) \
g_debug ("%s: " msg, G_STRFUNC, ##__VA_ARGS__)
@@ -484,11 +486,15 @@ async_initable_iface_init (
* TestChannelManager implementation *
***********************************/
static void channel_manager_iface_init (gpointer, gpointer);
+static void caps_channel_manager_iface_init (gpointer g_iface,
+ gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (TestChannelManager, test_channel_manager,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER,
- channel_manager_iface_init));
+ channel_manager_iface_init)
+ G_IMPLEMENT_INTERFACE (GABBLE_TYPE_CAPS_CHANNEL_MANAGER,
+ caps_channel_manager_iface_init));
static void
test_channel_manager_init (TestChannelManager *self)
@@ -593,8 +599,65 @@ test_channel_manager_type_foreach_channel_class (GType type,
}
static void
+test_channel_manager_represent_client (
+ GabbleCapsChannelManager *manager,
+ const gchar *client_name,
+ const GPtrArray *filters,
+ const gchar * const *cap_tokens,
+ GabbleCapabilitySet *cap_set,
+ GPtrArray *data_forms)
+{
+ WockyStanza *stanza;
+ WockyDataForm *form;
+
+ if (tp_strdiff (client_name, "dataformtest"))
+ return;
+
+ stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ,
+ WOCKY_STANZA_SUB_TYPE_NONE, NULL, "badger",
+ '(', "x",
+ ':', "jabber:x:data",
+ '@', "type", "result",
+ '(', "field",
+ '@', "var", "FORM_TYPE",
+ '@', "type", "hidden",
+ '(', "value", '$', "gabble:test:channel:manager:data:form", ')',
+ ')',
+ '(', "field",
+ '@', "var", "animal",
+ '(', "value", '$', "badger", ')',
+ '(', "value", '$', "snake", ')',
+ '(', "value", '$', "weasel", ')',
+ ')',
+ '(', "field",
+ '@', "var", "cheese",
+ '(', "value", '$', "omgnothorriblecheese", ')',
+ ')',
+ '(', "field",
+ '@', "var", "favourite_crane",
+ '(', "value", '$', "a tall one", ')',
+ '(', "value", '$', "a short one", ')',
+ ')',
+ '(', "field",
+ '@', "var", "running_out_of",
+ '(', "value", '$', "ideas", ')',
+ '(', "value", '$', "cake", ')',
+ ')',
+ ')',
+ NULL);
+
+ form = wocky_data_form_new_from_node (
+ wocky_node_get_first_child (wocky_stanza_get_top_node (stanza)),
+ NULL);
+
+ g_ptr_array_add (data_forms, form);
+
+ g_object_unref (stanza);
+}
+
+static void
channel_manager_iface_init (gpointer g_iface,
- gpointer iface_data)
+ gpointer iface_data)
{
TpChannelManagerIface *iface = g_iface;
@@ -606,3 +669,12 @@ channel_manager_iface_init (gpointer g_iface,
iface->request_channel = NULL;
iface->foreach_channel_class = NULL;
}
+
+static void
+caps_channel_manager_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ GabbleCapsChannelManagerInterface *iface = g_iface;
+
+ iface->represent_client = test_channel_manager_represent_client;
+}
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 3bb3a241d..4560638d0 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -96,6 +96,7 @@ TWISTED_TESTS = \
text/test-text.py \
tls/server-tls-channel.py \
version.py \
+ dataforms.py \
$(NULL)
TWISTED_TUBE_TESTS = \
diff --git a/tests/twisted/dataforms.py b/tests/twisted/dataforms.py
new file mode 100644
index 000000000..04af1ac38
--- /dev/null
+++ b/tests/twisted/dataforms.py
@@ -0,0 +1,30 @@
+"""
+Test dataforms
+"""
+
+from servicetest import sync_dbus, assertEquals
+from gabbletest import exec_test, sync_stream
+import ns
+import constants as cs
+from caps_helper import receive_presence_and_ask_caps
+
+def test(q, bus, conn, stream):
+ q.expect('stream-presence')
+
+ conn.ContactCapabilities.UpdateCapabilities(
+ [
+ ('dataformtest', [], [])
+ ])
+
+ _, _, forms, _ = receive_presence_and_ask_caps(q, stream)
+
+ assertEquals({'gabble:test:channel:manager:data:form':
+ {'cheese': ['omgnothorriblecheese'],
+ 'running_out_of': ['ideas', 'cake'],
+ 'favourite_crane': ['a tall one', 'a short one'],
+ 'animal': ['badger', 'snake', 'weasel']
+ }
+ }, forms)
+
+if __name__ == '__main__':
+ exec_test(test)