2
Test code for highlighting functions
4
Copyright 2012 Canonical Ltd.
6
This program is free software: you can redistribute it and/or modify it
7
under the terms of the GNU General Public License version 3, as published
8
by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranties of
12
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
PURPOSE. See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include <glib-object.h>
24
#include "hudresult.h"
25
#include "hudsettings.h"
27
/* hardcode some parameters so the test doesn't fail if the user
28
* has bogus things in GSettings.
30
HudSettings hud_settings = {
31
.indicator_penalty = 50,
34
.end_drop_penalty = 1,
40
add_item_to_hud_string_list (const gchar *item, HudStringList *stringlist)
42
HudStringList *new_list = hud_string_list_cons (item, stringlist);
43
hud_string_list_unref (stringlist);
48
test_result_highlighting_base (void)
51
HudStringList *item_tokens;
52
HudTokenList *search_tokens;
54
item_tokens = add_item_to_hud_string_list ("foo", NULL);
55
item_tokens = add_item_to_hud_string_list ("bar", item_tokens);
56
item_tokens = add_item_to_hud_string_list ("mango", item_tokens);
58
search_tokens = hud_token_list_new_from_string ("bar");
60
item = hud_item_new (item_tokens, NULL, NULL, TRUE);
62
HudResult *result = hud_result_new (item, search_tokens, 0);
64
g_assert (strcmp (hud_result_get_html_description (result), "foo > <b>bar</b> > mango") == 0);
66
hud_token_list_free (search_tokens);
67
g_object_unref (result);
68
g_object_unref (item);
69
hud_string_list_unref (item_tokens);
75
test_result_highlighting_baseutf8 (void)
78
HudStringList *item_tokens;
79
HudTokenList *search_tokens;
81
item_tokens = add_item_to_hud_string_list ("foo", NULL);
82
item_tokens = add_item_to_hud_string_list ("ẃêỳᶉ∂", item_tokens);
83
item_tokens = add_item_to_hud_string_list ("mango", item_tokens);
85
search_tokens = hud_token_list_new_from_string ("ẃêỳᶉ∂");
87
item = hud_item_new (item_tokens, NULL, NULL, TRUE);
89
HudResult *result = hud_result_new (item, search_tokens, 0);
91
g_assert (strcmp (hud_result_get_html_description (result), "foo > <b>ẃêỳᶉ∂</b> > mango") == 0);
93
hud_token_list_free (search_tokens);
94
g_object_unref (result);
95
g_object_unref (item);
96
hud_string_list_unref (item_tokens);
102
test_result_highlighting_gt (void)
105
HudStringList *item_tokens;
106
HudTokenList *search_tokens;
108
item_tokens = add_item_to_hud_string_list ("foo", NULL);
109
item_tokens = add_item_to_hud_string_list ("bar", item_tokens);
110
item_tokens = add_item_to_hud_string_list ("gt", item_tokens);
112
search_tokens = hud_token_list_new_from_string ("gt");
114
item = hud_item_new (item_tokens, NULL, NULL, TRUE);
116
HudResult *result = hud_result_new (item, search_tokens, 0);
117
g_assert (strcmp (hud_result_get_html_description (result), "foo > bar > <b>gt</b>") == 0);
119
hud_token_list_free (search_tokens);
120
g_object_unref (result);
121
g_object_unref (item);
122
hud_string_list_unref (item_tokens);
128
test_result_highlighting_apos1 (void)
131
HudStringList *item_tokens;
132
HudTokenList *search_tokens;
134
item_tokens = add_item_to_hud_string_list ("d'interes", NULL);
135
item_tokens = add_item_to_hud_string_list ("a", item_tokens);
137
search_tokens = hud_token_list_new_from_string ("d'in");
139
item = hud_item_new (item_tokens, NULL, NULL, TRUE);
141
HudResult *result = hud_result_new (item, search_tokens, 0);
142
g_assert (strcmp (hud_result_get_html_description (result), "<b>d'interes</b> > a") == 0);
144
hud_token_list_free (search_tokens);
145
g_object_unref (result);
146
g_object_unref (item);
147
hud_string_list_unref (item_tokens);
153
test_result_highlighting_apos2 (void)
156
HudStringList *item_tokens;
157
HudTokenList *search_tokens;
159
item_tokens = add_item_to_hud_string_list ("d'interes", NULL);
160
item_tokens = add_item_to_hud_string_list ("a", item_tokens);
162
search_tokens = hud_token_list_new_from_string ("a");
164
item = hud_item_new (item_tokens, NULL, NULL, TRUE);
166
HudResult *result = hud_result_new (item, search_tokens, 0);
167
g_assert (strcmp (hud_result_get_html_description (result), "d'interes > <b>a</b>") == 0);
169
hud_token_list_free (search_tokens);
170
g_object_unref (result);
171
g_object_unref (item);
172
hud_string_list_unref (item_tokens);
177
/* Build the test suite */
179
test_result_highlighting_suite (void)
181
g_test_add_func ("/hud/highlighting/base", test_result_highlighting_base);
182
g_test_add_func ("/hud/highlighting/baseutf8", test_result_highlighting_baseutf8);
183
g_test_add_func ("/hud/highlighting/gt", test_result_highlighting_gt);
184
g_test_add_func ("/hud/highlighting/apos1", test_result_highlighting_apos1);
185
g_test_add_func ("/hud/highlighting/apos2", test_result_highlighting_apos2);
190
main (gint argc, gchar * argv[])
192
g_test_init(&argc, &argv, NULL);
195
test_result_highlighting_suite();
197
return g_test_run ();