~ubuntu-branches/ubuntu/saucy/indicator-appmenu/saucy-updates

« back to all changes in this revision

Viewing changes to tests/test-result-highlighting.c

  • Committer: Package Import Robot
  • Author(s): Automatic PS uploader, Mathieu Trudel-Lapierre, Automatic PS uploader
  • Date: 2013-02-20 09:41:54 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20130220094154-zrxsx0vgay436wyt
Tags: 13.01.0daily13.02.20-0ubuntu1
[ Mathieu Trudel-Lapierre ]
* Artificially bump upstream major version to please hud.

[ Automatic PS uploader ]
* Automatic snapshot from revision 234

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Test code for highlighting functions
3
 
 
4
 
Copyright 2012 Canonical Ltd.
5
 
 
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.
9
 
 
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.
14
 
 
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/>.
17
 
*/
18
 
 
19
 
#include <glib.h>
20
 
#include <glib-object.h>
21
 
 
22
 
#include <string.h>
23
 
 
24
 
#include "hudresult.h"
25
 
#include "hudsettings.h"
26
 
 
27
 
/* hardcode some parameters so the test doesn't fail if the user
28
 
 * has bogus things in GSettings.
29
 
 */
30
 
HudSettings hud_settings = {
31
 
        .indicator_penalty = 50,
32
 
        .add_penalty = 10,
33
 
        .drop_penalty = 10,
34
 
        .end_drop_penalty = 1,
35
 
        .swap_penalty = 15,
36
 
        .max_distance = 30
37
 
};
38
 
 
39
 
static HudStringList*
40
 
add_item_to_hud_string_list (const gchar *item, HudStringList *stringlist)
41
 
{
42
 
        HudStringList *new_list = hud_string_list_cons (item, stringlist);
43
 
        hud_string_list_unref (stringlist);
44
 
        return new_list;
45
 
}
46
 
 
47
 
static void
48
 
test_result_highlighting_base (void)
49
 
{
50
 
        HudItem *item;
51
 
        HudStringList *item_tokens;
52
 
        HudTokenList *search_tokens;
53
 
        
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);
57
 
        
58
 
        search_tokens = hud_token_list_new_from_string ("bar");
59
 
        
60
 
        item = hud_item_new (item_tokens, NULL, NULL, TRUE);
61
 
 
62
 
        HudResult *result = hud_result_new (item, search_tokens, 0);
63
 
        
64
 
        g_assert (strcmp (hud_result_get_html_description (result), "foo &gt; <b>bar</b> &gt; mango") == 0);
65
 
        
66
 
        hud_token_list_free (search_tokens);
67
 
        g_object_unref (result);
68
 
        g_object_unref (item);
69
 
        hud_string_list_unref (item_tokens);
70
 
        
71
 
        return;
72
 
}
73
 
 
74
 
static void
75
 
test_result_highlighting_baseutf8 (void)
76
 
{
77
 
        HudItem *item;
78
 
        HudStringList *item_tokens;
79
 
        HudTokenList *search_tokens;
80
 
        
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);
84
 
        
85
 
        search_tokens = hud_token_list_new_from_string ("ẃêỳᶉ∂");
86
 
        
87
 
        item = hud_item_new (item_tokens, NULL, NULL, TRUE);
88
 
 
89
 
        HudResult *result = hud_result_new (item, search_tokens, 0);
90
 
        
91
 
        g_assert (strcmp (hud_result_get_html_description (result), "foo &gt; <b>ẃêỳᶉ∂</b> &gt; mango") == 0);
92
 
        
93
 
        hud_token_list_free (search_tokens);
94
 
        g_object_unref (result);
95
 
        g_object_unref (item);
96
 
        hud_string_list_unref (item_tokens);
97
 
        
98
 
        return;
99
 
}
100
 
 
101
 
static void
102
 
test_result_highlighting_gt (void)
103
 
{
104
 
        HudItem *item;
105
 
        HudStringList *item_tokens;
106
 
        HudTokenList *search_tokens;
107
 
        
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);
111
 
        
112
 
        search_tokens = hud_token_list_new_from_string ("gt");
113
 
        
114
 
        item = hud_item_new (item_tokens, NULL, NULL, TRUE);
115
 
 
116
 
        HudResult *result = hud_result_new (item, search_tokens, 0);
117
 
        g_assert (strcmp (hud_result_get_html_description (result), "foo &gt; bar &gt; <b>gt</b>") == 0);
118
 
        
119
 
        hud_token_list_free (search_tokens);
120
 
        g_object_unref (result);
121
 
        g_object_unref (item);
122
 
        hud_string_list_unref (item_tokens);
123
 
        
124
 
        return;
125
 
}
126
 
 
127
 
static void
128
 
test_result_highlighting_apos1 (void)
129
 
{
130
 
        HudItem *item;
131
 
        HudStringList *item_tokens;
132
 
        HudTokenList *search_tokens;
133
 
 
134
 
        item_tokens = add_item_to_hud_string_list ("d'interes", NULL);
135
 
        item_tokens = add_item_to_hud_string_list ("a", item_tokens);
136
 
 
137
 
        search_tokens = hud_token_list_new_from_string ("d'in");
138
 
 
139
 
        item = hud_item_new (item_tokens, NULL, NULL, TRUE);
140
 
 
141
 
        HudResult *result = hud_result_new (item, search_tokens, 0);
142
 
        g_assert (strcmp (hud_result_get_html_description (result), "<b>d&apos;interes</b> &gt; a") == 0);
143
 
 
144
 
        hud_token_list_free (search_tokens);
145
 
        g_object_unref (result);
146
 
        g_object_unref (item);
147
 
        hud_string_list_unref (item_tokens);
148
 
 
149
 
        return;
150
 
}
151
 
 
152
 
static void
153
 
test_result_highlighting_apos2 (void)
154
 
{
155
 
        HudItem *item;
156
 
        HudStringList *item_tokens;
157
 
        HudTokenList *search_tokens;
158
 
 
159
 
        item_tokens = add_item_to_hud_string_list ("d'interes", NULL);
160
 
        item_tokens = add_item_to_hud_string_list ("a", item_tokens);
161
 
 
162
 
        search_tokens = hud_token_list_new_from_string ("a");
163
 
 
164
 
        item = hud_item_new (item_tokens, NULL, NULL, TRUE);
165
 
 
166
 
        HudResult *result = hud_result_new (item, search_tokens, 0);
167
 
        g_assert (strcmp (hud_result_get_html_description (result), "d&apos;interes &gt; <b>a</b>") == 0);
168
 
 
169
 
        hud_token_list_free (search_tokens);
170
 
        g_object_unref (result);
171
 
        g_object_unref (item);
172
 
        hud_string_list_unref (item_tokens);
173
 
 
174
 
        return;
175
 
}
176
 
 
177
 
/* Build the test suite */
178
 
static void
179
 
test_result_highlighting_suite (void)
180
 
{
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);
186
 
        return;
187
 
}
188
 
 
189
 
gint
190
 
main (gint argc, gchar * argv[])
191
 
{
192
 
        g_test_init(&argc, &argv, NULL);
193
 
 
194
 
        /* Test suites */
195
 
        test_result_highlighting_suite();
196
 
 
197
 
        return g_test_run ();
198
 
}