From: Yu Watanabe Date: Sat, 6 Sep 2025 18:30:21 +0000 (+0900) Subject: test-parse-util: use newlocale() and freelocale() to set temporarl locale X-Git-Tag: v259-rc1~535^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e219a09c2353ddbf52a66536db6c2b5593a903b;p=thirdparty%2Fsystemd.git test-parse-util: use newlocale() and freelocale() to set temporarl locale This also drops unnecessary call of strtod(), as it is a test for safe_atod(). --- diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index 2a54dae2a46..37d0280cadd 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -6,6 +6,7 @@ #include #include +#include "locale-util.h" #include "parse-util.h" #include "tests.h" @@ -655,7 +656,6 @@ TEST(safe_atoux64) { TEST(safe_atod) { double d; - char *e; ASSERT_ERROR(safe_atod("junk", &d), EINVAL); @@ -663,39 +663,18 @@ TEST(safe_atod) { assert_se(fabs(d - 0.2244) < 0.000001); ASSERT_ERROR(safe_atod("0,5", &d), EINVAL); - - errno = 0; - strtod("0,5", &e); - assert_se(*e == ','); - ASSERT_ERROR(safe_atod("", &d), EINVAL); /* Check if this really is locale independent */ - if (setlocale(LC_NUMERIC, "de_DE.utf8")) { - - ASSERT_OK_ZERO(safe_atod("0.2244", &d)); - assert_se(fabs(d - 0.2244) < 0.000001); - - ASSERT_ERROR(safe_atod("0,5", &d), EINVAL); - - errno = 0; - assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001); - - ASSERT_ERROR(safe_atod("", &d), EINVAL); - } - - /* And check again, reset */ - ASSERT_NOT_NULL(setlocale(LC_NUMERIC, "C")); + _cleanup_(freelocalep) locale_t loc = + newlocale(LC_NUMERIC_MASK, "de_DE.utf8", (locale_t) 0); + if (!loc) + return (void) log_tests_skipped_errno(errno, "locale de_DE.utf8 not found"); ASSERT_OK_ZERO(safe_atod("0.2244", &d)); assert_se(fabs(d - 0.2244) < 0.000001); ASSERT_ERROR(safe_atod("0,5", &d), EINVAL); - - errno = 0; - strtod("0,5", &e); - assert_se(*e == ','); - ASSERT_ERROR(safe_atod("", &d), EINVAL); }