[gnome-settings-daemon] keyboard: Add tests for previous commit
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] keyboard: Add tests for previous commit
- Date: Fri, 5 Oct 2012 11:56:54 +0000 (UTC)
commit 533f9c2970951bc00d16ce54f7e7dfb222c5ee33
Author: Rui Matos <tiagomatos gmail com>
Date: Thu Sep 27 15:59:42 2012 +0200
keyboard: Add tests for previous commit
https://bugzilla.gnome.org/show_bug.cgi?id=684855
plugins/keyboard/Makefile.am | 16 ++--
plugins/keyboard/test-keyboard-ibus-utils.c | 116 +++++++++++++++++++++++++++
plugins/keyboard/test-make-xkb-source-id.c | 23 -----
3 files changed, 124 insertions(+), 31 deletions(-)
---
diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am
index 445dd1f..9c5f395 100644
--- a/plugins/keyboard/Makefile.am
+++ b/plugins/keyboard/Makefile.am
@@ -66,14 +66,14 @@ plugin_in_files = \
plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin)
if HAVE_IBUS
-noinst_PROGRAMS = test-make-xkb-source-id
-test_make_xkb_source_id_SOURCES = test-make-xkb-source-id.c
-test_make_xkb_source_id_CFLAGS = $(libkeyboard_la_CFLAGS)
-test_make_xkb_source_id_CPPFLAGS = $(libkeyboard_la_CPPFLAGS)
-test_make_xkb_source_id_LDADD = $(libkeyboard_la_LIBADD) $(top_builddir)/gnome-settings-daemon/libgsd.la
-
-check-local: test-make-xkb-source-id
- $(builddir)/test-make-xkb-source-id > /dev/null
+noinst_PROGRAMS = test-keyboard-ibus-utils
+test_keyboard_ibus_utils_SOURCES = test-keyboard-ibus-utils.c
+test_keyboard_ibus_utils_CFLAGS = $(libkeyboard_la_CFLAGS)
+test_keyboard_ibus_utils_CPPFLAGS = $(libkeyboard_la_CPPFLAGS)
+test_keyboard_ibus_utils_LDADD = $(libkeyboard_la_LIBADD) $(top_builddir)/gnome-settings-daemon/libgsd.la
+
+check-local: test-keyboard-ibus-utils
+ $(builddir)/test-keyboard-ibus-utils > /dev/null
endif
libexec_PROGRAMS += gsd-input-sources-switcher
diff --git a/plugins/keyboard/test-keyboard-ibus-utils.c b/plugins/keyboard/test-keyboard-ibus-utils.c
new file mode 100644
index 0000000..0bfc2e5
--- /dev/null
+++ b/plugins/keyboard/test-keyboard-ibus-utils.c
@@ -0,0 +1,116 @@
+#include "gsd-keyboard-manager.c"
+
+static void
+test_make_xkb_source_id (void)
+{
+ gint i;
+ const gchar *test_strings[][2] = {
+ /* input output */
+ { "xkb:aa:bb:cc", "aa+bb" },
+ { "xkb:aa:bb:", "aa+bb" },
+ { "xkb:aa::cc", "aa" },
+ { "xkb:aa::", "aa" },
+ { "xkb::bb:cc", "+bb" },
+ { "xkb::bb:", "+bb" },
+ { "xkb:::cc", "" },
+ { "xkb:::", "" },
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
+ g_assert_cmpstr (make_xkb_source_id (test_strings[i][0]), ==, test_strings[i][1]);
+}
+
+static void
+test_layout_from_ibus_layout (void)
+{
+ gint i;
+ const gchar *test_strings[][2] = {
+ /* input output */
+ { "", "" },
+ { "a", "a" },
+ { "a(", "a" },
+ { "a[", "a" },
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
+ g_assert_cmpstr (layout_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]);
+}
+
+static void
+test_variant_from_ibus_layout (void)
+{
+ gint i;
+ const gchar *test_strings[][2] = {
+ /* input output */
+ { "", NULL },
+ { "a", NULL },
+ { "(", NULL },
+ { "()", "" },
+ { "(b)", "b" },
+ { "a(", NULL },
+ { "a()", "" },
+ { "a(b)", "b" },
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
+ g_assert_cmpstr (variant_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]);
+}
+
+static void
+test_options_from_ibus_layout (void)
+{
+ gint i, j;
+ gchar *output_0[] = {
+ NULL
+ };
+ gchar *output_1[] = {
+ "",
+ NULL
+ };
+ gchar *output_2[] = {
+ "b",
+ NULL
+ };
+ gchar *output_3[] = {
+ "b", "",
+ NULL
+ };
+ gchar *output_4[] = {
+ "b", "c",
+ NULL
+ };
+ const gpointer tests[][2] = {
+ /* input output */
+ { "", NULL },
+ { "a", NULL },
+ { "a[", output_0 },
+ { "a[]", output_1 },
+ { "a[b]", output_2 },
+ { "a[b,]", output_3 },
+ { "a[b,c]", output_4 },
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (tests); ++i) {
+ if (tests[i][1] == NULL) {
+ g_assert (options_from_ibus_layout (tests[i][0]) == NULL);
+ } else {
+ gchar **strv_a = options_from_ibus_layout (tests[i][0]);
+ gchar **strv_b = tests[i][1];
+
+ g_assert (g_strv_length (strv_a) == g_strv_length (strv_b));
+ for (j = 0; j < g_strv_length (strv_a); ++j)
+ g_assert_cmpstr (strv_a[j], ==, strv_b[j]);
+ }
+ }
+}
+
+int
+main (void)
+{
+ test_make_xkb_source_id ();
+ test_layout_from_ibus_layout ();
+ test_variant_from_ibus_layout ();
+ test_options_from_ibus_layout ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]