LCOV - code coverage report
Current view: top level - glib/glib/tests - charset.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 19 19 100.0 %
Date: 2024-04-23 05:16:05 Functions: 3 3 100.0 %
Branches: 4 4 100.0 %

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

Generated by: LCOV version 1.14