git: 29972f06f95d - main - strfmon_test: Add a test for strfmon_l

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 29 Oct 2022 21:10:52 UTC
The branch main has been updated by kib:

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

commit 29972f06f95d6f5f550ac81367d5ebda8d6860a8
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 02:53:43 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:08:54 +0000

    strfmon_test: Add a test for strfmon_l
    
    Attempt to test the correctness of strfmon_l(3).
    
    Items marked with XXX represent an invalid output.
    
    Obtained from:  https://github.com/NetBSD/src/commit/e7eba0044fe6128291cbb7e5923c7cf7d87318cc
    
    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week
---
 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());
 }