diff --git a/gio/gsimpleaction.c b/gio/gsimpleaction.c index e9eb3603d..2c0bc85a4 100644 --- a/gio/gsimpleaction.c +++ b/gio/gsimpleaction.c @@ -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, diff --git a/gio/gsimpleactiongroup.c b/gio/gsimpleactiongroup.c index c5422511c..c62e66f3d 100644 --- a/gio/gsimpleactiongroup.c +++ b/gio/gsimpleactiongroup.c @@ -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) diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c index 42f76af35..33d757e6f 100644 --- a/gio/tests/gapplication.c +++ b/gio/tests/gapplication.c @@ -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 (); }