[gspell] icu: write unit test for get_language_name_from_code()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell] icu: write unit test for get_language_name_from_code()
- Date: Fri, 9 Oct 2020 01:02:42 +0000 (UTC)
commit ab5f8d753c311ace81a8cbf9e5b5e9ec7324e407
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Oct 9 02:59:19 2020 +0200
icu: write unit test for get_language_name_from_code()
This requires to add the @inLocaleID parameter.
gspell/gspell-icu.c | 14 +++++++++-----
gspell/gspell-icu.h | 3 ++-
gspell/gspell-language.c | 2 +-
testsuite/test-icu.c | 18 ++++++++++++++++++
4 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/gspell/gspell-icu.c b/gspell/gspell-icu.c
index e81c58d..f5fbff5 100644
--- a/gspell/gspell-icu.c
+++ b/gspell/gspell-icu.c
@@ -216,15 +216,20 @@ _gspell_icu_loc_canonicalizeSimple (const char *localeID)
return result;
}
-/* This function uses gspell's terminology:
+/* The name of this function uses gspell's terminology:
* "Language code": as in gspell_language_get_code().
- * "Language name": as in gspell_language_get_name().
+ * "Language name": as in gspell_language_get_name(), except that the
+ * translation is controlled by the @inLocaleID parameter which has the same
+ * meaning as for _gspell_icu_loc_getDisplayNameSimple(). If @inLocaleID is
+ * %NULL then the default locale is used to translate the name. The @inLocaleID
+ * parameter is kept for this function for unit tests.
*
* Returns: (transfer full) (nullable): the language name, or %NULL in case of
* error. Free with g_free() when no longer needed.
*/
char *
-_gspell_icu_get_language_name_from_code (const char *language_code)
+_gspell_icu_get_language_name_from_code (const char *language_code,
+ const char *inLocaleID)
{
char *canonicalized_language_code;
char *language_name;
@@ -238,8 +243,7 @@ _gspell_icu_get_language_name_from_code (const char *language_code)
return NULL;
}
- /* NULL: for the default locale. */
- language_name = _gspell_icu_loc_getDisplayNameSimple (canonicalized_language_code, NULL);
+ language_name = _gspell_icu_loc_getDisplayNameSimple (canonicalized_language_code, inLocaleID);
g_free (canonicalized_language_code);
return language_name;
}
diff --git a/gspell/gspell-icu.h b/gspell/gspell-icu.h
index 14e6cbe..46a1c65 100644
--- a/gspell/gspell-icu.h
+++ b/gspell/gspell-icu.h
@@ -25,7 +25,8 @@
G_BEGIN_DECLS
G_GNUC_INTERNAL
-char * _gspell_icu_get_language_name_from_code (const char *language_code);
+char * _gspell_icu_get_language_name_from_code (const char *language_code,
+ const char *inLocaleID);
/* Intermediate functions, for unit tests: */
diff --git a/gspell/gspell-language.c b/gspell/gspell-language.c
index 84bc515..c1274f4 100644
--- a/gspell/gspell-language.c
+++ b/gspell/gspell-language.c
@@ -82,7 +82,7 @@ spell_language_dict_describe_cb (const gchar * const language_code,
language = g_slice_new (GspellLanguage);
language->code = g_strdup (language_code);
- language->name = _gspell_icu_get_language_name_from_code (language_code);
+ language->name = _gspell_icu_get_language_name_from_code (language_code, NULL);
if (language->name == NULL)
{
/* Translators: %s is the language ISO code. */
diff --git a/testsuite/test-icu.c b/testsuite/test-icu.c
index 363575e..72c1f68 100644
--- a/testsuite/test-icu.c
+++ b/testsuite/test-icu.c
@@ -37,6 +37,23 @@ test_loc_getDisplayNameSimple (void)
check_loc_getDisplayNameSimple ("en_US", "English (United States)");
}
+static void
+check_get_language_name_from_code (const char *language_code,
+ const char *expected_name)
+{
+ char *received_name;
+
+ received_name = _gspell_icu_get_language_name_from_code (language_code, "en_US");
+ g_assert_cmpstr (received_name, ==, expected_name);
+ g_free (received_name);
+}
+
+static void
+test_get_language_name_from_code (void)
+{
+ check_get_language_name_from_code ("en_US", "English (United States)");
+}
+
int
main (int argc,
char **argv)
@@ -44,6 +61,7 @@ main (int argc,
gtk_test_init (&argc, &argv);
g_test_add_func ("/icu/loc_getDisplayNameSimple", test_loc_getDisplayNameSimple);
+ g_test_add_func ("/icu/get_language_name_from_code", test_get_language_name_from_code);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]