]> git.0d.be Git - empathy.git/blob - tests/empathy-live-search-test.c
Updated Dutch translation master
[empathy.git] / tests / empathy-live-search-test.c
1 #include "config.h"
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <tp-account-widgets/tpaw-live-search.h>
7
8 #include "test-helper.h"
9
10 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
11 #include "empathy-debug.h"
12
13 typedef struct
14 {
15   const gchar *string;
16   const gchar *prefix;
17   gboolean should_match;
18 } LiveSearchTest;
19
20 static void
21 test_live_search (void)
22 {
23   LiveSearchTest tests[] =
24     {
25       /* Test word separators and case */
26       { "Hello World", "he", TRUE },
27       { "Hello World", "wo", TRUE },
28       { "Hello World", "lo", FALSE },
29       { "Hello World", "ld", FALSE },
30       { "Hello-World", "wo", TRUE },
31       { "HelloWorld", "wo", FALSE },
32
33       /* Test composed chars (accentued letters) */
34       { "Jörgen", "jor", TRUE },
35       { "Gaëtan", "gaetan", TRUE },
36       { "élève", "ele", TRUE },
37       { "Azais", "AzaÏs", TRUE },
38
39       /* Test decomposed chars, they looks the same, but are actually
40        * composed of multiple unicodes */
41       { "Jorgen", "Jör", TRUE },
42       { "Jörgen", "jor", TRUE },
43
44       /* Multi words */
45       { "Xavier Claessens", "Xav Cla", TRUE },
46       { "Xavier Claessens", "Cla Xav", TRUE },
47       { "Foo Bar Baz", "   b  ", TRUE },
48       { "Foo Bar Baz", "bar bazz", FALSE },
49
50       { NULL, NULL, FALSE }
51     };
52   guint i;
53
54   DEBUG ("Started");
55   for (i = 0; tests[i].string != NULL; i ++)
56     {
57       gboolean match;
58       gboolean ok;
59
60       match = tpaw_live_search_match_string (tests[i].string, tests[i].prefix);
61       ok = (match == tests[i].should_match);
62
63       DEBUG ("'%s' - '%s' %s: %s", tests[i].string, tests[i].prefix,
64           tests[i].should_match ? "should match" : "should NOT match",
65           ok ? "OK" : "FAILED");
66
67       g_assert (ok);
68     }
69 }
70
71 int
72 main (int argc,
73     char **argv)
74 {
75   int result;
76
77   test_init (argc, argv);
78
79   g_test_add_func ("/live-search", test_live_search);
80
81   result = g_test_run ();
82   test_deinit ();
83
84   return result;
85 }