telepathy-gabble: Add a regression test for line-wrapping avatars

Will Thompson wjt at kemper.freedesktop.org
Wed Nov 14 07:54:00 PST 2012


Module: telepathy-gabble
Branch: master
Commit: fbee99b49de53621a8a5a38534d4cc423296aeef
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=fbee99b49de53621a8a5a38534d4cc423296aeef

Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Wed Nov 14 15:27:13 2012 +0000

Add a regression test for line-wrapping avatars

---

 tests/twisted/Makefile.am         |    1 +
 tests/twisted/vcard/set-avatar.py |   55 +++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 9948eec..eff6454 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -150,6 +150,7 @@ TWISTED_VCARD_TESTS = \
 	vcard/overlapping-sets.py \
 	vcard/redundant-set.py \
 	vcard/refresh-contact-info.py \
+	vcard/set-avatar.py \
 	vcard/set-contact-info.py \
 	vcard/set-set-disconnect.py \
 	vcard/supported-fields.py \
diff --git a/tests/twisted/vcard/set-avatar.py b/tests/twisted/vcard/set-avatar.py
new file mode 100644
index 0000000..ca7bbf5
--- /dev/null
+++ b/tests/twisted/vcard/set-avatar.py
@@ -0,0 +1,55 @@
+"""
+Tests the very simple case of "setting your own avatar".
+"""
+
+from twisted.words.xish import xpath
+from servicetest import call_async, assertEquals
+from gabbletest import (
+    exec_test, expect_and_handle_get_vcard, expect_and_handle_set_vcard,
+    )
+import base64
+import functools
+
+def test(q, bus, conn, stream, image_data, mime_type):
+    call_async(q, conn.Avatars, 'SetAvatar', image_data, mime_type)
+
+    expect_and_handle_get_vcard(q, stream)
+
+    def check(vcard):
+        assertEquals(mime_type,
+            xpath.queryForString('/vCard/PHOTO/TYPE', vcard))
+
+        binval = xpath.queryForString('/vCard/PHOTO/BINVAL', vcard)
+
+        # <http://xmpp.org/extensions/xep-0153.html#bizrules-image> says:
+        #
+        #  5. The image data MUST conform to the base64Binary datatype and thus
+        #     be encoded in accordance with Section 6.8 of RFC 2045, which
+        #     recommends that base64 data should have lines limited to at most
+        #     76 characters in length.
+        lines = binval.split('\n')
+        for line in lines:
+            assert len(line) <= 76, line
+
+        assertEquals(image_data, base64.decodestring(binval))
+
+    expect_and_handle_set_vcard(q, stream, check=check)
+
+    q.expect('dbus-return', method='SetAvatar')
+
+def test_little_avatar(q, bus, conn, stream):
+    test(q, bus, conn, stream, image_data='Guy.brush',
+        mime_type='image/x-mighty-pirate')
+
+def test_massive_avatar(q, bus, conn, stream):
+    """Regression test for
+    <https://bugs.freedesktop.org/show_bug.cgi?id=57080>, where a too-small
+    buffer was allocated if the base64-encoded avatar spanned multiple lines.
+
+    """
+    lol = 'lo' * (4 * 1024)
+    test(q, bus, conn, stream, image_data=lol, mime_type='image/x-lolololo')
+
+if __name__ == '__main__':
+    exec_test(test_little_avatar)
+    exec_test(test_massive_avatar)



More information about the telepathy-commits mailing list