mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
gapplication: reject actions without names
https://bugzilla.gnome.org/show_bug.cgi?id=756134
This commit is contained in:
parent
863bffdac7
commit
ee718d3526
@ -605,6 +605,8 @@ GSimpleAction *
|
||||
g_simple_action_new (const gchar *name,
|
||||
const GVariantType *parameter_type)
|
||||
{
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
return g_object_new (G_TYPE_SIMPLE_ACTION,
|
||||
"name", name,
|
||||
"parameter-type", parameter_type,
|
||||
|
@ -191,6 +191,13 @@ g_simple_action_group_add_action (GActionMap *action_map,
|
||||
GAction *old_action;
|
||||
|
||||
action_name = g_action_get_name (action);
|
||||
if (action_name == NULL)
|
||||
{
|
||||
g_critical ("The supplied action has no name. You must set the "
|
||||
"GAction:name property when creating an action.");
|
||||
return;
|
||||
}
|
||||
|
||||
old_action = g_hash_table_lookup (simple->priv->table, action_name);
|
||||
|
||||
if (old_action != action)
|
||||
|
@ -937,6 +937,30 @@ test_handle_local_options_passthrough (void)
|
||||
g_test_trap_assert_passed ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_api (void)
|
||||
{
|
||||
GApplication *app;
|
||||
GSimpleAction *action;
|
||||
|
||||
app = g_application_new ("org.gtk.TestApplication", 0);
|
||||
|
||||
/* add an action without a name */
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*assertion*failed*");
|
||||
action = g_simple_action_new (NULL, NULL);
|
||||
g_assert (action == NULL);
|
||||
g_test_assert_expected_messages ();
|
||||
|
||||
/* also, gapplication shouldn't accept actions without names */
|
||||
action = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*action has no name*");
|
||||
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
|
||||
g_test_assert_expected_messages ();
|
||||
|
||||
g_object_unref (action);
|
||||
g_object_unref (app);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@ -961,6 +985,7 @@ main (int argc, char **argv)
|
||||
g_test_add_func ("/gapplication/test-handle-local-options1", test_handle_local_options_success);
|
||||
g_test_add_func ("/gapplication/test-handle-local-options2", test_handle_local_options_failure);
|
||||
g_test_add_func ("/gapplication/test-handle-local-options3", test_handle_local_options_passthrough);
|
||||
g_test_add_func ("/gapplication/api", test_api);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user