From patchwork Thu Mar 17 19:28:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52065 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F9DB3857C50 for ; Thu, 17 Mar 2022 19:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F9DB3857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545507; bh=lTZSh/hZjah74zYtiDn92Ckw7863fjXcRc5Au79qHyc=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=asngdj7WQdovln2P9DqcBejbPnQiEQzRoGufZi9DekWAFTAlPAcjWlOCnnQObQOJX f3EP/pjlNNNlLBtWmysKCzl/ePAQ4D/CWJ5186wm4n4un4K9Krwqse57jGy870/wvt bBLxPSDGkzzUsqudMJe2piDFEBZINtYRUMUgjBlc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6474D385DC3B for ; Thu, 17 Mar 2022 19:28:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6474D385DC3B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-AV3gg9PhP2mlpba9S3A5Sg-1; Thu, 17 Mar 2022 15:28:36 -0400 X-MC-Unique: AV3gg9PhP2mlpba9S3A5Sg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5184185A79C for ; Thu, 17 Mar 2022 19:28:35 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D3644010A39 for ; Thu, 17 Mar 2022 19:28:35 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width In-Reply-To: References: X-From-Line: f0f166cc7b0b3bef7cd51cdf1788ff429e560396 Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 17 Mar 2022 20:28:33 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Related to bug 28943 and bug 28944. Reviewed-by: Adhemerval Zanella --- stdio-common/Makefile | 1 + stdio-common/tst-printf-width-i18n.c | 95 ++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 stdio-common/tst-printf-width-i18n.c diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 435cd8904f..f0e65f0dcd 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -250,6 +250,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 diff --git a/stdio-common/tst-printf-width-i18n.c b/stdio-common/tst-printf-width-i18n.c new file mode 100644 index 0000000000..2355f30d67 --- /dev/null +++ b/stdio-common/tst-printf-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