~ctf/unity-settings-daemon/bug1389099_mic_volume_icons

« back to all changes in this revision

Viewing changes to plugins/keyboard/test-keyboard-ibus-utils.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-02-07 11:44:36 UTC
  • Revision ID: package-import@ubuntu.com-20140207114436-7t5u3yvwc4ul7w3e
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gsd-keyboard-manager.c"
 
2
 
 
3
static void
 
4
test_layout_from_ibus_layout (void)
 
5
{
 
6
        gint i;
 
7
        const gchar *test_strings[][2] = {
 
8
                /* input                output */
 
9
                { "",                   "" },
 
10
                { "a",                  "a" },
 
11
                { "a(",                 "a" },
 
12
                { "a[",                 "a" },
 
13
        };
 
14
 
 
15
        for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
 
16
                g_assert_cmpstr (layout_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]);
 
17
}
 
18
 
 
19
static void
 
20
test_variant_from_ibus_layout (void)
 
21
{
 
22
        gint i;
 
23
        const gchar *test_strings[][2] = {
 
24
                /* input                output */
 
25
                { "",                   NULL },
 
26
                { "a",                  NULL },
 
27
                { "(",                  NULL },
 
28
                { "()",                 "" },
 
29
                { "(b)",                "b" },
 
30
                { "a(",                 NULL },
 
31
                { "a()",                "" },
 
32
                { "a(b)",               "b" },
 
33
        };
 
34
 
 
35
        for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
 
36
                g_assert_cmpstr (variant_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]);
 
37
}
 
38
 
 
39
static void
 
40
test_options_from_ibus_layout (void)
 
41
{
 
42
        gint i, j;
 
43
        gchar *output_0[] = {
 
44
                NULL
 
45
        };
 
46
        gchar *output_1[] = {
 
47
                "",
 
48
                NULL
 
49
        };
 
50
        gchar *output_2[] = {
 
51
                "b",
 
52
                NULL
 
53
        };
 
54
        gchar *output_3[] = {
 
55
                "b", "",
 
56
                NULL
 
57
        };
 
58
        gchar *output_4[] = {
 
59
                "b", "c",
 
60
                NULL
 
61
        };
 
62
        const gpointer tests[][2] = {
 
63
                /* input                output */
 
64
                { "",                   NULL },
 
65
                { "a",                  NULL },
 
66
                { "a[",                 output_0 },
 
67
                { "a[]",                output_1 },
 
68
                { "a[b]",               output_2 },
 
69
                { "a[b,]",              output_3 },
 
70
                { "a[b,c]",             output_4 },
 
71
        };
 
72
 
 
73
        for (i = 0; i < G_N_ELEMENTS (tests); ++i) {
 
74
                if (tests[i][1] == NULL) {
 
75
                        g_assert (options_from_ibus_layout (tests[i][0]) == NULL);
 
76
                } else {
 
77
                        gchar **strv_a = options_from_ibus_layout (tests[i][0]);
 
78
                        gchar **strv_b = tests[i][1];
 
79
 
 
80
                        g_assert (g_strv_length (strv_a) == g_strv_length (strv_b));
 
81
                        for (j = 0; j < g_strv_length (strv_a); ++j)
 
82
                                g_assert_cmpstr (strv_a[j], ==, strv_b[j]);
 
83
                }
 
84
        }
 
85
}
 
86
 
 
87
int
 
88
main (void)
 
89
{
 
90
        test_layout_from_ibus_layout ();
 
91
        test_variant_from_ibus_layout ();
 
92
        test_options_from_ibus_layout ();
 
93
 
 
94
        return 0;
 
95
}