From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id A37FA3858C2C for ; Fri, 18 Mar 2022 17:40:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A37FA3858C2C Received: by mail-oo1-xc33.google.com with SMTP id s203-20020a4a3bd4000000b003191c2dcbe8so10939592oos.9 for ; Fri, 18 Mar 2022 10:40:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=IBDL9HmPnRcxWdGeAXBOuffP76NAFq6kGuYLjahaVPQ=; b=Oj2iEzsoFkOz1uynCRHtfXQuVS0U/L8R6p5LRV4sjc9WPzBHOaRKpkptL9Zgq4Yw71 l2Fcl2oQ+57nK9f0Tlzl4RoQSgREuDDBZLiIemN22k5tLEWsGTqpRx1xnCt4ySl8gwhp NbkQ4ck8FfKNIQwFAFhTy8cSd8CnPyjaxNkDDT1Ul2iqA8XEY+xjHJ4qHN3bk8y3UXsc yb8nYg75oTKinjNbd1EsqoLmrIXIDQMF7HKnF3f96LkHQ32taNlpn2RpV7e4k/KYY3/m dYE8VQrqsJOdGAeUrFS6ag/vKAErwqd/g10upsZmn9lDcYqLAzCyB2mckjA1Lu4yXxCV Ye2g== X-Gm-Message-State: AOAM530xjG07s92wKWUeyVJyoYd91d/uOQbSuS4mS5S8z4zmMMyufIa2 b2LMvUQiQfcV3azO//ZfQ1EOHXhRQuyHwA== X-Google-Smtp-Source: ABdhPJxYjKI09n6gdtvbVmbmUo5Jb+CQTnSOfmTLZkkgSO5UffK9i7BX9LpFcTyMwPH834Km8h7T/Q== X-Received: by 2002:a05:6870:e302:b0:da:b3f:321f with SMTP id z2-20020a056870e30200b000da0b3f321fmr4342991oad.207.1647625230881; Fri, 18 Mar 2022 10:40:30 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:99a3:99e2:1060:da92:ae49? ([2804:431:c7ca:99a3:99e2:1060:da92:ae49]) by smtp.gmail.com with ESMTPSA id bb39-20020a05680816a700b002d9a8eb89fasm4107283oib.46.2022.03.18.10.40.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Mar 2022 10:40:30 -0700 (PDT) Message-ID: Date: Fri, 18 Mar 2022 14:40:27 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 01/26] libio: Convert tst_swprintf to the test framework Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-List-Received-Date: Fri, 18 Mar 2022 17:40:33 -0000 On 17/03/2022 16:28, Florian Weimer via Libc-alpha wrote: > And increase test coverage slightly. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > libio/tst_swprintf.c | 79 ++++++++++++++++---------------------------- > 1 file changed, 28 insertions(+), 51 deletions(-) > > diff --git a/libio/tst_swprintf.c b/libio/tst_swprintf.c > index e4bd7f022a..5ede402fff 100644 > --- a/libio/tst_swprintf.c > +++ b/libio/tst_swprintf.c > @@ -1,10 +1,11 @@ > +#include > #include > -#include > +#include > #include > +#include > > > static wchar_t buf[100]; > -#define nbuf (sizeof (buf) / sizeof (buf[0])) > static const struct > { > size_t n; > @@ -12,81 +13,57 @@ static const struct > ssize_t exp; > } tests[] = > { > - { nbuf, "hello world", 11 }, > + { array_length (buf), "hello world", 11 }, > { 0, "hello world", -1 }, > + { 1, "hello world", -1 }, > + { 2, "hello world", -1 }, > + { 11, "hello world", -1 }, > + { 12, "hello world", 11 }, > { 0, "", -1 }, > - { nbuf, "", 0 } > + { array_length (buf), "", 0 } > }; > > -int > -main (int argc, char *argv[]) > +static int > +do_test (void) > { > size_t n; > - int result = 0; > > - puts ("test 1"); > - n = swprintf (buf, nbuf, L"Hello %s", "world"); > - if (n != 11) > - { > - printf ("incorrect return value: %zd instead of 11\n", n); > - result = 1; > - } > - else if (wcscmp (buf, L"Hello world") != 0) > - { > - printf ("incorrect string: L\"%ls\" instead of L\"Hello world\"\n", buf); > - result = 1; > - } > + TEST_COMPARE (swprintf (buf, array_length (buf), L"Hello %s", "world"), 11); > + TEST_COMPARE_STRING_WIDE (buf, L"Hello world"); > > - puts ("test 2"); > - n = swprintf (buf, nbuf, L"Is this >%g< 3.1?", 3.1); > - if (n != 18) > - { > - printf ("incorrect return value: %zd instead of 18\n", n); > - result = 1; > - } > - else if (wcscmp (buf, L"Is this >3.1< 3.1?") != 0) > - { > - printf ("incorrect string: L\"%ls\" instead of L\"Is this >3.1< 3.1?\"\n", > - buf); > - result = 1; > - } > + TEST_COMPARE (swprintf (buf, array_length (buf), L"Is this >%g< 3.1?", 3.1), > + 18); > + TEST_COMPARE_STRING_WIDE (buf, L"Is this >3.1< 3.1?"); > > - for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n) > + for (n = 0; n < array_length(tests); ++n) Missing space before '('? > { > ssize_t res = swprintf (buf, tests[n].n, L"%s", tests[n].str); > > if (tests[n].exp < 0 && res >= 0) > { > + support_record_failure (); > printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n", > tests[n].n, tests[n].str); > - result = 1; > } > else if (tests[n].exp >= 0 && tests[n].exp != res) > { > - printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n", > + support_record_failure (); > + printf ("\ > +swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n", > tests[n].n, tests[n].str, tests[n].exp, res); > - result = 1; > } > else > printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n", > tests[n].n, tests[n].str); > } > > - if (swprintf (buf, nbuf, L"%.0s", "foo") != 0 > - || wcslen (buf) != 0) > - { > - printf ("swprintf (buf, %Zu, L\"%%.0s\", \"foo\") create some output\n", > - nbuf); > - result = 1; > - } > + TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0s", "foo"), 0); > + TEST_COMPARE_STRING_WIDE (buf, L""); > > - if (swprintf (buf, nbuf, L"%.0ls", L"foo") != 0 > - || wcslen (buf) != 0) > - { > - printf ("swprintf (buf, %Zu, L\"%%.0ls\", L\"foo\") create some output\n", > - nbuf); > - result = 1; > - } > + TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0ls", L"foo"), 0); > + TEST_COMPARE_STRING_WIDE (buf, L""); > > - return result; > + return 0; > } > + > +#include