git: dbfea0a6d894 - stable/13 - strfmon_test: Add a test for strfmon_l

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 05 Nov 2022 00:31:08 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=dbfea0a6d894ca11f6e383115f8e3afd045d8d4b

commit dbfea0a6d894ca11f6e383115f8e3afd045d8d4b
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 02:53:43 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-11-05 00:30:39 +0000

    strfmon_test: Add a test for strfmon_l
    
    (cherry picked from commit 29972f06f95d6f5f550ac81367d5ebda8d6860a8)
---
 lib/libc/tests/stdlib/strfmon_test.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index c2fa6250dc58..dcad17d3dbfd 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -211,6 +211,38 @@ ATF_TC_BODY(strfmon_international_currency_code, tc)
 	}
 }
 
+ATF_TC(strfmon_l);
+ATF_TC_HEAD(strfmon_l, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "checks strfmon_l under different locales");
+}
+ATF_TC_BODY(strfmon_l, tc)
+{
+	const struct {
+		const char *locale;
+		const char *expected;
+	} tests[] = {
+	    { "C", "[ **1234.57 ] [ **1234.57 ]" },
+	    { "de_DE.UTF-8", "[ €**1234.57 ] [ EUR**1234.57 ]" }, /* XXX */
+	    { "en_GB.UTF-8", "[ £**1234.57 ] [ GBP**1234.57 ]" }, /* XXX */
+	};
+	locale_t loc;
+	size_t i;
+	char buf[100];
+
+	for (i = 0; i < nitems(tests); ++i) {
+		loc = newlocale(LC_MONETARY_MASK, tests[i].locale, NULL);
+		ATF_REQUIRE(loc != NULL);
+
+		strfmon_l(buf, sizeof(buf) - 1, loc, "[%^=*#6n] [%=*#6i]",
+		    1234.567, 1234.567);
+		ATF_REQUIRE_STREQ(tests[i].expected, buf);
+
+		freelocale(loc);
+	}
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, strfmon_locale_thousands);
@@ -218,5 +250,6 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, strfmon_cs_precedes_0);
 	ATF_TP_ADD_TC(tp, strfmon_cs_precedes_1);
 	ATF_TP_ADD_TC(tp, strfmon_international_currency_code);
+	ATF_TP_ADD_TC(tp, strfmon_l);
 	return (atf_no_error());
 }