From 2c7ad39202242c83265dcd94e384b8ad12979d83 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 4 Jun 2012 18:56:44 +0200 Subject: gactionmuxer: don't crash when no global actions are given --- src/gactionmuxer.c | 13 ++++++++----- test/test-gactionmuxer.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/gactionmuxer.c b/src/gactionmuxer.c index 6c4d08b..ac3f8e4 100644 --- a/src/gactionmuxer.c +++ b/src/gactionmuxer.c @@ -227,13 +227,16 @@ g_action_muxer_list_actions (GActionGroup *group) all_actions = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), 8); - actions = g_action_group_list_actions (muxer->global_actions); - for (a = actions; *a; a++) + if (muxer->global_actions) { - gchar *name = g_strdup (*a); - g_array_append_val (all_actions, name); + actions = g_action_group_list_actions (muxer->global_actions); + for (a = actions; *a; a++) + { + gchar *name = g_strdup (*a); + g_array_append_val (all_actions, name); + } + g_strfreev (actions); } - g_strfreev (actions); g_hash_table_iter_init (&it, muxer->groups); while (g_hash_table_iter_next (&it, (gpointer *) &prefix, (gpointer *) &subgroup)) diff --git a/test/test-gactionmuxer.cpp b/test/test-gactionmuxer.cpp index fb32452..9f0ac3b 100644 --- a/test/test-gactionmuxer.cpp +++ b/test/test-gactionmuxer.cpp @@ -22,6 +22,21 @@ strv_contains (gchar **str_array, return FALSE; } +TEST(GActionMuxerTest, Empty) { + GActionMuxer *muxer; + gchar **actions; + + g_type_init (); + + muxer = g_action_muxer_new (); + + actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); + EXPECT_EQ (0, g_strv_length (actions)); + + g_strfreev (actions); + g_object_unref (muxer); +} + TEST(GActionMuxerTest, General) { const GActionEntry entries1[] = { { "one" }, { "two" }, { "three" } }; const GActionEntry entries2[] = { { "gb" }, { "es" }, { "fr" } }; -- cgit v1.2.3