From nobody Wed Nov 26 20:35:36 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dGrt03PYRz6HPnj for ; Wed, 26 Nov 2025 20:35:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dGrt02bTqz3RwG for ; Wed, 26 Nov 2025 20:35:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764189336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MGCIAFDn9Ola5GGZcKVRU0RZ7v1NTs3sU+58TJRetqQ=; b=G8lQK3z8Byu8VhGsZhgYi8PNjZsfNXyjLC5oJip/V+M4qyhv9s8Ll8yoeFfu2z4uKdRfrS yrPMm/yp0AoMKuUvxgC/jET4E/eli7yQGL0fPG7vst6HaZNfv53+8xp2awKL0N2N982GIU 9HQUTfptrwHXPZNueA0WDIsmfkpdPEi6DZ++dV7sw0BxWDguOlcLYU8HazhXbVqXAf/iBF WS9wwez3UoXys6+HnxvZWoCHHud/+SYZoBdnPk3xO0kvodyX2ghj8hXEbgZONsYg/iG8Hf lC2SMjuPW1N4pJkyBryA75czlWoZB/XWaqCZxXsXyHVeNPkc7nFSHLjL2HLRgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764189336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MGCIAFDn9Ola5GGZcKVRU0RZ7v1NTs3sU+58TJRetqQ=; b=oe6lGB5397/XhrCmbXSlmblidLtbEdTchGQ446IwunfzQGhQnZP+D0s84+vd7UyPpWZlvs Fja3T6blORCG7GYYL6ZvB1cfGFnIFMOcMRTCTQQl9ze8c+/B4qhteWSTSBYnuddnOBE7TQ QJVrmDQvQyNrzvEJpyQsaz3ji2SpIOYA3KR1PbupSMN0U7cHn3ogBZJZtwQdzdb6VkrGIK 7zlY35BQHlogngiOm1RoUHJBCT5vPLVrRUoQ93FIJBmCnaPhsLIjl020kjFb7pM3Hm4SDQ rbDrPFyoPBsA1CVVeDEPUt5FvCSDyIwtDfeU0ZUPVz1cru9Pbjhw6zOkEbqT+w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1764189336; a=rsa-sha256; cv=none; b=o/qkEmbEpTESkuscoiaZT06Syc0Jc5tTzzm+JNoHj90Fa2KD0gsulkiR4px4EJuHqJEPYk FnXqAgiXM2p+e/cjz2VIC2hCrqu/CYK3dOlw3jAHLkFwzjzxJ2JIzGescnIfQHfVHuYgut XJ1nHIQVEUxOXUDlycZ+uNSXpsIm57O30uizXPQlYwW+OSNSjI9J4qea4mGE76wxvERnaL 54T7zw6zBOagKAsYIw+ahEMIGNheh3987Irv40VtHnd4IDq34lqliC7UtlySdHhPHjYZf6 fi4zi03PBlomBGZ5LrQ5anPmur5+01gGTYYS8DE7zUhDSJs+oEBK3K2JJCIauA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dGrt0296Dz12fV for ; Wed, 26 Nov 2025 20:35:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 30e8f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 26 Nov 2025 20:35:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jose Luis Duran Subject: git: 19e153004fb6 - main - strfmon: Add tests for Austin Group Defect 1199 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jlduran X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 19e153004fb63c32eba0ef40249f5ede61a93170 Auto-Submitted: auto-generated Date: Wed, 26 Nov 2025 20:35:36 +0000 Message-Id: <69276498.30e8f.5ef3e274@gitrepo.freebsd.org> The branch main has been updated by jlduran: URL: https://cgit.FreeBSD.org/src/commit/?id=19e153004fb63c32eba0ef40249f5ede61a93170 commit 19e153004fb63c32eba0ef40249f5ede61a93170 Author: Jose Luis Duran AuthorDate: 2025-11-26 20:34:55 +0000 Commit: Jose Luis Duran CommitDate: 2025-11-26 20:34:55 +0000 strfmon: Add tests for Austin Group Defect 1199 Add tests for The Open Group Base Specifications Issue 8[1], Austin Group Defect 1199[2]. Items marked with XXX represent an invalid output. These items will be fixed in subsequent commits. Notice that an existing test is now considered invalid. Our locale definitions do not include int_p_sep_by_space nor int_n_sep_by_space[3]. Those will be addressed in a subsequent commit. However, the CLDR project defines them as "0", which causes the output to appear as "USD123.45". If our locale definitions were to set the international {n,p}_sep_by_space to "1", the output would display as the expected "USD 123.45". While here, use the SPDX license identifier and add my name to the file. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html [2]: https://www.austingroupbugs.net/view.php?id=1199 [3]: https://unicode-org.atlassian.net/browse/CLDR-237 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53911 --- lib/libc/tests/stdlib/strfmon_test.c | 80 +++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index 86f6256dba0b..3c97d61ba82c 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -1,31 +1,14 @@ -/*- - * Copyright (C) 2018 Conrad Meyer +/* + * Copyright (c) 2018 Conrad Meyer * All rights reserved. + * Copyright (c) 2022-2025 Jose Luis Duran * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include #include @@ -208,6 +191,56 @@ ATF_TC_BODY(strfmon_international_currency_code, tc) } } +ATF_TC_WITHOUT_HEAD(strfmon_plus_or_parenthesis); +ATF_TC_BODY(strfmon_plus_or_parenthesis, tc) +{ + const struct { + const char *format; + const char *locale; + const char *expected; + } tests[] = { + { "%+n", "en_US.UTF-8", "[$123.45] [-$123.45]" }, + { "%+i", "en_US.UTF-8", "[USD123.45] [-USD123.45]" }, + { "%(n", "C", "[123.45] [(123.45)]" }, + { "%(i", "C", "[123.45] [(123.45)]" }, + { "%(n", "en_US.UTF-8", "[$123.45] [($123.45)]" }, + { "%(i", "en_US.UTF-8", "[USD123.45] [(USD123.45)]" }, + { "%n", "C", "[123.45] [(123.45)]" }, /* XXX */ + { "%i", "C", "[123.45] [(123.45)]" }, /* XXX */ + { "%n", "en_US.UTF-8", "[$123.45] [-$123.45]" }, + { "%i", "en_US.UTF-8", "[USD123.45] [-USD123.45]" }, + }; + size_t i; + char actual[100], format[50]; + + for (i = 0; i < nitems(tests); ++i) { + if (setlocale(LC_MONETARY, tests[i].locale) == NULL) + atf_tc_skip("unable to setlocale(): %s", + tests[i].locale); + + snprintf(format, sizeof(format), "[%s] [%s]", + tests[i].format, tests[i].format); + strfmon(actual, sizeof(actual) - 1, format, + 123.45, -123.45); + ATF_CHECK_STREQ_MSG(tests[i].expected, actual, + "[%s] %s", tests[i].format, tests[i].locale); + } + + /* + * The '+' flag was included in a conversion specification and + * the locale's positive_sign and negative_sign values would + * both be returned by localeconv() as empty strings. + */ + if (setlocale(LC_MONETARY, "C") == NULL) + atf_tc_skip("unable to setlocale(): %s", tests[i].locale); + + /* ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1, + "[%+n] [%+n]", 123.45, -123.45)); XXX */ + + /* ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1, + "[%+i] [%+i]", 123.45, -123.45)); XXX */ +} + ATF_TC(strfmon_l); ATF_TC_HEAD(strfmon_l, tc) { @@ -220,7 +253,7 @@ ATF_TC_BODY(strfmon_l, tc) const char *locale; const char *expected; } tests[] = { - { "C", "[ **1234.57 ] [ **1234.57 ]" }, + { "C", "[ **1234.57 ] [ **1234.57 ]" }, /* XXX */ { "de_DE.UTF-8", "[ **1234,57 €] [ **1.234,57 EUR]" }, { "en_GB.UTF-8", "[ £**1234.57] [ GBP**1,234.57]" }, }; @@ -247,6 +280,7 @@ 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_plus_or_parenthesis); ATF_TP_ADD_TC(tp, strfmon_l); return (atf_no_error()); }