Merge branch 'test-ip_mreq_source-android-only' into 'master'
[glib.git] / glib / tests / search-utils.c
blob54926d5a59aaff1719059cfd38c8c3b2c3fac4de
1 #include "config.h"
3 #include <locale.h>
4 #include <glib.h>
6 typedef struct
8 const gchar *string;
9 const gchar *prefix;
10 gboolean should_match;
11 } SearchTest;
13 static void
14 test_search (void)
16 SearchTest tests[] =
18 /* Test word separators and case */
19 { "Hello World", "he", TRUE },
20 { "Hello World", "wo", TRUE },
21 { "Hello World", "lo", FALSE },
22 { "Hello World", "ld", FALSE },
23 { "Hello-World", "wo", TRUE },
24 { "HelloWorld", "wo", FALSE },
26 /* Test composed chars (accentued letters) */
27 { "Jörgen", "jor", TRUE },
28 { "Gaëtan", "gaetan", TRUE },
29 { "élève", "ele", TRUE },
30 { "Azais", "AzaÏs", FALSE },
31 { "AzaÏs", "Azais", TRUE },
33 /* Test decomposed chars, they looks the same, but are actually
34 * composed of multiple unicodes */
35 { "Jorgen", "Jör", FALSE },
36 { "Jörgen", "jor", TRUE },
38 /* Turkish special case */
39 { "İstanbul", "ist", TRUE },
40 { "Diyarbakır", "diyarbakir", TRUE },
42 /* Multi words */
43 { "Xavier Claessens", "Xav Cla", TRUE },
44 { "Xavier Claessens", "Cla Xav", TRUE },
45 { "Foo Bar Baz", " b ", TRUE },
46 { "Foo Bar Baz", "bar bazz", FALSE },
48 { NULL, NULL, FALSE }
50 guint i;
52 setlocale(LC_ALL, "");
54 g_debug ("Started");
55 for (i = 0; tests[i].string != NULL; i ++)
57 gboolean match;
58 gboolean ok;
60 match = g_str_match_string (tests[i].prefix, tests[i].string, TRUE);
61 ok = (match == tests[i].should_match);
63 g_debug ("'%s' - '%s' %s: %s", tests[i].prefix, tests[i].string,
64 tests[i].should_match ? "should match" : "should NOT match",
65 ok ? "OK" : "FAILED");
67 g_assert (ok);
71 int
72 main (int argc,
73 char **argv)
75 g_test_init (&argc, &argv, NULL);
77 g_test_add_func ("/search", test_search);
79 return g_test_run ();