From c5081565eb85268da5c89b7b8020adc4d4815fc8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 9 Jun 2011 18:36:05 +0100 Subject: [PATCH 4/4] marshal test: test dbus_message_demarshal_bytes_needed Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38120 --- test/marshal.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/test/marshal.c b/test/marshal.c index 420c830..9e6faa7 100644 --- a/test/marshal.c +++ b/test/marshal.c @@ -203,6 +203,40 @@ test_endian (Fixture *f, } static void +test_needed (Fixture *f, + gconstpointer arg) +{ + const gchar *blob = arg; + + /* We need at least 16 bytes to know how long the message is - that's just + * a fact of the D-Bus protocol. */ + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 0), ==, 0); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 15), ==, 0); + /* This is enough that we should be able to tell how much we need. */ + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 16), ==, BLOB_LENGTH); + /* The header is 32 bytes long (here), so that's another interesting + * boundary. */ + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 31), ==, BLOB_LENGTH); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 32), ==, BLOB_LENGTH); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, 33), ==, BLOB_LENGTH); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, BLOB_LENGTH - 1), ==, + BLOB_LENGTH); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, BLOB_LENGTH), ==, + BLOB_LENGTH); + g_assert_cmpint ( + dbus_message_demarshal_bytes_needed (blob, sizeof (be_blob)), ==, + BLOB_LENGTH); +} + +static void teardown (Fixture *f, gconstpointer arg G_GNUC_UNUSED) { @@ -217,6 +251,10 @@ main (int argc, g_test_add ("/demarshal/le", Fixture, le_blob, setup, test_endian, teardown); g_test_add ("/demarshal/be", Fixture, be_blob, setup, test_endian, teardown); + g_test_add ("/demarshal/needed/le", Fixture, le_blob, setup, test_needed, + teardown); + g_test_add ("/demarshal/needed/be", Fixture, be_blob, setup, test_needed, + teardown); return g_test_run (); } -- 1.7.5.3