~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise-201112142106

« back to all changes in this revision

Viewing changes to nautilus/test-highlight.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-08-09 12:47:56 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809124756-7nzilp3oix0a1yl9
Tags: 1.7.1-0ubuntu1
* New upstream release.
* debian/*:
  - Removed obsolete pycompat file
  - Removed ubuntuone-client-gnome deps and binary packaging, as it was
    moved out to separate project upstream.
  - Updated copyright to remove obsolete file reference
* debian/patches:
  - Removed patches which have been included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Authors: Alejandro J. Cura <alecu@canonical.com>
3
 
 *
4
 
 * Copyright 2010 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
 
 
20
 
#include "highlight.h"
21
 
 
22
 
#include <glib.h>
23
 
 
24
 
#define ASSERT_HIGHLIGHT(a,b,c) \
25
 
        ret = highlight_result (a, b); \
26
 
        g_assert_cmpstr (ret, ==, c); \
27
 
        g_free (ret);
28
 
 
29
 
static void
30
 
test_highlight_matches (void)
31
 
{
32
 
        gchar *ret = NULL;
33
 
        /* match at beginning */
34
 
        ASSERT_HIGHLIGHT ("john", "john q. public", "<b>john</b> q. public");
35
 
 
36
 
        /* match in the middle */
37
 
        ASSERT_HIGHLIGHT ("john", "andrew john q. public", "andrew <b>john</b> q. public");
38
 
 
39
 
        /* no match */
40
 
        ASSERT_HIGHLIGHT ("john", "andrew q. public", "andrew q. public");
41
 
 
42
 
        /* double match */
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");
45
 
 
46
 
        /* empty search */
47
 
        ASSERT_HIGHLIGHT ("", "john q. public", "john q. public");
48
 
 
49
 
        /* empty search with entities */
50
 
        ASSERT_HIGHLIGHT ("", "john & public", "john &amp; public");
51
 
 
52
 
        /* empty search term */
53
 
        ASSERT_HIGHLIGHT (" ", "john q. public", "john q. public");
54
 
 
55
 
        /* empty result */
56
 
        ASSERT_HIGHLIGHT ("john", "", "");
57
 
 
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");
62
 
 
63
 
        /* nested match */
64
 
        ASSERT_HIGHLIGHT ("edward wa", "edward wall", "<b>ed<b>wa</b>rd</b> <b>wa</b>ll");
65
 
 
66
 
        /* utf-8 strings */
67
 
        ASSERT_HIGHLIGHT ("ñandÚ", "Ñandú", "<b>Ñandú</b>");
68
 
 
69
 
        /* xml entities in the search */
70
 
        ASSERT_HIGHLIGHT ("john &", "john sons", "<b>john</b> sons");
71
 
 
72
 
        /* xml entities in the result */
73
 
        ASSERT_HIGHLIGHT ("john sons", "john & sons", "<b>john</b> &amp; <b>sons</b>");
74
 
 
75
 
        /* xml entities everywhere */
76
 
        ASSERT_HIGHLIGHT ("john & sons", "john & sons", "<b>john</b> <b>&amp;</b> <b>sons</b>");
77
 
 
78
 
        /* make sure the name of the entities is not highlighted */
79
 
        ASSERT_HIGHLIGHT ("john amp sons", "john & sons", "<b>john</b> &amp; <b>sons</b>");
80
 
}
81
 
 
82
 
int
83
 
main (int argc, gchar *argv[])
84
 
{
85
 
        g_test_init (&argc, &argv, NULL);
86
 
 
87
 
        g_test_add_func ("/testcontacts/TestHighlightMatches", test_highlight_matches);
88
 
 
89
 
        return g_test_run ();
90
 
}