gio: Add regression test for double array encoding
[platform/upstream/glib.git] / gio / tests / gdbus-serialization.c
index 3a49f07..e31dbe4 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
 
+#include <locale.h>
 #include <gio/gio.h>
 
 #include <string.h>
@@ -216,7 +215,7 @@ append_gv_to_dbus_iter (DBusMessageIter  *iter,
       g_set_error (error,
                    G_IO_ERROR,
                    G_IO_ERROR_INVALID_ARGUMENT,
-                   "Error serializing GVariant with type-string `%s' to a D-Bus message",
+                   "Error serializing GVariant with type-string '%s' to a D-Bus message",
                    g_variant_get_type_string (value));
       goto fail;
     }
@@ -385,7 +384,7 @@ dbus_1_message_append (GString *s,
       {
         const gchar *value;
         dbus_message_iter_get_basic (iter, &value);
-        g_string_append_printf (s, "string: `%s'\n", value);
+        g_string_append_printf (s, "string: '%s'\n", value);
         break;
       }
 
@@ -393,7 +392,7 @@ dbus_1_message_append (GString *s,
       {
         const gchar *value;
         dbus_message_iter_get_basic (iter, &value);
-        g_string_append_printf (s, "object_path: `%s'\n", value);
+        g_string_append_printf (s, "object_path: '%s'\n", value);
         break;
       }
 
@@ -401,10 +400,22 @@ dbus_1_message_append (GString *s,
       {
         const gchar *value;
         dbus_message_iter_get_basic (iter, &value);
-        g_string_append_printf (s, "signature: `%s'\n", value);
+        g_string_append_printf (s, "signature: '%s'\n", value);
         break;
       }
 
+#ifdef DBUS_TYPE_UNIX_FD
+    case DBUS_TYPE_UNIX_FD:
+      {
+        /* unfortunately there's currently no way to get just the
+         * protocol value, since dbus_message_iter_get_basic() wants
+         * to be 'helpful' and dup the fd for the user...
+         */
+        g_string_append (s, "unix-fd: (not extracted)\n");
+        break;
+      }
+#endif
+
      case DBUS_TYPE_VARIANT:
        g_string_append_printf (s, "variant:\n");
        dbus_message_iter_recurse (iter, &sub);
@@ -446,7 +457,7 @@ dbus_1_message_append (GString *s,
        break;
 
      default:
-       g_printerr ("Error serializing D-Bus message to GVariant. Unsupported arg type `%c' (%d)",
+       g_printerr ("Error serializing D-Bus message to GVariant. Unsupported arg type '%c' (%d)",
                    arg_type,
                    arg_type);
        g_assert_not_reached ();
@@ -484,12 +495,19 @@ get_body_signature (GVariant *value)
   gsize len;
   gchar *ret;
 
+  if (value == NULL)
+    {
+      ret = g_strdup ("");
+      goto out;
+    }
+
   s = g_variant_get_type_string (value);
   len = strlen (s);
-  g_assert (len>=2);
+  g_assert (len >= 2);
 
   ret = g_strndup (s + 1, len - 2);
 
+ out:
   return ret;
 }
 
@@ -506,6 +524,7 @@ check_serialization (GVariant *value,
   DBusError dbus_error;
   gchar *s;
   gchar *s1;
+  guint n;
 
   message = g_dbus_message_new ();
   g_dbus_message_set_body (message, value);
@@ -517,71 +536,108 @@ check_serialization (GVariant *value,
   g_dbus_message_set_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE, g_variant_new_signature (s));
   g_free (s);
 
-  /* First check that the serialization to the D-Bus wire format is correct */
-
-  error = NULL;
-  blob = g_dbus_message_to_blob (message,
-                                 &blob_size,
-                                 G_DBUS_CAPABILITY_FLAGS_NONE,
-                                 &error);
-  g_assert_no_error (error);
-  g_assert (blob != NULL);
-
-  dbus_error_init (&dbus_error);
-  dbus_1_message = dbus_message_demarshal ((char *) blob, blob_size, &dbus_error);
-  if (dbus_error_is_set (&dbus_error))
+  /* First check that the serialization to the D-Bus wire format is correct - do this for both byte orders */
+  for (n = 0; n < 2; n++)
     {
-      g_printerr ("Error calling dbus_message_demarshal() on this blob: %s: %s\n",
-                  dbus_error.name,
-                  dbus_error.message);
-      hexdump (blob, blob_size);
-      dbus_error_free (&dbus_error);
-
-      s = g_variant_print (value, TRUE);
-      g_printerr ("\nThe blob was generated from the following GVariant value:\n%s\n\n", s);
-      g_free (s);
+      GDBusMessageByteOrder byte_order;
+      switch (n)
+        {
+        case 0:
+          byte_order = G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN;
+          break;
+        case 1:
+          byte_order = G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN;
+          break;
+        case 2:
+          g_assert_not_reached ();
+          break;
+        }
+      g_dbus_message_set_byte_order (message, byte_order);
 
-      g_printerr ("If the blob was encoded using DBusMessageIter, the payload would have been:\n");
-      print_gv_dbus_message (value);
+      error = NULL;
+      blob = g_dbus_message_to_blob (message,
+                                     &blob_size,
+                                     G_DBUS_CAPABILITY_FLAGS_NONE,
+                                     &error);
+      g_assert_no_error (error);
+      g_assert (blob != NULL);
 
-      g_assert_not_reached ();
-    }
+      switch (byte_order)
+        {
+        case G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN:
+          g_assert_cmpint (blob[0], ==, 'B');
+          break;
+        case G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN:
+          g_assert_cmpint (blob[0], ==, 'l');
+          break;
+        }
 
-  s = dbus_1_message_print (dbus_1_message);
-  dbus_message_unref (dbus_1_message);
+      dbus_error_init (&dbus_error);
+      dbus_1_message = dbus_message_demarshal ((char *) blob, blob_size, &dbus_error);
+      if (dbus_error_is_set (&dbus_error))
+        {
+          g_printerr ("Error calling dbus_message_demarshal() on this blob: %s: %s\n",
+                      dbus_error.name,
+                      dbus_error.message);
+          hexdump (blob, blob_size);
+          dbus_error_free (&dbus_error);
 
-  g_assert_cmpstr (s, ==, expected_dbus_1_output);
-  g_free (s);
+          s = g_variant_print (value, TRUE);
+          g_printerr ("\nThe blob was generated from the following GVariant value:\n%s\n\n", s);
+          g_free (s);
 
-  /* Then serialize back and check that the body is identical */
+          g_printerr ("If the blob was encoded using DBusMessageIter, the payload would have been:\n");
+          print_gv_dbus_message (value);
 
-  error = NULL;
-  recovered_message = g_dbus_message_new_from_blob (blob,
-                                                    blob_size,
-                                                    G_DBUS_CAPABILITY_FLAGS_NONE,
-                                                    &error);
-  g_assert_no_error (error);
-  g_assert (recovered_message != NULL);
-  g_assert (g_dbus_message_get_body (recovered_message) != NULL);
+          g_assert_not_reached ();
+        }
 
-  if (!g_variant_equal (g_dbus_message_get_body (recovered_message), value))
-    {
-      s = g_variant_print (g_dbus_message_get_body (recovered_message), TRUE);
-      s1 = g_variant_print (value, TRUE);
-      g_printerr ("Recovered value:\n%s\ndoes not match given value\n%s\n",
-                  s,
-                  s1);
+      s = dbus_1_message_print (dbus_1_message);
+      dbus_message_unref (dbus_1_message);
+
+      g_assert_cmpstr (s, ==, expected_dbus_1_output);
       g_free (s);
-      g_free (s1);
-      g_assert_not_reached ();
+
+      /* Then serialize back and check that the body is identical */
+
+      error = NULL;
+      recovered_message = g_dbus_message_new_from_blob (blob,
+                                                        blob_size,
+                                                        G_DBUS_CAPABILITY_FLAGS_NONE,
+                                                        &error);
+      g_assert_no_error (error);
+      g_assert (recovered_message != NULL);
+
+      if (value == NULL)
+        {
+          g_assert (g_dbus_message_get_body (recovered_message) == NULL);
+        }
+      else
+        {
+          g_assert (g_dbus_message_get_body (recovered_message) != NULL);
+          if (!g_variant_equal (g_dbus_message_get_body (recovered_message), value))
+            {
+              s = g_variant_print (g_dbus_message_get_body (recovered_message), TRUE);
+              s1 = g_variant_print (value, TRUE);
+              g_printerr ("Recovered value:\n%s\ndoes not match given value\n%s\n",
+                          s,
+                          s1);
+              g_free (s);
+              g_free (s1);
+              g_assert_not_reached ();
+            }
+        }
+      g_object_unref (recovered_message);
     }
+
   g_object_unref (message);
-  g_object_unref (recovered_message);
 }
 
 static void
 message_serialize_basic (void)
 {
+  check_serialization (NULL, "");
+
   check_serialization (g_variant_new ("(sogybnqiuxtd)",
                                       "this is a string",
                                       "/this/is/a/path",
@@ -595,9 +651,9 @@ message_serialize_basic (void)
                                       -G_GINT64_CONSTANT(2)<<34,
                                       G_GUINT64_CONSTANT(0xffffffffffffffff),
                                       42.5),
-                       "value 0:   string: `this is a string'\n"
-                       "value 1:   object_path: `/this/is/a/path'\n"
-                       "value 2:   signature: `sad'\n"
+                       "value 0:   string: 'this is a string'\n"
+                       "value 1:   object_path: '/this/is/a/path'\n"
+                       "value 2:   signature: 'sad'\n"
                        "value 3:   byte: 0x2a\n"
                        "value 4:   bool: true\n"
                        "value 5:   int16: -42\n"
@@ -631,11 +687,11 @@ message_serialize_complex (void)
                        "    int32: 3\n"
                        "value 1:   array:\n"
                        "    dict_entry:\n"
-                       "      string: `one'\n"
-                       "      string: `white'\n"
+                       "      string: 'one'\n"
+                       "      string: 'white'\n"
                        "    dict_entry:\n"
-                       "      string: `two'\n"
-                       "      string: `black'\n");
+                       "      string: 'two'\n"
+                       "      string: 'black'\n");
 
   value = g_variant_parse (G_VARIANT_TYPE ("(sa{sv}as)"),
                            "('01234567890123456', {}, ['Something'])",
@@ -643,12 +699,385 @@ message_serialize_complex (void)
   g_assert_no_error (error);
   g_assert (value != NULL);
   check_serialization (value,
-                       "value 0:   string: `01234567890123456'\n"
+                       "value 0:   string: '01234567890123456'\n"
                        "value 1:   array:\n"
                        "value 2:   array:\n"
-                       "    string: `Something'\n");
+                       "    string: 'Something'\n");
+
+  /* https://bugzilla.gnome.org/show_bug.cgi?id=621838 */
+  check_serialization (g_variant_new_parsed ("(@aay [], {'cwd': <'/home/davidz/Hacking/glib/gio/tests'>})"),
+                       "value 0:   array:\n"
+                       "value 1:   array:\n"
+                       "    dict_entry:\n"
+                       "      string: 'cwd'\n"
+                       "      variant:\n"
+                       "        string: '/home/davidz/Hacking/glib/gio/tests'\n");
+
+#ifdef DBUS_TYPE_UNIX_FD
+  value = g_variant_parse (G_VARIANT_TYPE ("(hah)"),
+                           "(42, [43, 44])",
+                           NULL, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (value != NULL);
+  /* about (not extracted), see comment in DBUS_TYPE_UNIX_FD case in
+   * dbus_1_message_append() above.
+   */
+  check_serialization (value,
+                       "value 0:   unix-fd: (not extracted)\n"
+                       "value 1:   array:\n"
+                       "    unix-fd: (not extracted)\n"
+                       "    unix-fd: (not extracted)\n");
+#endif
+}
+
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+replace (char       *blob,
+         gsize       len,
+        const char *before,
+        const char *after)
+{
+  gsize i;
+  gsize slen = strlen (before) + 1;
+
+  g_assert_cmpuint (strlen (before), ==, strlen (after));
+  g_assert_cmpuint (len, >=, slen);
+
+  for (i = 0; i < (len - slen + 1); i++)
+    {
+      if (memcmp (blob + i, before, slen) == 0)
+        memcpy (blob + i, after, slen);
+    }
+}
+
+static void
+message_serialize_invalid (void)
+{
+  guint n;
+
+  /* Other things we could check (note that GDBus _does_ check for all
+   * these things - we just don't have test-suit coverage for it)
+   *
+   *  - array exceeding 64 MiB (2^26 bytes) - unfortunately libdbus-1 checks
+   *    this, e.g.
+   *
+   *      process 19620: arguments to dbus_message_iter_append_fixed_array() were incorrect,
+   *      assertion "n_elements <= DBUS_MAXIMUM_ARRAY_LENGTH / _dbus_type_get_alignment (element_type)"
+   *      failed in file dbus-message.c line 2344.
+   *      This is normally a bug in some application using the D-Bus library.
+   *      D-Bus not built with -rdynamic so unable to print a backtrace
+   *      Aborted (core dumped)
+   *
+   *  - message exceeding 128 MiB (2^27 bytes)
+   *
+   *  - endianness, message type, flags, protocol version
+   */
+
+  for (n = 0; n < 3; n++)
+    {
+      GDBusMessage *message;
+      GError *error;
+      DBusMessage *dbus_message;
+      char *blob;
+      int blob_len;
+      /* these are in pairs with matching length */
+      const gchar *valid_utf8_str = "this is valid...";
+      const gchar *invalid_utf8_str = "this is invalid\xff";
+      const gchar *valid_signature = "a{sv}a{sv}a{sv}aiai";
+      const gchar *invalid_signature = "not valid signature";
+      const gchar *valid_object_path = "/this/is/a/valid/dbus/object/path";
+      const gchar *invalid_object_path = "/this/is/not a valid object path!";
+
+      dbus_message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
+      dbus_message_set_serial (dbus_message, 0x41);
+      dbus_message_set_path (dbus_message, "/foo/bar");
+      dbus_message_set_member (dbus_message, "Member");
+      switch (n)
+        {
+        case 0:
+          /* invalid UTF-8 */
+          dbus_message_append_args (dbus_message,
+                                    DBUS_TYPE_STRING, &valid_utf8_str,
+                                    DBUS_TYPE_INVALID);
+          break;
+
+        case 1:
+          /* invalid object path */
+          dbus_message_append_args (dbus_message,
+                                    DBUS_TYPE_OBJECT_PATH, &valid_object_path,
+                                    DBUS_TYPE_INVALID);
+          break;
+
+        case 2:
+          /* invalid signature */
+          dbus_message_append_args (dbus_message,
+                                    DBUS_TYPE_SIGNATURE, &valid_signature,
+                                    DBUS_TYPE_INVALID);
+          break;
+
+        default:
+          g_assert_not_reached ();
+          break;
+        }
+      dbus_message_marshal (dbus_message, &blob, &blob_len);
+      /* hack up the message to be invalid by replacing each valid string
+       * with its invalid counterpart */
+      replace (blob, blob_len, valid_utf8_str, invalid_utf8_str);
+      replace (blob, blob_len, valid_object_path, invalid_object_path);
+      replace (blob, blob_len, valid_signature, invalid_signature);
+
+      error = NULL;
+      message = g_dbus_message_new_from_blob ((guchar *) blob,
+                                              blob_len,
+                                              G_DBUS_CAPABILITY_FLAGS_NONE,
+                                              &error);
+      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+      g_error_free (error);
+      g_assert (message == NULL);
+
+      dbus_free (blob);
+    }
+
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+message_serialize_header_checks (void)
+{
+  GDBusMessage *message;
+  GDBusMessage *reply;
+  GError *error;
+  guchar *blob;
+  gsize blob_size;
+
+  /*
+   * check we can't serialize messages with INVALID type
+   */
+  message = g_dbus_message_new ();
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: type is INVALID");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  g_object_unref (message);
+
+  /*
+   * check we can't serialize signal messages with INTERFACE, PATH or MEMBER unset / set to reserved value
+   */
+  message = g_dbus_message_new_signal ("/the/path", "The.Interface", "TheMember");
+  /* ----- */
+  /* interface NULL => error */
+  g_dbus_message_set_interface (message, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* interface reserved value => error */
+  g_dbus_message_set_interface (message, "org.freedesktop.DBus.Local");
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The INTERFACE header field is using the reserved value org.freedesktop.DBus.Local");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset interface */
+  g_dbus_message_set_interface (message, "The.Interface");
+  /* ----- */
+  /* path NULL => error */
+  g_dbus_message_set_path (message, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* path reserved value => error */
+  g_dbus_message_set_path (message, "/org/freedesktop/DBus/Local");
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The PATH header field is using the reserved value /org/freedesktop/DBus/Local");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset path */
+  g_dbus_message_set_path (message, "/the/path");
+  /* ----- */
+  /* member NULL => error */
+  g_dbus_message_set_member (message, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset member */
+  g_dbus_message_set_member (message, "TheMember");
+  /* ----- */
+  /* done */
+  g_object_unref (message);
+
+  /*
+   * check that we can't serialize method call messages with PATH or MEMBER unset
+   */
+  message = g_dbus_message_new_method_call (NULL, "/the/path", NULL, "TheMember");
+  /* ----- */
+  /* path NULL => error */
+  g_dbus_message_set_path (message, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset path */
+  g_dbus_message_set_path (message, "/the/path");
+  /* ----- */
+  /* member NULL => error */
+  g_dbus_message_set_member (message, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset member */
+  g_dbus_message_set_member (message, "TheMember");
+  /* ----- */
+  /* done */
+  g_object_unref (message);
+
+  /*
+   * check that we can't serialize method reply messages with REPLY_SERIAL unset
+   */
+  message = g_dbus_message_new_method_call (NULL, "/the/path", NULL, "TheMember");
+  g_dbus_message_set_serial (message, 42);
+  /* method reply */
+  reply = g_dbus_message_new_method_reply (message);
+  g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
+  g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_RETURN message: REPLY_SERIAL header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  g_object_unref (reply);
+  /* method error - first nuke ERROR_NAME, then REPLY_SERIAL */
+  reply = g_dbus_message_new_method_error (message, "Some.Error.Name", "the message");
+  g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
+  /* nuke ERROR_NAME */
+  g_dbus_message_set_error_name (reply, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  /* reset ERROR_NAME */
+  g_dbus_message_set_error_name (reply, "Some.Error.Name");
+  /* nuke REPLY_SERIAL */
+  g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
+  error = NULL;
+  blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
+  g_error_free (error);
+  g_assert (blob == NULL);
+  g_object_unref (reply);
+  g_object_unref (message);
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+message_parse_empty_arrays_of_arrays (void)
+{
+  GVariant *body;
+  GError *error = NULL;
+
+  g_test_bug ("673612");
+  /* These three-element array of empty arrays were previously read back as a
+   * two-element array of empty arrays, due to sometimes erroneously skipping
+   * four bytes to align for the eight-byte-aligned grandchild types (x and
+   * dict_entry).
+   */
+  body = g_variant_parse (G_VARIANT_TYPE ("(aaax)"),
+      "([@aax [], [], []],)", NULL, NULL, &error);
+  g_assert_no_error (error);
+  check_serialization (body,
+      "value 0:   array:\n"
+      "    array:\n"
+      "    array:\n"
+      "    array:\n");
+
+  body = g_variant_parse (G_VARIANT_TYPE ("(aaa{uu})"),
+      "([@aa{uu} [], [], []],)", NULL, NULL, &error);
+  g_assert_no_error (error);
+  check_serialization (body,
+      "value 0:   array:\n"
+      "    array:\n"
+      "    array:\n"
+      "    array:\n");
+
+  /* Due to the same bug, g_dbus_message_new_from_blob() would fail for this
+   * message because it would try to read past the end of the string. Hence,
+   * sending this to an application would make it fall off the bus. */
+  body = g_variant_parse (G_VARIANT_TYPE ("(a(aa{sv}as))"),
+      "([ ([], []),"
+      "   ([], []),"
+      "   ([], [])],)", NULL, NULL, &error);
+  g_assert_no_error (error);
+  check_serialization (body,
+      "value 0:   array:\n"
+      "    struct:\n"
+      "      array:\n"
+      "      array:\n"
+      "    struct:\n"
+      "      array:\n"
+      "      array:\n"
+      "    struct:\n"
+      "      array:\n"
+      "      array:\n");
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+test_double_array (void)
+{
+  GDBusConnection *conn;
+  GError *error = NULL;
+  GVariantBuilder builder;
+
+  g_test_bug ("732754");
+
+  conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+  g_assert_no_error (error);
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("ad"));
+  g_variant_builder_add (&builder, "d", (gdouble)0.0);
+  g_variant_builder_add (&builder, "d", (gdouble)8.0);
+  g_variant_builder_add (&builder, "d", (gdouble)22.0);
+  g_variant_builder_add (&builder, "d", (gdouble)0.0);
+
+  /*
+   * Some versions of glib encoded arrays of doubles wrong. Here we send such
+   * a message and check that we didn't get bumped from the connection.
+   */
+  g_dbus_connection_call_sync (conn, "org.freedesktop.DBus", "/path",
+                               "org.freedesktop.DBus", "InvalidNonExistantMethod",
+                               g_variant_new ("(@ad)", g_variant_builder_end (&builder)),
+                               NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &error);
+  g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
+
+  g_object_unref (conn);
+}
 
 /* ---------------------------------------------------------------------------------------------------- */
 
@@ -656,11 +1085,21 @@ int
 main (int   argc,
       char *argv[])
 {
-  g_type_init ();
+  setlocale (LC_ALL, "C");
+
   g_test_init (&argc, &argv, NULL);
+  g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
 
   g_test_add_func ("/gdbus/message-serialize-basic", message_serialize_basic);
   g_test_add_func ("/gdbus/message-serialize-complex", message_serialize_complex);
+  g_test_add_func ("/gdbus/message-serialize-invalid", message_serialize_invalid);
+  g_test_add_func ("/gdbus/message-serialize-header-checks", message_serialize_header_checks);
+
+  g_test_add_func ("/gdbus/message-parse-empty-arrays-of-arrays",
+      message_parse_empty_arrays_of_arrays);
+
+  g_test_add_func ("/gdbus/message-serialize/double-array", test_double_array);
+
   return g_test_run();
 }