mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +01:00
add testcase for GAction
fix some small bugs it found
This commit is contained in:
parent
8475d6d7d0
commit
8014e9c6e6
@ -141,7 +141,8 @@ g_action_set_property (GObject *object, guint prop_id,
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
@ -270,7 +271,8 @@ g_action_class_init (GActionClass *class)
|
||||
g_object_class_install_property (object_class, PROP_ENABLED,
|
||||
g_param_spec_boolean ("enabled", "enabled",
|
||||
"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:
|
||||
@ -292,7 +294,8 @@ g_action_class_init (GActionClass *class)
|
||||
g_object_class_install_property (object_class, PROP_STATE,
|
||||
g_param_spec_variant ("state", "state", "the state the action is in",
|
||||
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));
|
||||
}
|
||||
|
1
gio/tests/.gitignore
vendored
1
gio/tests/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
actions
|
||||
appinfo
|
||||
appinfo-test
|
||||
application
|
||||
|
@ -18,6 +18,7 @@ progs_ldadd = \
|
||||
$(top_builddir)/gio/libgio-2.0.la
|
||||
|
||||
TEST_PROGS += \
|
||||
actions \
|
||||
memory-input-stream \
|
||||
memory-output-stream \
|
||||
readwrite \
|
||||
@ -94,6 +95,8 @@ if OS_WIN32
|
||||
TEST_PROGS += win32-streams
|
||||
endif
|
||||
|
||||
actions_LDADD = $(progs_ldadd)
|
||||
|
||||
memory_input_stream_SOURCES = memory-input-stream.c
|
||||
memory_input_stream_LDADD = $(progs_ldadd)
|
||||
|
||||
|
81
gio/tests/actions.c
Normal file
81
gio/tests/actions.c
Normal 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 ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user