~ubuntu-branches/ubuntu/saucy/dee/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/test-icu.c

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2012-02-03 11:38:57 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120203113857-a46h5kyigogedqy2
Tags: 1.0.2-0ubuntu1
* New upstream release.
  - DeeModel support insert_sorted() and find_sorted() (LP: #913128)
* debian/control:
  - requires now libicu-dev
* debian/libdee-1.0-4.symbols:
  - updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Canonical, Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License
 
6
 * version 3.0 as published by the Free Software Foundation.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License version 3.0 for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library. If not, see
 
15
 * <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 
18
 */
 
19
 
 
20
#include <dee.h>
 
21
#include <dee-icu.h>
 
22
 
 
23
typedef struct
 
24
{
 
25
  DeeICUTermFilter *filter;
 
26
} Fixture;
 
27
 
 
28
static void setup    (Fixture *fix, gconstpointer data);
 
29
static void teardown (Fixture *fix, gconstpointer data);
 
30
 
 
31
static void
 
32
setup (Fixture *fix, gconstpointer data)
 
33
{
 
34
  fix->filter = NULL;
 
35
}
 
36
 
 
37
static void
 
38
teardown (Fixture *fix, gconstpointer data)
 
39
{
 
40
  if (fix->filter)
 
41
    dee_icu_term_filter_destroy (fix->filter);
 
42
}
 
43
 
 
44
static void
 
45
test_ascii_folder (Fixture *fix, gconstpointer data)
 
46
{
 
47
  gchar *result;
 
48
 
 
49
  fix->filter = dee_icu_term_filter_new_ascii_folder();
 
50
 
 
51
  result = dee_icu_term_filter_apply (fix->filter, "Hello world");
 
52
  g_assert_cmpstr (result, ==, "Hello world");
 
53
  g_free (result);
 
54
 
 
55
  result = dee_icu_term_filter_apply (fix->filter, "øöô");
 
56
  g_assert_cmpstr (result, ==, "ooo");
 
57
  g_free (result);
 
58
 
 
59
  result = dee_icu_term_filter_apply (fix->filter, "Θεοδωράτου, Ελένη");
 
60
  g_assert_cmpstr (result, ==, "Theodoratou, Elene");
 
61
  g_free (result);
 
62
 
 
63
  result = dee_icu_term_filter_apply (fix->filter, "Догилева, Татьяна");
 
64
  g_assert_cmpstr (result, ==, "Dogileva, Tatʹana");
 
65
  g_free (result);
 
66
 
 
67
  result = dee_icu_term_filter_apply (fix->filter, "김, 국삼");
 
68
  g_assert_cmpstr (result, ==,  "gim, gugsam");
 
69
  g_free (result);
 
70
 
 
71
  result = dee_icu_term_filter_apply (fix->filter, "たけだ, まさゆき");
 
72
  g_assert_cmpstr (result, ==, "takeda, masayuki");
 
73
  g_free (result);
 
74
 
 
75
  /* One last time to honor the French ;-) */
 
76
  result = dee_icu_term_filter_apply (fix->filter, "Est-ce que tes enfants sont de bons élèves? Ça va pour eux?");
 
77
  g_assert_cmpstr (result, ==, "Est-ce que tes enfants sont de bons eleves? Ca va pour eux?");
 
78
  g_free (result);
 
79
}
 
80
 
 
81
static void
 
82
test_bad_id (Fixture *fix, gconstpointer data)
 
83
{
 
84
  GError *error = NULL;
 
85
 
 
86
  fix->filter = dee_icu_term_filter_new ("*-sad ???", NULL, &error);
 
87
 
 
88
  g_assert (fix->filter == NULL);
 
89
  g_assert (error != NULL);
 
90
  g_assert_cmpint (error->domain, ==, DEE_ICU_ERROR);
 
91
  g_assert_cmpint (error->code, ==, DEE_ICU_ERROR_BAD_ID);
 
92
 
 
93
  g_error_free (error);
 
94
}
 
95
 
 
96
static void
 
97
test_bad_rule (Fixture *fix, gconstpointer data)
 
98
{
 
99
  GError *error = NULL;
 
100
 
 
101
  fix->filter = dee_icu_term_filter_new (NULL, "*-sad ???", &error);
 
102
 
 
103
  g_assert (fix->filter == NULL);
 
104
  g_assert (error != NULL);
 
105
  g_assert_cmpint (error->domain, ==, DEE_ICU_ERROR);
 
106
  g_assert_cmpint (error->code, ==, DEE_ICU_ERROR_BAD_RULE);
 
107
 
 
108
  g_error_free (error);
 
109
}
 
110
 
 
111
void
 
112
test_icu_create_suite (void)
 
113
{
 
114
#define DOMAIN "/ICU/TermFilter"
 
115
 
 
116
  g_test_add (DOMAIN"/Default/AsciiFolder", Fixture, 0,
 
117
              setup, test_ascii_folder, teardown);
 
118
  g_test_add (DOMAIN"/Default/BadId", Fixture, 0,
 
119
              setup, test_bad_id, teardown);
 
120
  g_test_add (DOMAIN"/Default/BadRule", Fixture, 0,
 
121
              setup, test_bad_rule, teardown);
 
122
}