summaryrefslogtreecommitdiff
path: root/glib2-static/MR1414.patch
blob: 67da4f01c6dceb23517a72bd168d0d04c2589280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
diff --git a/glib/tests/search-utils.c b/glib/tests/search-utils.c
index 54926d5a59aaff1719059cfd38c8c3b2c3fac4de..7478a290a9e393170042ea8a91c9531fd0c197b6 100644
--- a/glib/tests/search-utils.c
+++ b/glib/tests/search-utils.c
@@ -7,74 +7,120 @@ typedef struct
 {
   const gchar *string;
   const gchar *prefix;
+  const gchar *locale;
   gboolean should_match;
 } SearchTest;
 
+/* Test word separators and case */
+SearchTest basic[] = {
+  { "Hello World", "he", "C", TRUE },
+  { "Hello World", "wo", "C", TRUE },
+  { "Hello World", "lo", "C", FALSE },
+  { "Hello World", "ld", "C", FALSE },
+  { "Hello-World", "wo", "C", TRUE },
+  { "HelloWorld", "wo", "C", FALSE },
+  { NULL, NULL, NULL, FALSE }
+};
+
+/* Test composed chars (accentued letters) */
+SearchTest composed[] = {
+  { "Jörgen", "jor", "sv_SE.UTF-8", TRUE },
+  { "Gaëtan", "gaetan", "fr_FR.UTF-8", TRUE },
+  { "élève", "ele", "fr_FR.UTF-8", TRUE },
+  { "Azais", "AzaÏs", "fr_FR.UTF-8", FALSE },
+  { "AzaÏs", "Azais", "fr_FR.UTF-8", TRUE },
+  { NULL, NULL, NULL, FALSE }
+};
+
+/* Test decomposed chars, they looks the same, but are actually
+ * composed of multiple unicodes */
+SearchTest decomposed[] = {
+  { "Jorgen", "Jör", "sv_SE.UTF-8", FALSE },
+  { "Jörgen", "jor", "sv_SE.UTF-8", TRUE },
+  { NULL, NULL, NULL, FALSE }
+};
+
+/* Turkish special case */
+SearchTest turkish[] = {
+  { "İstanbul", "ist", "tr_TR.UTF-8", TRUE },
+  { "Diyarbakır", "diyarbakir", "tr_TR.UTF-8", TRUE },
+  { NULL, NULL, NULL, FALSE }
+};
+
+/* Test unicode chars when no locale is available */
+SearchTest c_locale_unicode[] = {
+  { "Jörgen", "jor", "C", TRUE },
+  { "Jorgen", "Jör", "C", FALSE },
+  { "Jörgen", "jor", "C", TRUE },
+  { NULL, NULL, NULL, FALSE }
+};
+
+/* Multi words */
+SearchTest multi_words[] = {
+  { "Xavier Claessens", "Xav Cla", "C", TRUE },
+  { "Xavier Claessens", "Cla Xav", "C", TRUE },
+  { "Foo Bar Baz", "   b  ", "C", TRUE },
+  { "Foo Bar Baz", "bar bazz", "C", FALSE },
+  { NULL, NULL, NULL, FALSE }
+};
+
 static void
-test_search (void)
+test_search (gconstpointer d)
 {
-  SearchTest tests[] =
-    {
-      /* Test word separators and case */
-      { "Hello World", "he", TRUE },
-      { "Hello World", "wo", TRUE },
-      { "Hello World", "lo", FALSE },
-      { "Hello World", "ld", FALSE },
-      { "Hello-World", "wo", TRUE },
-      { "HelloWorld", "wo", FALSE },
-
-      /* Test composed chars (accentued letters) */
-      { "Jörgen", "jor", TRUE },
-      { "Gaëtan", "gaetan", TRUE },
-      { "élève", "ele", TRUE },
-      { "Azais", "AzaÏs", FALSE },
-      { "AzaÏs", "Azais", TRUE },
-
-      /* Test decomposed chars, they looks the same, but are actually
-       * composed of multiple unicodes */
-      { "Jorgen", "Jör", FALSE },
-      { "Jörgen", "jor", TRUE },
-
-      /* Turkish special case */
-      { "İstanbul", "ist", TRUE },
-      { "Diyarbakır", "diyarbakir", TRUE },
-
-      /* Multi words */
-      { "Xavier Claessens", "Xav Cla", TRUE },
-      { "Xavier Claessens", "Cla Xav", TRUE },
-      { "Foo Bar Baz", "   b  ", TRUE },
-      { "Foo Bar Baz", "bar bazz", FALSE },
-
-      { NULL, NULL, FALSE }
-    };
+  const SearchTest *tests = d;
   guint i;
-
-  setlocale(LC_ALL, "");
+  gboolean all_skipped = TRUE;
 
   g_debug ("Started");
-  for (i = 0; tests[i].string != NULL; i ++)
+
+  for (i = 0; tests[i].string != NULL; i++)
     {
       gboolean match;
       gboolean ok;
-
-      match = g_str_match_string (tests[i].prefix, tests[i].string, TRUE);
-      ok = (match == tests[i].should_match);
+      gboolean skipped;
+
+      if (setlocale (LC_ALL, tests[i].locale))
+        {
+          skipped = FALSE;
+          all_skipped = FALSE;
+          match = g_str_match_string (tests[i].prefix, tests[i].string, TRUE);
+          ok = (match == tests[i].should_match);
+        }
+      else
+        {
+          skipped = TRUE;
+          g_test_message ("Locale '%s' is unavailable", tests[i].locale);
+        }
 
       g_debug ("'%s' - '%s' %s: %s", tests[i].prefix, tests[i].string,
           tests[i].should_match ? "should match" : "should NOT match",
-          ok ? "OK" : "FAILED");
+          skipped ? "SKIPPED" : ok ? "OK" : "FAILED");
 
-      g_assert (ok);
+      g_assert (skipped || ok);
     }
+
+  if (all_skipped)
+    g_test_skip ("No locales for the test set are available");
 }
 
 int
 main (int argc,
       char **argv)
 {
+  gchar *user_locale;
+
   g_test_init (&argc, &argv, NULL);
 
-  g_test_add_func ("/search", test_search);
+  setlocale (LC_ALL, "");
+  user_locale = setlocale (LC_ALL, NULL);
+  g_debug ("Current user locale: %s", user_locale);
+
+  g_test_add_data_func ("/search/basic", basic, test_search);
+  g_test_add_data_func ("/search/composed", composed, test_search);
+  g_test_add_data_func ("/search/decomposed", decomposed, test_search);
+  g_test_add_data_func ("/search/turkish", turkish, test_search);
+  g_test_add_data_func ("/search/c_locale_unicode", c_locale_unicode, test_search);
+  g_test_add_data_func ("/search/multi_words", multi_words, test_search);
 
   return g_test_run ();
 }