aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Makefile.am13
-rw-r--r--test/test-gactionmuxer.cpp76
2 files changed, 88 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 977c1ed..f1ab408 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,6 +1,6 @@
check_LIBRARIES = libgtest.a
-check_PROGRAMS = test-gtest
+check_PROGRAMS = test-gtest test-gactionmuxer
TESTS =
@@ -31,6 +31,17 @@ test_gtest_LDADD = \
libgtest.a
+TESTS += test-gactionmuxer
+
+test_gactionmuxer_SOURCES = \
+ test-gactionmuxer.cpp \
+ $(top_srcdir)/src/gactionmuxer.c \
+ $(top_srcdir)/src/gactionmuxer.h
+
+test_gactionmuxer_CPPFLAGS = $(APPLET_CFLAGS) $(AM_CPPFLAGS)
+test_gactionmuxer_LDADD = $(APPLET_LIBS) libgtest.a
+
+
######################################
# Lib containing code under test
######################################
diff --git a/test/test-gactionmuxer.cpp b/test/test-gactionmuxer.cpp
new file mode 100644
index 0000000..fb32452
--- /dev/null
+++ b/test/test-gactionmuxer.cpp
@@ -0,0 +1,76 @@
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <gtest/gtest.h>
+
+extern "C" {
+#include "app-section.h"
+#include "gactionmuxer.h"
+}
+
+static gboolean
+strv_contains (gchar **str_array,
+ const gchar *str)
+{
+ gchar **it;
+
+ for (it = str_array; *it; it++) {
+ if (!g_strcmp0 (*it, str))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+TEST(GActionMuxerTest, General) {
+ const GActionEntry entries1[] = { { "one" }, { "two" }, { "three" } };
+ const GActionEntry entries2[] = { { "gb" }, { "es" }, { "fr" } };
+ const GActionEntry entries3[] = { { "foo" }, { "bar" } };
+ GSimpleActionGroup *group1;
+ GSimpleActionGroup *group2;
+ GSimpleActionGroup *group3;
+ GActionMuxer *muxer;
+ gchar **actions;
+
+ g_type_init ();
+
+ group1 = g_simple_action_group_new ();
+ g_simple_action_group_add_entries (group1,
+ entries1,
+ G_N_ELEMENTS (entries1),
+ NULL);
+
+ group2 = g_simple_action_group_new ();
+ g_simple_action_group_add_entries (group2,
+ entries2,
+ G_N_ELEMENTS (entries2),
+ NULL);
+
+ group3 = g_simple_action_group_new ();
+ g_simple_action_group_add_entries (group3,
+ entries3,
+ G_N_ELEMENTS (entries3),
+ NULL);
+
+ muxer = g_action_muxer_new ();
+ g_action_muxer_insert (muxer, "first", G_ACTION_GROUP (group1));
+ g_action_muxer_insert (muxer, "second", G_ACTION_GROUP (group2));
+ g_action_muxer_insert (muxer, NULL, G_ACTION_GROUP (group3));
+
+ actions = g_action_group_list_actions (G_ACTION_GROUP (muxer));
+ EXPECT_EQ (8, g_strv_length (actions));
+ EXPECT_TRUE (strv_contains (actions, "first.one"));
+ EXPECT_TRUE (strv_contains (actions, "first.two"));
+ EXPECT_TRUE (strv_contains (actions, "first.three"));
+ EXPECT_TRUE (strv_contains (actions, "second.gb"));
+ EXPECT_TRUE (strv_contains (actions, "second.es"));
+ EXPECT_TRUE (strv_contains (actions, "second.fr"));
+ EXPECT_TRUE (strv_contains (actions, "foo"));
+ EXPECT_TRUE (strv_contains (actions, "bar"));
+ g_strfreev (actions);
+
+ g_object_unref (muxer);
+ g_object_unref (group1);
+ g_object_unref (group2);
+ g_object_unref (group3);
+}