[glib] gio/tests: port some stuff to g_test_expect_message()
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio/tests: port some stuff to g_test_expect_message()
- Date: Mon, 3 Sep 2012 12:57:00 +0000 (UTC)
commit 568f7377088ea7836217f0bec917cc77e1210742
Author: Dan Winship <danw gnome org>
Date: Fri Aug 24 17:11:17 2012 -0400
gio/tests: port some stuff to g_test_expect_message()
https://bugzilla.gnome.org/show_bug.cgi?id=682560
gio/tests/Makefile.am | 2 +-
gio/tests/actions.c | 78 ++++++++++++++++++--------------------------
gio/tests/gdbus-message.c | 42 ++++++++++++++----------
gio/tests/gsettings.c | 52 ++++++++++++++----------------
4 files changed, 81 insertions(+), 93 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 0ea9bf2..e352383 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -7,7 +7,7 @@ include $(top_srcdir)/Makefile.decl
SUBDIRS = gdbus-object-manager-example
INCLUDES = \
- -g \
+ -DG_LOG_DOMAIN=\"GLib-GIO\" \
$(gio_INCLUDES) \
$(GLIB_DEBUG_FLAGS) \
-I$(top_builddir)/gio \
diff --git a/gio/tests/actions.c b/gio/tests/actions.c
index f128033..e808bef 100644
--- a/gio/tests/actions.c
+++ b/gio/tests/actions.c
@@ -66,12 +66,10 @@ test_basic (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_action_activate (G_ACTION (action), g_variant_new_string ("xxx"));
- exit (0);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*g_variant_is_of_type*failed*");
+ g_action_activate (G_ACTION (action), g_variant_new_string ("xxx"));
+ g_test_assert_expected_messages ();
}
g_object_unref (action);
@@ -94,13 +92,10 @@ test_basic (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_action_activate (G_ACTION (action), NULL);
- exit (0);
- }
-
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*failed*");
+ g_action_activate (G_ACTION (action), NULL);
+ g_test_assert_expected_messages ();
}
g_object_unref (action);
@@ -260,12 +255,10 @@ test_stateful (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_simple_action_set_state (action, g_variant_new_int32 (123));
- exit (0);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*g_variant_is_of_type*failed*");
+ g_simple_action_set_state (action, g_variant_new_int32 (123));
+ g_test_assert_expected_messages ();
}
g_simple_action_set_state (action, g_variant_new_string ("hello"));
@@ -279,12 +272,10 @@ test_stateful (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_simple_action_set_state (action, g_variant_new_int32 (123));
- exit (0);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*failed*");
+ g_simple_action_set_state (action, g_variant_new_int32 (123));
+ g_test_assert_expected_messages ();
}
g_object_unref (action);
@@ -357,27 +348,22 @@ test_entries (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- const GActionEntry bad_type = {
- "bad-type", NULL, "ss"
- };
-
- g_simple_action_group_add_entries (actions, &bad_type, 1, NULL);
- exit (0);
- }
- g_test_trap_assert_failed ();
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- const GActionEntry bad_state = {
- "bad-state", NULL, NULL, "flse"
- };
-
- g_simple_action_group_add_entries (actions, &bad_state, 1, NULL);
- exit (0);
- }
- g_test_trap_assert_failed ();
+ const GActionEntry bad_type = {
+ "bad-type", NULL, "ss"
+ };
+ const GActionEntry bad_state = {
+ "bad-state", NULL, NULL, "flse"
+ };
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*not a valid GVariant type string*");
+ g_simple_action_group_add_entries (actions, &bad_type, 1, NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*could not parse*");
+ g_simple_action_group_add_entries (actions, &bad_state, 1, NULL);
+ g_test_assert_expected_messages ();
}
state = g_action_group_get_action_state (G_ACTION_GROUP (actions), "volume");
diff --git a/gio/tests/gdbus-message.c b/gio/tests/gdbus-message.c
index b3be200..13d5d0d 100644
--- a/gio/tests/gdbus-message.c
+++ b/gio/tests/gdbus-message.c
@@ -54,29 +54,35 @@ message_lock (void)
g_assert (g_dbus_message_get_locked (m));
g_assert_cmpint (count, ==, 1);
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_serial (m, 42);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_byte_order (m, G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_message_type (m, G_DBUS_MESSAGE_TYPE_METHOD_CALL);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_flags (m, G_DBUS_MESSAGE_FLAGS_NONE);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_body (m, NULL);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_serial (m, 42);
+ g_test_assert_expected_messages ();
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- g_dbus_message_set_header (m, 0, NULL);
- g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*Attempted to modify a locked message*");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_byte_order (m, G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_message_type (m, G_DBUS_MESSAGE_TYPE_METHOD_CALL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_flags (m, G_DBUS_MESSAGE_FLAGS_NONE);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_body (m, NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*Attempted to modify a locked message*");
+ g_dbus_message_set_header (m, 0, NULL);
+ g_test_assert_expected_messages ();
g_object_unref (m);
}
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 52e0d58..9628bad 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -55,14 +55,14 @@ test_basic (void)
if (!backend_set && g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- settings = g_settings_new ("org.gtk.test");
- g_settings_set (settings, "greeting", "i", 555);
- abort ();
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*g_settings_set_value*expects type*");
+ GSettings *tmp_settings = g_settings_new ("org.gtk.test");
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*g_settings_set_value*expects type*");
+ g_settings_set (tmp_settings, "greeting", "i", 555);
+ g_test_assert_expected_messages ();
+
+ g_object_unref (tmp_settings);
}
g_settings_get (settings, "greeting", "s", &str);
@@ -132,33 +132,29 @@ test_no_schema (void)
static void
test_wrong_type (void)
{
+ GSettings *settings;
+ gchar *str = NULL;
+
if (!g_test_undefined ())
return;
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- GSettings *settings;
- gchar *str = NULL;
-
- settings = g_settings_new ("org.gtk.test");
-
- g_settings_get (settings, "greeting", "o", &str);
+ settings = g_settings_new ("org.gtk.test");
- g_assert (str == NULL);
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*CRITICAL*");
+ g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
+ "*given value has a type of*");
+ g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
+ "*valid_format_string*");
+ g_settings_get (settings, "greeting", "o", &str);
+ g_test_assert_expected_messages ();
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- GSettings *settings;
+ g_assert (str == NULL);
- settings = g_settings_new ("org.gtk.test");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*expects type 's'*");
+ g_settings_set (settings, "greeting", "o", "/a/path");
+ g_test_assert_expected_messages ();
- g_settings_set (settings, "greeting", "o", "/a/path");
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*CRITICAL*");
+ g_object_unref (settings);
}
/* Check errors with explicit paths */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]