Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / tests / empathy-live-search-test.c
blob2fb3e48db68adddcb4ca816456f0e21bd42d637c
1 #include "config.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <tp-account-widgets/tpaw-live-search.h>
8 #include "test-helper.h"
10 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
11 #include "empathy-debug.h"
13 typedef struct
15 const gchar *string;
16 const gchar *prefix;
17 gboolean should_match;
18 } LiveSearchTest;
20 static void
21 test_live_search (void)
23 LiveSearchTest tests[] =
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 },
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 },
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 },
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 },
50 { NULL, NULL, FALSE }
52 guint i;
54 DEBUG ("Started");
55 for (i = 0; tests[i].string != NULL; i ++)
57 gboolean match;
58 gboolean ok;
60 match = tpaw_live_search_match_string (tests[i].string, tests[i].prefix);
61 ok = (match == tests[i].should_match);
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");
67 g_assert (ok);
71 int
72 main (int argc,
73 char **argv)
75 int result;
77 test_init (argc, argv);
79 g_test_add_func ("/live-search", test_live_search);
81 result = g_test_run ();
82 test_deinit ();
84 return result;