add testcase for GAction

fix some small bugs it found
This commit is contained in:
Ryan Lortie 2010-08-18 01:55:48 -04:00
parent 8475d6d7d0
commit 8014e9c6e6
4 changed files with 91 additions and 3 deletions

View File

@ -141,7 +141,8 @@ g_action_set_property (GObject *object, guint prop_id,
break; break;
case PROP_STATE: case PROP_STATE:
g_action_set_state (action, g_value_get_variant (value)); if (g_value_get_variant (value))
g_action_set_state (action, g_value_get_variant (value));
break; break;
default: default:
@ -270,7 +271,8 @@ g_action_class_init (GActionClass *class)
g_object_class_install_property (object_class, PROP_ENABLED, g_object_class_install_property (object_class, PROP_ENABLED,
g_param_spec_boolean ("enabled", "enabled", g_param_spec_boolean ("enabled", "enabled",
"if the action can be activated", TRUE, "if the action can be activated", TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/** /**
* GAction:state-type: * GAction:state-type:
@ -292,7 +294,8 @@ g_action_class_init (GActionClass *class)
g_object_class_install_property (object_class, PROP_STATE, g_object_class_install_property (object_class, PROP_STATE,
g_param_spec_variant ("state", "state", "the state the action is in", g_param_spec_variant ("state", "state", "the state the action is in",
G_VARIANT_TYPE_ANY, NULL, G_VARIANT_TYPE_ANY, NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_type_class_add_private (class, sizeof (GActionPrivate)); g_type_class_add_private (class, sizeof (GActionPrivate));
} }

View File

@ -1,3 +1,4 @@
actions
appinfo appinfo
appinfo-test appinfo-test
application application

View File

@ -18,6 +18,7 @@ progs_ldadd = \
$(top_builddir)/gio/libgio-2.0.la $(top_builddir)/gio/libgio-2.0.la
TEST_PROGS += \ TEST_PROGS += \
actions \
memory-input-stream \ memory-input-stream \
memory-output-stream \ memory-output-stream \
readwrite \ readwrite \
@ -94,6 +95,8 @@ if OS_WIN32
TEST_PROGS += win32-streams TEST_PROGS += win32-streams
endif endif
actions_LDADD = $(progs_ldadd)
memory_input_stream_SOURCES = memory-input-stream.c memory_input_stream_SOURCES = memory-input-stream.c
memory_input_stream_LDADD = $(progs_ldadd) memory_input_stream_LDADD = $(progs_ldadd)

81
gio/tests/actions.c Normal file
View File

@ -0,0 +1,81 @@
#include <gio/gio.h>
#include <stdlib.h>
typedef struct
{
GVariant *params;
gboolean did_run;
} Activation;
static void
activate (GAction *action,
GVariant *parameter,
gpointer user_data)
{
Activation *activation = user_data;
if (parameter)
activation->params = g_variant_ref (parameter);
else
activation->params = NULL;
activation->did_run = TRUE;
}
static void
test_basic (void)
{
Activation a = { 0, };
GAction *action;
action = g_action_new ("foo", NULL);
g_signal_connect (action, "activate", G_CALLBACK (activate), &a);
g_assert (!a.did_run);
g_action_activate (action, NULL);
g_assert (a.did_run);
a.did_run = FALSE;
g_action_set_enabled (action, FALSE);
g_action_activate (action, NULL);
g_assert (!a.did_run);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_action_activate (action, g_variant_new_string ("xxx"));
exit (0);
}
g_test_trap_assert_failed ();
g_object_unref (action);
g_assert (!a.did_run);
action = g_action_new ("foo", G_VARIANT_TYPE_STRING);
g_signal_connect (action, "activate", G_CALLBACK (activate), &a);
g_assert (!a.did_run);
g_action_activate (action, g_variant_new_string ("Hello world"));
g_assert (a.did_run);
g_assert_cmpstr (g_variant_get_string (a.params, NULL), ==, "Hello world");
g_variant_unref (a.params);
a.did_run = FALSE;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_action_activate (action, NULL);
exit (0);
}
g_test_trap_assert_failed ();
g_object_unref (action);
g_assert (!a.did_run);
}
int
main (int argc, char **argv)
{
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/actions/basic", test_basic);
return g_test_run ();
}