1 | /* |
2 | * Copyright 2018 Red Hat, Inc. |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * See the included COPYING file for more information. |
10 | */ |
11 | |
12 | #include "glib.h" |
13 | |
14 | #define TEST_LOCALE "fr_FR.UTF-8@latin:en_US.UTF-8" |
15 | |
16 | const gchar *TEST_RESULT[] = { |
17 | "fr_FR.UTF-8@latin" , |
18 | "fr_FR@latin" , |
19 | "fr.UTF-8@latin" , |
20 | "fr@latin" , |
21 | "fr_FR.UTF-8" , |
22 | "fr_FR" , |
23 | "fr.UTF-8" , |
24 | "fr" , |
25 | "en_US.UTF-8" , |
26 | "en_US" , |
27 | "en.UTF-8" , |
28 | "en" , |
29 | "C" , |
30 | NULL |
31 | }; |
32 | |
33 | const gchar *TEST_TABLE[] = { |
34 | "LANGUAGE" , |
35 | "LC_ALL" , |
36 | "LC_CTYPE" , |
37 | "LANG" , |
38 | NULL |
39 | }; |
40 | |
41 | static void |
42 | test_language_names_with_category (void) |
43 | { |
44 | const gchar * const *language_names = NULL; |
45 | gsize i, j; |
46 | |
47 | for (i = 0; TEST_TABLE[i]; ++i) |
48 | { |
49 | g_test_message (format: "Test %" G_GSIZE_FORMAT, i); |
50 | g_assert_true (g_setenv (TEST_TABLE[i], TEST_LOCALE, TRUE)); |
51 | language_names = g_get_language_names_with_category (category_name: "LC_CTYPE" ); |
52 | g_assert_cmpuint (g_strv_length ((gchar **)language_names), ==, g_strv_length ((gchar **)TEST_RESULT)); |
53 | |
54 | for (j = 0; language_names[j]; ++j) |
55 | { |
56 | g_assert_cmpstr (language_names[j], ==, TEST_RESULT[j]); |
57 | } |
58 | g_unsetenv (variable: TEST_TABLE[i]); |
59 | } |
60 | } |
61 | |
62 | static void |
63 | test_language_names_with_category_async (void) |
64 | { |
65 | g_thread_join (thread: g_thread_new ( |
66 | NULL, func: (GThreadFunc)g_get_language_names_with_category, data: "LC_CTYPE" )); |
67 | |
68 | /* g_get_language_names_with_category returns a pointer to a memory |
69 | which is owned by a thread it has been called from. The thread is dead now, |
70 | therefore returned pointer can't be used at this stage. |
71 | */ |
72 | } |
73 | |
74 | int |
75 | main (int argc, char *argv[]) |
76 | { |
77 | g_test_init (argc: &argc, argv: &argv, NULL); |
78 | |
79 | g_test_bug_base (uri_pattern: "http://bugs.gnome.org/" ); |
80 | |
81 | g_test_add_func (testpath: "/charset/language_names_with_category" , test_func: test_language_names_with_category); |
82 | g_test_add_func (testpath: "/charset/language_names_with_category_async" , test_func: test_language_names_with_category_async); |
83 | |
84 | return g_test_run (); |
85 | } |
86 | |