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