2
* Authors: Alejandro J. Cura <alecu@canonical.com>
4
* Copyright 2010 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 "highlight.h"
24
#define ASSERT_HIGHLIGHT(a,b,c) \
25
ret = highlight_result (a, b); \
26
g_assert_cmpstr (ret, ==, c); \
30
test_highlight_matches (void)
33
/* match at beginning */
34
ASSERT_HIGHLIGHT ("john", "john q. public", "<b>john</b> q. public");
36
/* match in the middle */
37
ASSERT_HIGHLIGHT ("john", "andrew john q. public", "andrew <b>john</b> q. public");
40
ASSERT_HIGHLIGHT ("john", "andrew q. public", "andrew q. public");
43
ASSERT_HIGHLIGHT ("jo sm", "john smith", "<b>jo</b>hn <b>sm</b>ith");
44
ASSERT_HIGHLIGHT ("john", "john johnson", "<b>john</b> <b>john</b>son");
47
ASSERT_HIGHLIGHT ("", "john q. public", "john q. public");
49
/* empty search with entities */
50
ASSERT_HIGHLIGHT ("", "john & public", "john & public");
52
/* empty search term */
53
ASSERT_HIGHLIGHT (" ", "john q. public", "john q. public");
56
ASSERT_HIGHLIGHT ("john", "", "");
58
/* case insensitive match */
59
ASSERT_HIGHLIGHT ("john", "John Smith", "<b>John</b> Smith");
60
ASSERT_HIGHLIGHT ("john", "Brian JOHNSON", "Brian <b>JOHN</b>SON");
61
ASSERT_HIGHLIGHT ("br jo", "Brian JOHNSON", "<b>Br</b>ian <b>JO</b>HNSON");
64
ASSERT_HIGHLIGHT ("edward wa", "edward wall", "<b>ed<b>wa</b>rd</b> <b>wa</b>ll");
67
ASSERT_HIGHLIGHT ("ñandÚ", "Ñandú", "<b>Ñandú</b>");
69
/* xml entities in the search */
70
ASSERT_HIGHLIGHT ("john &", "john sons", "<b>john</b> sons");
72
/* xml entities in the result */
73
ASSERT_HIGHLIGHT ("john sons", "john & sons", "<b>john</b> & <b>sons</b>");
75
/* xml entities everywhere */
76
ASSERT_HIGHLIGHT ("john & sons", "john & sons", "<b>john</b> <b>&</b> <b>sons</b>");
78
/* make sure the name of the entities is not highlighted */
79
ASSERT_HIGHLIGHT ("john amp sons", "john & sons", "<b>john</b> & <b>sons</b>");
83
main (int argc, gchar *argv[])
85
g_test_init (&argc, &argv, NULL);
87
g_test_add_func ("/testcontacts/TestHighlightMatches", test_highlight_matches);