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