summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott James Remnant <scott@ubuntu.com>2009-07-09 16:28:29 +0100
committerColin Walters <walters@verbum.org>2009-07-14 15:39:02 -0400
commitbf2183345fbd19632e81b107593ca4e944d798de (patch)
tree52cc4a31f1ef4c965f3f414f7b55bc363f67c7a6
parent0539a23c661f028da63526996b6463ef342bb4f3 (diff)
downloaddbus-bf2183345fbd19632e81b107593ca4e944d798de.tar.gz
Add test case for assert when unwinding a container.
* dbus/dbus-message-util.c: when constructing an array of structures, it's not possible to unwind in case of an error part-way through. This test will therefore assert. Signed-off-by: Scott James Remnant <scott@ubuntu.com> (cherry picked from commit 4bea3ca2b02098f2513a9902511e4de77ccf9b91)
-rw-r--r--dbus/dbus-message-util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c
index 46cbe4e3..3d5a00f5 100644
--- a/dbus/dbus-message-util.c
+++ b/dbus/dbus-message-util.c
@@ -939,6 +939,7 @@ _dbus_message_test (const char *test_data_dir)
unsigned char v_BYTE;
unsigned char v2_BYTE;
dbus_bool_t v_BOOLEAN;
+ DBusMessageIter iter, array_iter, struct_iter;
message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
"/org/freedesktop/TestPath",
@@ -1272,6 +1273,34 @@ _dbus_message_test (const char *test_data_dir)
check_memleaks ();
+ /* Check that we can abandon a container */
+ message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
+ "/org/freedesktop/TestPath",
+ "Foo.TestInterface",
+ "Method");
+
+ dbus_message_iter_init_append (message, &iter);
+
+ _dbus_assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ (DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_STRUCT_END_CHAR_AS_STRING),
+ &array_iter));
+ _dbus_assert (dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
+ NULL, &struct_iter));
+
+ s = "peaches";
+ _dbus_assert (dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING,
+ &s));
+
+ /* uh-oh, error, try and unwind */
+
+ _dbus_assert (dbus_message_iter_close_container (&array_iter, &struct_iter));
+ _dbus_assert (dbus_message_iter_close_container (&array_iter, &iter));
+
+ dbus_message_unref (message);
+
/* Load all the sample messages from the message factory */
{
DBusMessageDataIter diter;