~mhr3/dee/add-changesets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (C) 2012 Canonical, Ltd.
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 3.0 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3.0 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 */

#include <dee.h>
#include <dee-icu.h>

typedef struct
{
  DeeICUTermFilter *filter;
} Fixture;

static void setup    (Fixture *fix, gconstpointer data);
static void teardown (Fixture *fix, gconstpointer data);

static void
setup (Fixture *fix, gconstpointer data)
{
  fix->filter = NULL;
}

static void
teardown (Fixture *fix, gconstpointer data)
{
  if (fix->filter)
    dee_icu_term_filter_destroy (fix->filter);
}

static void
test_ascii_folder (Fixture *fix, gconstpointer data)
{
  gchar *result;

  fix->filter = dee_icu_term_filter_new_ascii_folder();

  result = dee_icu_term_filter_apply (fix->filter, "Hello world");
  g_assert_cmpstr (result, ==, "Hello world");
  g_free (result);

  result = dee_icu_term_filter_apply (fix->filter, "øöô");
  g_assert_cmpstr (result, ==, "ooo");
  g_free (result);

  result = dee_icu_term_filter_apply (fix->filter, "Θεοδωράτου, Ελένη");
  g_assert_cmpstr (result, ==, "Theodoratou, Elene");
  g_free (result);

  result = dee_icu_term_filter_apply (fix->filter, "Догилева, Татьяна");
  g_assert_cmpstr (result, ==, "Dogileva, Tatʹana");
  g_free (result);

  result = dee_icu_term_filter_apply (fix->filter, "김, 국삼");
  g_assert_cmpstr (result, ==,  "gim, gugsam");
  g_free (result);

  result = dee_icu_term_filter_apply (fix->filter, "たけだ, まさゆき");
  g_assert_cmpstr (result, ==, "takeda, masayuki");
  g_free (result);

  /* One last time to honor the French ;-) */
  result = dee_icu_term_filter_apply (fix->filter, "Est-ce que tes enfants sont de bons élèves? Ça va pour eux?");
  g_assert_cmpstr (result, ==, "Est-ce que tes enfants sont de bons eleves? Ca va pour eux?");
  g_free (result);
}

static void
test_bad_id (Fixture *fix, gconstpointer data)
{
  GError *error = NULL;

  fix->filter = dee_icu_term_filter_new ("*-sad ???", NULL, &error);

  g_assert (fix->filter == NULL);
  g_assert (error != NULL);
  g_assert_cmpint (error->domain, ==, DEE_ICU_ERROR);
  g_assert_cmpint (error->code, ==, DEE_ICU_ERROR_BAD_ID);

  g_error_free (error);
}

static void
test_bad_rule (Fixture *fix, gconstpointer data)
{
  GError *error = NULL;

  fix->filter = dee_icu_term_filter_new (NULL, "*-sad ???", &error);

  g_assert (fix->filter == NULL);
  g_assert (error != NULL);
  g_assert_cmpint (error->domain, ==, DEE_ICU_ERROR);
  g_assert_cmpint (error->code, ==, DEE_ICU_ERROR_BAD_RULE);

  g_error_free (error);
}

void
test_icu_create_suite (void)
{
#define DOMAIN "/ICU/TermFilter"

  g_test_add (DOMAIN"/Default/AsciiFolder", Fixture, 0,
              setup, test_ascii_folder, teardown);
  g_test_add (DOMAIN"/Default/BadId", Fixture, 0,
              setup, test_bad_id, teardown);
  g_test_add (DOMAIN"/Default/BadRule", Fixture, 0,
              setup, test_bad_rule, teardown);
}