gio/tests: port some stuff to g_test_expect_message()

https://bugzilla.gnome.org/show_bug.cgi?id=682560
This commit is contained in:
Dan Winship 2012-08-24 17:11:17 -04:00
parent 039ecf2bc6
commit 568f737708
4 changed files with 79 additions and 91 deletions

View File

@ -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 \

View File

@ -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"
};
const GActionEntry bad_type = {
"bad-type", NULL, "ss"
};
const GActionEntry bad_state = {
"bad-state", NULL, NULL, "flse"
};
g_simple_action_group_add_entries (actions, &bad_type, 1, NULL);
exit (0);
}
g_test_trap_assert_failed ();
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 ();
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 ();
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");

View File

@ -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*");
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_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*");
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 ();
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*");
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 ();
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*");
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 ();
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_body (m, NULL);
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_header (m, 0, NULL);
g_test_assert_expected_messages ();
g_object_unref (m);
}

View File

@ -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");
settings = g_settings_new ("org.gtk.test");
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 ();
g_settings_get (settings, "greeting", "o", &str);
g_assert (str == NULL);
g_assert (str == NULL);
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*CRITICAL*");
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 ();
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings;
settings = g_settings_new ("org.gtk.test");
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 */