From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id E65A01F63E for ; Sat, 28 Jan 2023 18:40:48 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=clisp.org header.i=@clisp.org header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=DmW11WvV; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLq7p-0003R3-7m; Sat, 28 Jan 2023 13:40:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLq7m-0003QT-FE for bug-gnulib@gnu.org; Sat, 28 Jan 2023 13:40:26 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.23]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLq7g-0002mT-W2 for bug-gnulib@gnu.org; Sat, 28 Jan 2023 13:40:25 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1674931218; cv=none; d=strato.com; s=strato-dkim-0002; b=rzm6lu5lDmVVtkr2AIp+ppd/KdF2i7CAeyTnxtra5VkH91SiK1/8hSXAUFn8FK/S06 LDAT0O+i0sb/fn/uDRlN082zCTPS8pG8B8m5w+HDXzdFUj4D2o4NfRRl/IhGDNMZwBgn heKDoCoO4hxGH/pyyuwrFvw1J6hH9Q+sCmYB4pTSX+CDD3J0Nju4aQbSLk7xkdPAnKXv V+i9I7Tat6Re27D2EbprAoTyMB6Eumxj+gd5jgHSDv47Gbohn0KZeFU7mbkInqxu/adx 8OFiNDG8cM0wTp8efUwx5jd9LNOy/8OS4dbQrUjI2caNN+0lbcIF7BP5qe+W52xIqNeV oGlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1674931218; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=n+hQXcSadqYZ0pC38eZlZFJ79ueJDKmBrsf0WcVq68A=; b=TWS4tZCsmGdUzR1uvOpHzgygTDUaf4LivsA+Bz1FedQJm3Fp2QNmPVn3IdY05EztEq 7J9ymLVuZuUUTQWlDeK2Af2QAIf1GyDmjqJmcvK0QTJtqLqP7Xrra4WuWeBwF11d5i1i Rm8tmyA8/F9hCe4qEzzJ14lfbY+thh45iSId6+khV61CwEm2TO5rtl9h83e++fEarpcC wGwsdNbFJ1V4TCnD/OBikIPVho4LEAUXe9EUKaGdQERSDDyi/QoVppZJed8dCcoqZ1GT hFks0+KK1yNBt0aXQ2ZGweDw8TbVImiOZdSfAC2du86aBtstt5s27HQrDIYnovJ+UuQo 7kfg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1674931218; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=n+hQXcSadqYZ0pC38eZlZFJ79ueJDKmBrsf0WcVq68A=; b=DmW11WvVHha1Cz7dz3qtaosAOOq9vFgBB/TkHTw9NPVWf34VnOMiQtzhYB3RTXMC1m K0wxZfJFGEHe1wEaqHamsRojko88PYMgmX2uUD6fbRv1YxoYLEK8f9bYlC9sRTCpb8on EPdZjuhL8k+wI1C16pJ2BXZXsijBUADY+aMZlquKvRULhpKPbcBEw5j3tiowcrShHkku ihAc53uuzPJOdZ9Cd/7F7LdLKyGpNCu52qXdxHV0xxwJwA7EHdlM48pERPPy0G56PNTx AKtdK9xGXmqdqZgHCxl9wNmZ19jhz0QOQH34+beIiytnrt250qAg/Lv91MAP2FOmQsbx bliw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPDjvwA7022TV+YfjovfFy3RIl4" Received: from nimes.localnet by smtp.strato.de (RZmta 49.2.2 AUTH) with ESMTPSA id 098542z0SIeINb1 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 28 Jan 2023 19:40:18 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: unistdio/*printf: Fix negative width handling for %U, %lU, %llU Date: Sat, 28 Jan 2023 19:40:18 +0100 Message-ID: <3349434.aEXykhD65X@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=85.215.255.23; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org The same bug as mentioned in exists also in the code that handles Unicode strings (packaged as part of GNU libunistring). When I add some unit tests and create a testdir with the modules unistdio/ulc-asnprintf unistdio/ulc-vasnprintf unistdio/ulc-vasprintf unistdio/ulc-vsnprintf unistdio/ulc-vsprintf unistdio/u8-asnprintf unistdio/u8-vasnprintf unistdio/u8-vasprintf unistdio/u8-vsnprintf unistdio/u8-vsprintf unistdio/u16-asnprintf unistdio/u16-vasnprintf unistdio/u16-vasprintf unistdio/u16-vsnprintf unistdio/u16-vsprintf unistdio/u32-asnprintf unistdio/u32-vasnprintf unistdio/u32-vasprintf unistdio/u32-vsnprintf unistdio/u32-vsprintf I get test failures: FAIL: test-u16-vasnprintf1 FAIL: unistdio/test-u16-vasnprintf2.sh FAIL: unistdio/test-u16-vasnprintf3.sh FAIL: test-u16-vasprintf1 FAIL: test-u16-vsnprintf1 FAIL: test-u16-vsprintf1 FAIL: test-u32-vasnprintf1 FAIL: unistdio/test-u32-vasnprintf2.sh FAIL: unistdio/test-u32-vasnprintf3.sh FAIL: test-u32-vasprintf1 FAIL: test-u32-vsnprintf1 FAIL: test-u32-vsprintf1 FAIL: test-u8-vasnprintf1 FAIL: unistdio/test-u8-vasnprintf2.sh FAIL: unistdio/test-u8-vasnprintf3.sh FAIL: test-u8-vasprintf1 FAIL: test-u8-vsnprintf1 FAIL: test-u8-vsprintf1 FAIL: test-ulc-vasnprintf1 FAIL: unistdio/test-ulc-vasnprintf2.sh FAIL: unistdio/test-ulc-vasnprintf3.sh FAIL: test-ulc-vasprintf1 FAIL: test-ulc-vsnprintf1 FAIL: test-ulc-vsprintf1 This patch fixes them. 2023-01-28 Bruno Haible unistdio/*printf: Fix negative width handling for %U, %lU, %llU. * lib/vasnprintf.c (VASNPRINTF): In the code for %U, %lU, %llU, test for the FLAG_LEFT bit in the flags variable. * tests/unistdio/test-u8-printf1.h (test_xfunction): Add tests for width given as argument for the directives %U, %lU, %llU, %s, %a, %f, %e, %g. * tests/unistdio/test-u16-printf1.h (test_xfunction): Likewise. * tests/unistdio/test-u32-printf1.h (test_xfunction): Likewise. * tests/unistdio/test-ulc-printf1.h (test_xfunction): Likewise. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 0e6220ae18..72b8cdbfa6 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -2130,7 +2130,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, characters = 0; } - if (characters < width && !(dp->flags & FLAG_LEFT)) + if (characters < width && !(flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2175,7 +2175,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2232,7 +2232,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, characters = 0; } - if (characters < width && !(dp->flags & FLAG_LEFT)) + if (characters < width && !(flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2277,7 +2277,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2334,7 +2334,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, characters = 0; } - if (characters < width && !(dp->flags & FLAG_LEFT)) + if (characters < width && !(flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2379,7 +2379,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h index 54fce5630c..843b2f7c20 100644 --- a/tests/unistdio/test-u16-printf1.h +++ b/tests/unistdio/test-u16-printf1.h @@ -83,6 +83,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); @@ -123,6 +141,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); @@ -163,6 +199,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); @@ -211,6 +265,32 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); @@ -278,6 +358,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint16_t *result = my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); @@ -402,6 +520,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint16_t *result = my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); @@ -502,6 +658,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); @@ -532,6 +708,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); @@ -620,6 +816,40 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); @@ -657,6 +887,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); @@ -689,6 +943,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); @@ -722,6 +996,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); @@ -795,6 +1089,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); @@ -850,6 +1168,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); @@ -905,6 +1247,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); diff --git a/tests/unistdio/test-u32-printf1.h b/tests/unistdio/test-u32-printf1.h index 9d2107b852..7737c11a1f 100644 --- a/tests/unistdio/test-u32-printf1.h +++ b/tests/unistdio/test-u32-printf1.h @@ -83,6 +83,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); @@ -123,6 +141,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); @@ -163,6 +199,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); @@ -211,6 +265,32 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); @@ -278,6 +358,44 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint32_t *result = my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); @@ -402,6 +520,44 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint32_t *result = my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); @@ -502,6 +658,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); @@ -532,6 +708,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); @@ -620,6 +816,40 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + static const uint32_t expected2[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + static const uint32_t expected2[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); @@ -657,6 +887,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); @@ -689,6 +943,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); @@ -722,6 +996,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint32_t *result = my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); @@ -795,6 +1089,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); @@ -850,6 +1168,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); @@ -905,6 +1247,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) ASSERT (u32_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint32_t *result = + my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint32_t *result = + my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint32_t *result = my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h index 96673ba1ac..796499cac1 100644 --- a/tests/unistdio/test-u8-printf1.h +++ b/tests/unistdio/test-u8-printf1.h @@ -77,6 +77,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); @@ -113,6 +129,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); @@ -149,6 +181,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); @@ -187,6 +235,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); @@ -238,6 +304,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55); + static const uint8_t expected1[] = " 0x1.cp+0 33"; + static const uint8_t expected2[] = " 0x3.8p-1 33"; + static const uint8_t expected3[] = " 0x7p-2 33"; + static const uint8_t expected4[] = " 0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55); + static const uint8_t expected1[] = "0x1.cp+0 33"; + static const uint8_t expected2[] = "0x3.8p-1 33"; + static const uint8_t expected3[] = "0x7p-2 33"; + static const uint8_t expected4[] = "0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint8_t *result = my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); @@ -298,6 +394,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55); + static const uint8_t expected1[] = " 0x1.cp+0 33"; + static const uint8_t expected2[] = " 0x3.8p-1 33"; + static const uint8_t expected3[] = " 0x7p-2 33"; + static const uint8_t expected4[] = " 0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55); + static const uint8_t expected1[] = "0x1.cp+0 33"; + static const uint8_t expected2[] = "0x3.8p-1 33"; + static const uint8_t expected3[] = "0x7p-2 33"; + static const uint8_t expected4[] = "0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint8_t *result = my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); @@ -348,6 +474,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55); + static const uint8_t expected[] = " 1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55); + static const uint8_t expected[] = "1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); @@ -375,6 +519,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55); + static const uint8_t expected[] = "1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); @@ -446,6 +608,28 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55); + static const uint8_t expected1[] = " 1.750000e+00 33"; + static const uint8_t expected2[] = " 1.750000e+000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55); + static const uint8_t expected1[] = "1.750000e+00 33"; + static const uint8_t expected2[] = "1.750000e+000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); @@ -475,6 +659,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.750000e+00 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55); + static const uint8_t expected[] = "1.750000e+00 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); @@ -504,6 +706,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55); + static const uint8_t expected[] = " 1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55); + static const uint8_t expected[] = "1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); @@ -533,6 +753,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55); + static const uint8_t expected[] = "1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint8_t *result = my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); @@ -596,6 +834,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); @@ -636,6 +890,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); @@ -676,6 +946,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) ASSERT (u8_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint8_t *result = + my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint8_t *result = + my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint8_t *result = my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); diff --git a/tests/unistdio/test-ulc-printf1.h b/tests/unistdio/test-ulc-printf1.h index cd6c66bf82..698b4c7218 100644 --- a/tests/unistdio/test-ulc-printf1.h +++ b/tests/unistdio/test-ulc-printf1.h @@ -71,6 +71,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) ASSERT (strcmp (result, " Hello 33") == 0); free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } { /* FLAG_LEFT. */ char *result = my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); @@ -103,6 +117,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) ASSERT (strcmp (result, " Hello 33") == 0); free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } { /* FLAG_LEFT. */ char *result = my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); @@ -135,6 +163,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) ASSERT (strcmp (result, " Hello 33") == 0); free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } { /* FLAG_LEFT. */ char *result = my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); @@ -169,6 +211,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + { /* FLAG_LEFT. */ char *result = my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); @@ -210,6 +268,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.cp+0 33") == 0 + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); + free (result); + } + { /* Small precision. */ char *result = my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); @@ -254,6 +334,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.cp+0 33") == 0 + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); + free (result); + } + { /* Small precision. */ char *result = my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); @@ -294,6 +396,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.750000 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); @@ -318,6 +436,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.750000 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); @@ -380,6 +514,24 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); @@ -405,6 +557,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.750000e+00 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); @@ -431,6 +599,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.75 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.75 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); @@ -456,6 +640,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + char *result = + my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.75 33") == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + char *result = + my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.75 33") == 0); + free (result); + } + { /* Precision. */ char *result = my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);