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