dbus/dbus dbus-message.c,1.115,1.116

Richard Hult richard@pdx.freedesktop.org
Tue, 02 Dec 2003 02:33:37 -0800


Update of /cvs/dbus/dbus/dbus
In directory pdx:/tmp/cvs-serv25675/dbus

Modified Files:
	dbus-message.c 
Log Message:
2003-12-02  Richard Hult  <richard@imendio.com>

	* dbus/dbus-message.c (dbus_message_iter_append_dict): Set
	wrote_dict_key to FALSE on the iter that the dict is appended to,
	just like when appending other types. Fixes a bug where a dict
	couldn't be put inside a dict.
	(dbus_message_iter_append_dict_key): Fix typo in warning message.
	(message_iter_test, _dbus_message_test): Add test case for dict
	inside dict.


Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- dbus-message.c	27 Nov 2003 01:25:49 -0000	1.115
+++ dbus-message.c	2 Dec 2003 10:33:35 -0000	1.116
@@ -3874,7 +3874,7 @@
   
   if (real->wrote_dict_key)
     {
-      _dbus_warn ("Appendinging multiple dict key names\n");
+      _dbus_warn ("Appending multiple dict key names\n");
       return FALSE;
     }
   
@@ -4082,6 +4082,8 @@
 
   dbus_message_iter_append_done (dict_real);
   
+  real->wrote_dict_key = FALSE;
+  
   return TRUE;
 }
 
@@ -5800,7 +5802,7 @@
 static void
 message_iter_test (DBusMessage *message)
 {
-  DBusMessageIter iter, dict, array, array2;
+  DBusMessageIter iter, dict, dict2, array, array2;
   char *str;
   unsigned char *data;
   dbus_int32_t *our_int_array;
@@ -5899,6 +5901,32 @@
   if (dbus_message_iter_get_uint32 (&dict) != 0xDEADBEEF)
     _dbus_assert_not_reached ("wrong dict entry value");
 
+  /* dict (in dict) */
+
+  if (!dbus_message_iter_next (&dict))
+    _dbus_assert_not_reached ("reached end of dict");
+  
+  if (dbus_message_iter_get_arg_type (&dict) != DBUS_TYPE_DICT)
+    _dbus_assert_not_reached ("not dict type");
+    
+  dbus_message_iter_init_dict_iterator (&dict, &dict2);
+  
+  str = dbus_message_iter_get_dict_key (&dict2);
+  if (str == NULL || strcmp (str, "dictkey") != 0)
+    _dbus_assert_not_reached ("wrong dict key");
+  dbus_free (str);
+  
+  if (dbus_message_iter_get_arg_type (&dict2) != DBUS_TYPE_STRING)
+    _dbus_assert_not_reached ("wrong dict entry type");
+  
+  str = dbus_message_iter_get_string (&dict2);
+  if (str == NULL || strcmp (str, "dictvalue") != 0)
+    _dbus_assert_not_reached ("wrong dict entry value");
+  dbus_free (str);
+  
+  if (dbus_message_iter_next (&dict2))
+    _dbus_assert_not_reached ("didn't reach end of dict");
+
   if (!dbus_message_iter_next (&dict))
     _dbus_assert_not_reached ("reached end of dict");
   
@@ -7107,6 +7135,13 @@
   dbus_message_iter_append_dict_key (&child_iter, "test");
   dbus_message_iter_append_uint32 (&child_iter, 0xDEADBEEF);
 
+  /* dict (in dict) */
+  dbus_message_iter_append_dict_key (&child_iter, "testdict");
+  dbus_message_iter_append_dict (&child_iter, &child_iter2);
+
+  dbus_message_iter_append_dict_key (&child_iter2, "dictkey");
+  dbus_message_iter_append_string (&child_iter2, "dictvalue");
+
   /* array of array of int32  (in dict) */
   dbus_message_iter_append_dict_key (&child_iter, "array");
   dbus_message_iter_append_array (&child_iter, &child_iter2, DBUS_TYPE_ARRAY);