summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/dbus/tls-certificate.c2
-rw-r--r--tests/lib/util.c20
-rw-r--r--tests/lib/util.h6
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,