From patchwork Thu Mar 17 19:28:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52064 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 BC3AC3857815 for ; Thu, 17 Mar 2022 19:30:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC3AC3857815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545459; bh=YVeKXcXLZAdHmPPRPyjmqYRhwaKOUjgjOLmbp40WnRk=; 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=Y+O8bq8BAc3LVpC7fScwzS8CeU0sXhOgP1vRTdNyefAcwe2xFZtSdCu0LHEcioeuc GBQp5qTE0ko7pta1/6egwNx/HeGCw1ptAIoEPUWNXZk2jxq41kBbpObA+76YWjfJeC ZfBrz5zpGYVEGSdUbsXL63y+EdVzXDVmtYNPFc7Y= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id C844A385DC3B for ; Thu, 17 Mar 2022 19:28:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C844A385DC3B Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-fnOts2vdPc6ifAXt3EnpCA-1; Thu, 17 Mar 2022 15:28:29 -0400 X-MC-Unique: fnOts2vdPc6ifAXt3EnpCA-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 0E2BF1C05ABA for ; Thu, 17 Mar 2022 19:28:29 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6224240D2829 for ; Thu, 17 Mar 2022 19:28:28 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type In-Reply-To: References: X-From-Line: f251e498ed050e37063b3cdd2dae82d9a430b8fc Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 17 Mar 2022 20:28:26 +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=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, 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" And use TEST_COMPARE_STRING for the narrow tests. Reviewed-by: Adhemerval Zanella --- stdio-common/tst-vfprintf-user-type.c | 128 ++++++++++++-------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/stdio-common/tst-vfprintf-user-type.c b/stdio-common/tst-vfprintf-user-type.c index f2650ac018..4aa78a6b60 100644 --- a/stdio-common/tst-vfprintf-user-type.c +++ b/stdio-common/tst-vfprintf-user-type.c @@ -21,6 +21,7 @@ this indicates the number of such pairs which constitute the argument. */ +#include #include #include #include @@ -60,13 +61,23 @@ my_printf_function (FILE *fp, const struct printf_info *info, __func__, fp, info, args[0], args, (wint_t) info->spec, info->prec); + TEST_COMPARE (info->wide, fwide (fp, 0) > 0); + TEST_VERIFY (info->spec == 'P'); size_t nargs; int printed; if (info->prec >= 0) { - if (fputc ('{', fp) < 0) - return -1; + if (info->wide) + { + if (fputwc (L'{', fp) < 0) + return -1; + } + else + { + if (fputc ('{', fp) < 0) + return -1; + } nargs = info->prec; printed = 1; } @@ -80,8 +91,16 @@ my_printf_function (FILE *fp, const struct printf_info *info, { if (i != 0) { - if (fputc (',', fp) < 0) - return -1; + if (info->wide) + { + if (fputwc (L',', fp) < 0) + return -1; + } + else + { + if (fputc (',', fp) < 0) + return -1; + } ++printed; } @@ -89,15 +108,27 @@ my_printf_function (FILE *fp, const struct printf_info *info, and those pointers point to a pointer to the memory area supplied to my_va_arg_function. */ struct two_argument *pair = *(void **) args[i]; - int ret = fprintf (fp, "(%ld, %f)", pair->i, pair->d); + int ret; + if (info->wide) + ret = fwprintf (fp, L"(%ld, %f)", pair->i, pair->d); + else + ret = fprintf (fp, "(%ld, %f)", pair->i, pair->d); if (ret < 0) return -1; printed += ret; } if (info->prec >= 0) { - if (fputc ('}', fp) < 0) - return -1; + if (info->wide) + { + if (fputwc (L'}', fp) < 0) + return -1; + } + else + { + if (fputc ('}', fp) < 0) + return -1; + } ++printed; } return printed; @@ -145,77 +176,40 @@ do_test (void) TEST_VERIFY_EXIT (register_printf_specifier ('P', my_printf_function, my_arginfo_function) >= 0); - /* Alias declaration for asprintf, to avoid the format string - attribute and the associated warning. */ -#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 - extern int asprintf_alias (char **, const char *, ...) __asm__ ("__asprintfieee128"); -#else - extern int asprintf_alias (char **, const char *, ...) __asm__ ("asprintf"); -#endif - TEST_VERIFY (asprintf_alias == asprintf); - char *str = NULL; - TEST_VERIFY (asprintf_alias (&str, "[[%P]]", 123L, 456.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, "[[(123, 456.000000)]]") == 0); - free (str); - - str = NULL; - TEST_VERIFY (asprintf_alias (&str, "[[%1$P %1$P]]", 123L, 457.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, "[[(123, 457.000000) (123, 457.000000)]]") == 0); - free (str); - - str = NULL; - TEST_VERIFY (asprintf_alias (&str, "[[%.1P]]", 1L, 2.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, "[[{(1, 2.000000)}]]") == 0); - free (str); + /* Wide variants of the tests above. */ - str = NULL; - TEST_VERIFY (asprintf_alias (&str, "[[%.2P]]", 1L, 2.0, 3L, 4.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, "[[{(1, 2.000000),(3, 4.000000)}]]") == 0); - free (str); + wchar_t buf[200]; + TEST_VERIFY (swprintf (buf, array_length (buf), L"[[%.2P]]", + 1L, 2.0, 3L, 4.0) >= 0); + TEST_COMPARE_STRING_WIDE (buf, L"[[{(1, 2.000000),(3, 4.000000)}]]"); - str = NULL; - TEST_VERIFY (asprintf_alias - (&str, "[[%.2P | %.3P]]", + TEST_VERIFY (swprintf + (buf, array_length (buf), L"[[%.2P | %.3P]]", /* argument 1: */ 1L, 2.0, 3L, 4.0, /* argument 2: */ 5L, 6.0, 7L, 8.0, 9L, 10.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, - "[[" - "{(1, 2.000000),(3, 4.000000)}" - " | " - "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}" - "]]") == 0); - free (str); + TEST_COMPARE_STRING_WIDE (buf, + L"[[" + "{(1, 2.000000),(3, 4.000000)}" + " | " + "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}" + "]]"); /* The following subtest fails due to bug 21534. */ #if 0 - str = NULL; - TEST_VERIFY (asprintf_alias - (&str, "[[%1$.2P | %2$.3P | %1$.2P]]", + TEST_VERIFY (swprintf + (&buf, array_length (buf), L"[[%1$.2P | %2$.3P | %1$.2P]]", /* argument 1: */ 1L, 2.0, 3L, 4.0, /* argument 2: */ 5L, 6.0, 7L, 8.0, 9L, 10.0) >= 0); - if (test_verbose > 0) - printf ("info: %s\n", str); - TEST_VERIFY (strcmp (str, - "[[" - "{(1, 2.000000),(3, 4.000000)}" - " | " - "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}" - " | " - "{(1, 2.000000),(3, 4.000000)}" - "]]") == 0); - free (str); + TEST_COMPARE_STRING_WIDE (buf, + L"[[" + "{(1, 2.000000),(3, 4.000000)}" + " | " + "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}" + " | " + "{(1, 2.000000),(3, 4.000000)}" + "]]"); #endif return 0;