From patchwork Thu Mar 17 19:28:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52062 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 497663842405 for ; Thu, 17 Mar 2022 19:29:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 497663842405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545375; bh=SRlGAtDQTMVe6MkY5IGPYa+6Z7oq+Cc7OxaQ1yKABQs=; 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=EKuJZTPznIAofKFTPshSv5n19ENs2TuD+mlEc+W4k0gVvcpEjnOljIfhGQwFC07jx 5xlc44170oe1gx1Xyt91TsBPgaDNp5lg5ZPl6ItDQ1CuT++JKz5hPPx1nXZcyOjVgN IyfgfPDMwkDPGOkr3ZA64JEJ63qJV7uqNsG8YOj0= 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 0F243386549C for ; Thu, 17 Mar 2022 19:28:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0F243386549C 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-414-giJCecvhOraCPZdcaWs9eA-1; Thu, 17 Mar 2022 15:28:15 -0400 X-MC-Unique: giJCecvhOraCPZdcaWs9eA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3C29802803 for ; Thu, 17 Mar 2022 19:28:14 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48776C15D57 for ; Thu, 17 Mar 2022 19:28:14 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 01/26] libio: Convert tst_swprintf to the test framework In-Reply-To: References: X-From-Line: f4a970a0f55f12b3d90869336154a52293e48662 Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 17 Mar 2022 20:28:12 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 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 increase test coverage slightly. 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) { 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