[next] telepathy-glib: tls-certificate test: GBytes aren't 0 terminated
Xavier Claessens
xclaesse at kemper.freedesktop.org
Fri Sep 7 12:08:56 PDT 2012
Module: telepathy-glib
Branch: next
Commit: 8c682d0122b066ad69cc7106884f383563c2ba6d
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=8c682d0122b066ad69cc7106884f383563c2ba6d
Author: Sjoerd Simons <sjoerd.simons at collabora.co.uk>
Date: Fri Aug 31 15:33:08 2012 +0200
tls-certificate test: GBytes aren't 0 terminated
---
tests/dbus/tls-certificate.c | 2 +-
tests/lib/util.c | 20 ++++++++++++++++++++
tests/lib/util.h | 6 ++++++
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/tests/dbus/tls-certificate.c b/tests/dbus/tls-certificate.c
index 752ea6d..ee67ff2 100644
--- a/tests/dbus/tls-certificate.c
+++ b/tests/dbus/tls-certificate.c
@@ -160,7 +160,7 @@ test_core (Test *test,
g_assert (cert_data != NULL);
g_assert_cmpuint (cert_data->len, ==, 1);
d = g_ptr_array_index (cert_data, 0);
- g_assert_cmpstr (g_bytes_get_data (d, NULL), ==, "BADGER");
+ tp_tests_assert_bytes_equals (d, "BADGER", 6);
}
static void
diff --git a/tests/lib/util.c b/tests/lib/util.c
index 21d3855..9510cb0 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -176,6 +176,26 @@ _tp_tests_assert_strv_equals (const char *file,
}
void
+_tp_tests_assert_bytes_equal (const gchar *file, int line,
+ GBytes *actual, gconstpointer expected_data,
+ gsize expected_length)
+{
+ if (expected_length != g_bytes_get_size (actual))
+ {
+ g_error ("%s:%d: assertion failed: expected %"G_GSIZE_FORMAT
+ " bytes, got %"G_GSIZE_FORMAT,
+ file, line, expected_length, g_bytes_get_size (actual));
+ }
+ else if (memcmp (g_bytes_get_data (actual, NULL),
+ expected_data, expected_length) != 0)
+ {
+ g_error (
+ "%s:%d: assertion failed: expected data didn't match the actual data",
+ file, line);
+ }
+}
+
+void
tp_tests_create_conn (GType conn_type,
const gchar *account,
gboolean connect,
diff --git a/tests/lib/util.h b/tests/lib/util.h
index d58138e..ce19d66 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -36,6 +36,12 @@ void _tp_tests_assert_strv_equals (const char *file, int line,
const char *actual_desc, gconstpointer actual_strv,
const char *expected_desc, gconstpointer expected_strv);
+#define tp_tests_assert_bytes_equals(actual, expected, expected_length) \
+ _tp_tests_assert_bytes_equal (__FILE__, __LINE__, \
+ actual, expected, expected_length)
+void _tp_tests_assert_bytes_equal (const gchar *file, int line,
+ GBytes *actual, gconstpointer expected_data, gsize expected_length);
+
void tp_tests_create_conn (GType conn_type,
const gchar *account,
gboolean connect,
More information about the telepathy-commits
mailing list