Update tests for new truncate behavior
[platform/upstream/glib.git] / gio / tests / gdbus-error.c
index 3427710..96f3a76 100644 (file)
@@ -1,6 +1,6 @@
 /* GLib testing framework examples and tests
  *
- * Copyright (C) 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2008-2010 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -180,6 +180,76 @@ test_transparent_gerror (void)
   check_transparent_gerror (G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
 }
 
+typedef enum
+{
+  TEST_ERROR_FAILED,
+  TEST_ERROR_BLA
+} TestError;
+
+GDBusErrorEntry test_error_entries[] =
+{
+  { TEST_ERROR_FAILED, "org.gtk.test.Error.Failed" },
+  { TEST_ERROR_BLA,    "org.gtk.test.Error.Bla"    }
+};
+
+static void
+test_register_error (void)
+{
+  gsize test_error_quark = 0;
+  gboolean res;
+  gchar *msg;
+  GError *error;
+
+  g_dbus_error_register_error_domain ("test-error-quark",
+                                      &test_error_quark,
+                                      test_error_entries,
+                                      G_N_ELEMENTS (test_error_entries));
+  g_assert_cmpint (test_error_quark, !=, 0);
+
+  error = g_dbus_error_new_for_dbus_error ("org.gtk.test.Error.Failed", "Failed");
+  g_assert_error (error, test_error_quark, TEST_ERROR_FAILED);
+  res = g_dbus_error_is_remote_error (error);
+  msg = g_dbus_error_get_remote_error (error);
+  g_assert (res);
+  g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Failed");
+  res = g_dbus_error_strip_remote_error (error);
+  g_assert (res);
+  g_assert_cmpstr (error->message, ==, "Failed");
+  g_clear_error (&error);
+  g_free (msg);
+
+  g_dbus_error_set_dbus_error (&error, "org.gtk.test.Error.Failed", "Failed again", "Prefix %d", 1);
+  res = g_dbus_error_is_remote_error (error);
+  msg = g_dbus_error_get_remote_error (error);
+  g_assert (res);
+  g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Failed");
+  res = g_dbus_error_strip_remote_error (error);
+  g_assert (res);
+  g_assert_cmpstr (error->message, ==, "Prefix 1: Failed again");
+  g_clear_error (&error);
+  g_free (msg);
+
+  error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_EMPTY, "Not Empty");
+  res = g_dbus_error_is_remote_error (error);
+  msg = g_dbus_error_get_remote_error (error);
+  g_assert (!res);
+  g_assert_cmpstr (msg, ==, NULL);
+  res = g_dbus_error_strip_remote_error (error);
+  g_assert (!res);
+  g_assert_cmpstr (error->message, ==, "Not Empty");
+  g_clear_error (&error);
+
+  error = g_error_new_literal (test_error_quark, TEST_ERROR_BLA, "Bla");
+  msg = g_dbus_error_encode_gerror (error);
+  g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Bla");
+  g_free (msg);
+  g_clear_error (&error);
+
+  res = g_dbus_error_unregister_error (test_error_quark,
+                                       TEST_ERROR_BLA, "org.gtk.test.Error.Bla");
+  g_assert (res);
+}
+
 
 /* ---------------------------------------------------------------------------------------------------- */
 
@@ -187,12 +257,12 @@ int
 main (int   argc,
       char *argv[])
 {
-  g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/gdbus/registered-errors", test_registered_errors);
   g_test_add_func ("/gdbus/unregistered-errors", test_unregistered_errors);
   g_test_add_func ("/gdbus/transparent-gerror", test_transparent_gerror);
+  g_test_add_func ("/gdbus/register-error", test_register_error);
 
   return g_test_run();
 }