/* * Authors: Alejandro J. Cura * * Copyright 2010 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * */ #include "highlight.h" #include #define ASSERT_HIGHLIGHT(a,b,c) \ ret = highlight_result (a, b); \ g_assert_cmpstr (ret, ==, c); \ g_free (ret); static void test_highlight_matches (void) { gchar *ret = NULL; /* match at beginning */ ASSERT_HIGHLIGHT ("john", "john q. public", "john q. public"); /* match in the middle */ ASSERT_HIGHLIGHT ("john", "andrew john q. public", "andrew john q. public"); /* no match */ ASSERT_HIGHLIGHT ("john", "andrew q. public", "andrew q. public"); /* double match */ ASSERT_HIGHLIGHT ("jo sm", "john smith", "john smith"); ASSERT_HIGHLIGHT ("john", "john johnson", "john johnson"); /* empty search */ ASSERT_HIGHLIGHT ("", "john q. public", "john q. public"); /* empty search with entities */ ASSERT_HIGHLIGHT ("", "john & public", "john & public"); /* empty search term */ ASSERT_HIGHLIGHT (" ", "john q. public", "john q. public"); /* empty result */ ASSERT_HIGHLIGHT ("john", "", ""); /* case insensitive match */ ASSERT_HIGHLIGHT ("john", "John Smith", "John Smith"); ASSERT_HIGHLIGHT ("john", "Brian JOHNSON", "Brian JOHNSON"); ASSERT_HIGHLIGHT ("br jo", "Brian JOHNSON", "Brian JOHNSON"); /* nested match */ ASSERT_HIGHLIGHT ("edward wa", "edward wall", "edward wall"); /* utf-8 strings */ ASSERT_HIGHLIGHT ("ñandÚ", "Ñandú", "Ñandú"); /* xml entities in the search */ ASSERT_HIGHLIGHT ("john &", "john sons", "john sons"); /* xml entities in the result */ ASSERT_HIGHLIGHT ("john sons", "john & sons", "john & sons"); /* xml entities everywhere */ ASSERT_HIGHLIGHT ("john & sons", "john & sons", "john & sons"); /* make sure the name of the entities is not highlighted */ ASSERT_HIGHLIGHT ("john amp sons", "john & sons", "john & sons"); } int main (int argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/testcontacts/TestHighlightMatches", test_highlight_matches); return g_test_run (); }