1/* Pango
2 * testlanguage.c: Test program for PangoLanguage
3 *
4 * Copyright (C) 2021 Matthias Clasen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#include <glib.h>
23#include <pango/pango.h>
24
25static void
26test_language_to_string (void)
27{
28 PangoLanguage *lang;
29
30 lang = pango_language_from_string (language: "ja-jp");
31 g_assert_cmpstr (pango_language_to_string (lang), ==, "ja-jp");
32 g_assert_cmpstr ((pango_language_to_string) (lang), ==, "ja-jp");
33}
34
35static void
36test_language_env (void)
37{
38 if (g_test_subprocess ())
39 {
40 PangoLanguage **preferred;
41
42 g_setenv (variable: "PANGO_LANGUAGE", value: "de:ja", TRUE);
43 g_setenv (variable: "LANGUAGE", value: "fr", TRUE);
44
45 preferred = pango_language_get_preferred ();
46 g_assert_nonnull (preferred);
47 g_assert_true (preferred[0] == pango_language_from_string ("de"));
48 g_assert_true (preferred[1] == pango_language_from_string ("ja"));
49 g_assert_null (preferred[2]);
50
51 return;
52 }
53
54 g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0);
55 g_test_trap_assert_passed ();
56}
57
58int
59main (int argc, char *argv[])
60{
61 g_test_init (argc: &argc, argv: &argv, NULL);
62
63 g_test_add_func (testpath: "/language/to-string", test_func: test_language_to_string);
64 g_test_add_func (testpath: "/language/language-env", test_func: test_language_env);
65
66 return g_test_run ();
67}
68

source code of gtk/subprojects/pango/tests/testlanguage.c