mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-13 19:15:03 -04:00
tests: Expand test coverage for flatpak_get_lang_from_locale()
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
@@ -120,6 +120,10 @@ test_instance_SOURCES = \
|
||||
tests/test-instance.c \
|
||||
$(NULL)
|
||||
|
||||
test_locale_utils_CFLAGS = $(testcommon_CFLAGS)
|
||||
test_locale_utils_LDADD = $(testcommon_LDADD) libtestlib.la
|
||||
test_locale_utils_SOURCES = tests/test-locale-utils.c
|
||||
|
||||
test_portal_CFLAGS = $(testcommon_CFLAGS)
|
||||
test_portal_LDADD = $(testcommon_LDADD) libtestlib.la
|
||||
test_portal_SOURCES = \
|
||||
@@ -300,6 +304,7 @@ test_programs = \
|
||||
test-context \
|
||||
test-exports \
|
||||
test-instance \
|
||||
test-locale-utils \
|
||||
test-portal \
|
||||
testapp \
|
||||
testcommon \
|
||||
|
||||
@@ -108,6 +108,7 @@ c_tests = [
|
||||
libglnx_testlib_dep,
|
||||
],
|
||||
}],
|
||||
['test-locale-utils', {}],
|
||||
['test-portal', {
|
||||
'extra_sources' : [
|
||||
portal_gdbus[0],
|
||||
|
||||
64
tests/test-locale-utils.c
Normal file
64
tests/test-locale-utils.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2023 Collabora Ltd.
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include "libglnx.h"
|
||||
#include "flatpak.h"
|
||||
|
||||
#include "flatpak-utils-private.h"
|
||||
|
||||
#include "tests/testlib.h"
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *in;
|
||||
const char *expected;
|
||||
} lang_from_locale_tests[] =
|
||||
{
|
||||
{ "C", NULL },
|
||||
{ "C.UTF-8", NULL },
|
||||
{ "en.ISO-8859-15", "en" },
|
||||
{ "en@cantab", "en" },
|
||||
{ "en_GB", "en" },
|
||||
{ "en_US.utf8", "en" },
|
||||
{ "sv_FI@euro", "sv" },
|
||||
};
|
||||
|
||||
static void
|
||||
test_lang_from_locale (void)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (lang_from_locale_tests); i++)
|
||||
{
|
||||
const char *in = lang_from_locale_tests[i].in;
|
||||
const char *expected = lang_from_locale_tests[i].expected;
|
||||
g_autofree char *actual = NULL;
|
||||
|
||||
g_test_message ("%s", in);
|
||||
actual = flatpak_get_lang_from_locale (in);
|
||||
g_test_message ("-> %s", actual ? actual : "(null)");
|
||||
g_assert_cmpstr (actual, ==, expected);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int res;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
isolated_test_dir_global_setup ();
|
||||
|
||||
g_test_add_func ("/locale/lang-from-locale", test_lang_from_locale);
|
||||
|
||||
res = g_test_run ();
|
||||
|
||||
isolated_test_dir_global_teardown ();
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -632,19 +632,6 @@ test_subpaths_merge (void)
|
||||
g_clear_pointer (&res, g_strfreev);
|
||||
}
|
||||
|
||||
static void
|
||||
test_lang_from_locale (void)
|
||||
{
|
||||
g_autofree char *lang = NULL;
|
||||
|
||||
lang = flatpak_get_lang_from_locale ("en_US.utf8");
|
||||
g_assert_cmpstr (lang, ==, "en");
|
||||
g_clear_pointer (&lang, g_free);
|
||||
|
||||
lang = flatpak_get_lang_from_locale ("sv_FI@euro");
|
||||
g_assert_cmpstr (lang, ==, "sv");
|
||||
}
|
||||
|
||||
static void
|
||||
test_parse_appdata (void)
|
||||
{
|
||||
@@ -1376,7 +1363,6 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/common/string-to-unsigned", test_string_to_unsigned);
|
||||
g_test_add_func ("/common/levenshtein", test_levenshtein);
|
||||
g_test_add_func ("/common/subpaths-merge", test_subpaths_merge);
|
||||
g_test_add_func ("/common/lang-from-locale", test_lang_from_locale);
|
||||
g_test_add_func ("/common/appdata", test_parse_appdata);
|
||||
g_test_add_func ("/common/name-matching", test_name_matching);
|
||||
g_test_add_func ("/common/filter_parser", test_filter_parser);
|
||||
|
||||
Reference in New Issue
Block a user