From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 3F133385625C; Mon, 23 May 2022 09:08:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F133385625C MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] stdio-common: Add tst-vfprintf-width-i18n to cover numeric field width X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/master X-Git-Oldrev: 5a5f94af0542f9a35aaa7992c18eb4e2403a29b9 X-Git-Newrev: 21bb8382b62f7dc20b9936bab32658e8fd5952e0 Message-Id: <20220523090815.3F133385625C@sourceware.org> Date: Mon, 23 May 2022 09:08:15 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2022 09:08:15 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=21bb8382b62f7dc20b9936bab32658e8fd5952e0 commit 21bb8382b62f7dc20b9936bab32658e8fd5952e0 Author: Florian Weimer Date: Mon May 23 10:08:18 2022 +0200 stdio-common: Add tst-vfprintf-width-i18n to cover numeric field width Related to bug 28943 and bug 28944. Reviewed-by: Adhemerval Zanella Diff: --- stdio-common/Makefile | 3 ++ stdio-common/tst-vfprintf-width-i18n.c | 95 ++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/stdio-common/Makefile b/stdio-common/Makefile index cb85e949c0..2750334714 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -205,6 +205,7 @@ tests := \ tst-vfprintf-user-type \ tst-vfprintf-width-prec \ tst-vfprintf-width-prec-alloc \ + tst-vfprintf-width-i18n \ tst-wc-printf \ tstdiomisc \ tstgetln \ @@ -283,6 +284,7 @@ LOCALES := \ de_DE.ISO-8859-1 \ de_DE.UTF-8 \ en_US.ISO-8859-1 \ + hi_IN.UTF-8 \ ja_JP.EUC-JP \ ps_AF.UTF-8 \ # LOCALES @@ -296,6 +298,7 @@ $(objpfx)tst-sprintf.out: $(gen-locales) $(objpfx)tst-sscanf.out: $(gen-locales) $(objpfx)tst-swprintf.out: $(gen-locales) $(objpfx)tst-vfprintf-mbs-prec.out: $(gen-locales) +$(objpfx)tst-vfprintf-width-i18n.out: $(gen-locales) endif tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace \ diff --git a/stdio-common/tst-vfprintf-width-i18n.c b/stdio-common/tst-vfprintf-width-i18n.c new file mode 100644 index 0000000000..2355f30d67 --- /dev/null +++ b/stdio-common/tst-vfprintf-width-i18n.c @@ -0,0 +1,95 @@ +/* Test for width of non-ASCII digit sequences. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Behavior is currently inconsistent between %d and %f (bug 28943, + bug 28944). This test intends to capture the status quo. */ + +#include +#include +#include +#include + +static int +do_test (void) +{ + char buf[40]; + + xsetlocale (LC_ALL, "hi_IN.UTF-8"); + + /* Ungrouped, not translated. */ + TEST_COMPARE (sprintf (buf, "%7d", 12345), 7); + TEST_COMPARE_STRING (buf, " 12345"); + TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 10); + TEST_COMPARE_STRING (buf, " 12345.67"); + TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13); + TEST_COMPARE_STRING (buf, " INR12345.67"); + + /* Grouped. */ + TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8); + TEST_COMPARE_STRING (buf, " 12,345"); + TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 11); + TEST_COMPARE_STRING (buf, " 12,345.67"); + TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13); + TEST_COMPARE_STRING (buf, " INR12,345.67"); + + /* Translated. */ + TEST_COMPARE (sprintf (buf, "%I16d", 12345), 16); + TEST_COMPARE_STRING (buf, " १२३४५"); + TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 26); + TEST_COMPARE_STRING (buf, " १२३४५.६७"); + + /* Translated and grouped. */ + TEST_COMPARE (sprintf (buf, "%'I17d", 12345), 17); + TEST_COMPARE_STRING (buf, " १२,३४५"); + TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 26); + TEST_COMPARE_STRING (buf, " १२,३४५.६७"); + + xsetlocale (LC_ALL, "ps_AF.UTF-8"); + + /* Ungrouped, not translated. */ + TEST_COMPARE (sprintf (buf, "%7d", 12345), 7); + TEST_COMPARE_STRING (buf, " 12345"); + TEST_COMPARE (sprintf (buf, "%10.2f", 12345.67), 11); + TEST_COMPARE_STRING (buf, " 12345٫67"); + TEST_COMPARE (strfmon (buf, sizeof (buf), "%^13i", 12345.67), 13); + TEST_COMPARE_STRING (buf, " 12346 AFN"); + + /* Grouped. */ + TEST_COMPARE (sprintf (buf, "%'8d", 12345), 8); + TEST_COMPARE_STRING (buf, " 12٬345"); + TEST_COMPARE (sprintf (buf, "%'11.2f", 12345.67), 13); + TEST_COMPARE_STRING (buf, " 12٬345٫67"); /* Counts characters. */ + TEST_COMPARE (strfmon (buf, sizeof (buf), "%13i", 12345.67), 13); + TEST_COMPARE_STRING (buf, " 12٬346 AFN"); /* Counts bytes. */ + + /* Translated. */ + TEST_COMPARE (sprintf (buf, "%I11d", 12345), 11); + TEST_COMPARE_STRING (buf, " ١٢٣۴٥"); + TEST_COMPARE (sprintf (buf, "%I12.2f", 12345.67), 20); + TEST_COMPARE_STRING (buf, " ١٢٣۴٥٫٦٧"); + + /* Translated and grouped. */ + TEST_COMPARE (sprintf (buf, "%'I13d", 12345), 13); + TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥"); + TEST_COMPARE (sprintf (buf, "%'I12.2f", 12345.67), 21); + TEST_COMPARE_STRING (buf, " ١٢٬٣۴٥٫٦٧"); + + return 0; +} + +#include