mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 16:38:54 +02:00
Add testcase for GSimpleAction::change-state
This commit is contained in:
committed by
Javier Jardon
parent
9a23ef6c2d
commit
d5915a4be3
@@ -328,37 +328,49 @@ test_entries (void)
|
|||||||
g_object_unref (actions);
|
g_object_unref (actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
activate_quit (GSimpleAction *simple,
|
|
||||||
GVariant *parameter,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
/* /actions/change-state */
|
||||||
activate_print_string (GSimpleAction *simple,
|
static void
|
||||||
GVariant *parameter,
|
change_volume_state (GSimpleAction *action,
|
||||||
gpointer user_data)
|
GVariant *value,
|
||||||
{
|
gpointer user_data)
|
||||||
g_print ("%s\n", g_variant_get_string (parameter, NULL));
|
{
|
||||||
}
|
gint requested;
|
||||||
|
|
||||||
static GActionGroup *
|
requested = g_variant_get_int32 (value);
|
||||||
create_action_group (void)
|
|
||||||
{
|
|
||||||
const GActionEntry entries[] = {
|
|
||||||
{ "quit", activate_quit },
|
|
||||||
{ "print-string", activate_print_string, "s" }
|
|
||||||
};
|
|
||||||
GSimpleActionGroup *group;
|
|
||||||
|
|
||||||
group = g_simple_action_group_new ();
|
/* Volume only goes from 0 to 10 */
|
||||||
g_simple_action_group_add_entries (group, entries, G_N_ELEMENTS (entries), NULL);
|
if (0 <= requested && requested <= 10)
|
||||||
|
g_simple_action_set_state (action, value);
|
||||||
|
}
|
||||||
|
|
||||||
return G_ACTION_GROUP (group);
|
static void
|
||||||
}
|
test_change_state (void)
|
||||||
|
{
|
||||||
|
GSimpleAction *action;
|
||||||
|
GVariant *state;
|
||||||
|
|
||||||
|
action = g_simple_action_new_stateful ("volume", NULL,
|
||||||
|
g_variant_new_int32 (0));
|
||||||
|
g_signal_connect (action, "change-state",
|
||||||
|
G_CALLBACK (change_volume_state), NULL);
|
||||||
|
|
||||||
|
state = g_action_get_state (G_ACTION (action));
|
||||||
|
g_assert_cmpint (g_variant_get_int32 (state), ==, 0);
|
||||||
|
g_variant_unref (state);
|
||||||
|
|
||||||
|
/* should change */
|
||||||
|
g_action_change_state (G_ACTION (action), g_variant_new_int32 (7));
|
||||||
|
state = g_action_get_state (G_ACTION (action));
|
||||||
|
g_assert_cmpint (g_variant_get_int32 (state), ==, 7);
|
||||||
|
g_variant_unref (state);
|
||||||
|
|
||||||
|
/* should not change */
|
||||||
|
g_action_change_state (G_ACTION (action), g_variant_new_int32 (11));
|
||||||
|
state = g_action_get_state (G_ACTION (action));
|
||||||
|
g_assert_cmpint (g_variant_get_int32 (state), ==, 7);
|
||||||
|
g_variant_unref (state);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
@@ -370,6 +382,7 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/actions/simplegroup", test_simple_group);
|
g_test_add_func ("/actions/simplegroup", test_simple_group);
|
||||||
g_test_add_func ("/actions/stateful", test_stateful);
|
g_test_add_func ("/actions/stateful", test_stateful);
|
||||||
g_test_add_func ("/actions/entries", test_entries);
|
g_test_add_func ("/actions/entries", test_entries);
|
||||||
|
g_test_add_func ("/actions/change-state", test_change_state);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user