From patchwork Fri Sep 15 23:17:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 140756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1376063vqi; Fri, 15 Sep 2023 16:19:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEEIw3e+S7AcEEl5+GGjyFcejMAw0fOi4Z9TBX8RWSEsh/jZgtqW6cEPTnp3zpB6N8MoVP X-Received: by 2002:a17:906:5a53:b0:9ad:7c48:3239 with SMTP id my19-20020a1709065a5300b009ad7c483239mr2384311ejc.51.1694819983621; Fri, 15 Sep 2023 16:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694819983; cv=none; d=google.com; s=arc-20160816; b=ZkSlxjwmkm377Zv5GBLg2zJl5dvQc0ceTm0vWaNZtzc+4nQ5dDuzDyxd9tGlt+Yrdv ZPcP3AQK4cTnNw6e5qOwdi4PANe4WQyCdewm+3JC5/M53Uxtm6pKq3SdSV3c+ra4GXHN 1rpWzn3dMyf/FEDotAbGNBrPLdWccKJ6RoV9sXXYtU4qcT6sVzoqoBeMqLqyHZ7ng+Od lrch0t9y+SKN3W8/OSFO9u/XQEoNU8D3C/7F8LCZecBOHzbP0bgU+bH6EfZ111a+MEOo A8Al/zV1IpnZut3Ol6rOPsscDA5cnbRXkgmtoIqRuxDosYHuzyOAu5TfHKRr09RyWJ/8 Pfgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7CZueBtS8sv3Nx/9jkzvss8cmhzdJ/wY/7gmAZSIt3Q=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=hSZjBNE3Uu48cTp7Xg3R24+HvjVERxNjIyrM1vcLuJ++VoHWeqroaYLBY32LOIeTFf K9wLvkoRwFrAp8TAnBvhXEDWwtWHKHwgQpbmkkTfCXdG0I1btYqZyjUhzqgleuBGb/mU dB6tOb+xZLLJihpONlMbSf4oceFCWLIvFnM9rzDZgFHJCNNQFWsmQO6DnE8L/80bnexO wt9W38EWeTLYaxMzZZksNdXAUvevrlUdKYStath/IRgpK5+/e3HyrVrjVxoC/m8+EBEj /izYsf8bktaS+NdjW1kwJ5jjEE2z6bkz/tFr8FFRcoed8AzjkcUoLf0PsWcFUBSP5yHq F8/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S+3Uu319; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i13-20020a170906114d00b009a472926f77si4042155eja.219.2023.09.15.16.19.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S+3Uu319; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8160F385483E for ; Fri, 15 Sep 2023 23:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8160F385483E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694819952; bh=7CZueBtS8sv3Nx/9jkzvss8cmhzdJ/wY/7gmAZSIt3Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=S+3Uu319ig2xuI3dVXGN3OTebh0GUeJAqb3yI6570KOsA4NJDpdoYou8h58lzwjL1 zjUAOWBgpMbPbsLPFdWL/3o5we8+Y/uHz8BrAOj+8S7D4+/xXVBd0F+PxGwp9zTnaH cEP52xEyIYygOaxyGjD29MqdJzlhmDrLD0M1B+Lw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.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 AE6DB3858D35 for ; Fri, 15 Sep 2023 23:17:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE6DB3858D35 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-227-fk1tepr6O16FcCr4BhbEgQ-1; Fri, 15 Sep 2023 19:17:50 -0400 X-MC-Unique: fk1tepr6O16FcCr4BhbEgQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6AC381D7A0; Fri, 15 Sep 2023 23:17:49 +0000 (UTC) Received: from localhost (unknown [10.42.28.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C07840C2009; Fri, 15 Sep 2023 23:17:49 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add missing tests for std::basic_filebuf::native_handle() Date: Sat, 16 Sep 2023 00:17:37 +0100 Message-ID: <20230915231748.2348413-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777147559108630775 X-GMAIL-MSGID: 1777147559108630775 Tested aarch64-linux. Pushed to trunk. -- >8 -- I forgot to 'git add' these files in the commit that added the new member function to basic_filebuf. libstdc++-v3/ChangeLog: * testsuite/27_io/basic_filebuf/native_handle/char/1.cc: New test. * testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc: New test. --- .../basic_filebuf/native_handle/char/1.cc | 61 +++++++++++++++++++ .../basic_filebuf/native_handle/wchar_t/1.cc | 55 +++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc new file mode 100644 index 00000000000..749451a4c81 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc @@ -0,0 +1,61 @@ +// { dg-options "-fno-inline" } +// { dg-do run { target c++26 } } +// { dg-additional-files "filebuf_members-1.txt" } + +#include + +#ifndef __cpp_lib_fstream_native_handle +# error "Feature-test macro for fstream_native_handle missing in " +#elif __cpp_lib_fstream_native_handle != 202306L +# error "Feature-test macro for fstream_native_handle has wrong value in " +#endif + +using type = std::basic_filebuf::native_handle_type; + +#include // std::fclose(FILE*) +#if __has_include() +# include // close(int) +#endif +#if __has_include() +# include // CloseHandle(HANDLE) +#endif + +#include + +void +test01() +{ + std::filebuf f; + f.open("filebuf_members-1.txt", std::ios::in); + type handle = f.native_handle(); + + auto native_close = [](HandleT handle) { + if constexpr (std::is_same_v) + std::fclose(handle); // --enable-cstdio=stdio_pure +#if __has_include() + else if constexpr (std::is_same_v) + ::close(handle); // POSIX +#endif +#if __has_include() + else if constexpr (std::is_same_v) + ::CloseHandle(handle); // Windows +#endif + else + VERIFY( false ); + }; + native_close(handle); + + try + { + f.sgetc(); + VERIFY( false ); + } + catch (const std::ios::failure&) + { + } +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc new file mode 100644 index 00000000000..7ee5e4e8f53 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc @@ -0,0 +1,55 @@ +// { dg-options "-fno-inline" } +// { dg-do run { target c++26 } } +// { dg-additional-files "filebuf_members-1.txt" } + +#include + +using type = std::basic_filebuf::native_handle_type; + +#include // std::fclose(FILE*) +#if __has_include() +# include // close(int) +#endif +#if __has_include() +# include // CloseHandle(HANDLE) +#endif + +#include + +void +test01() +{ + std::wfilebuf f; + f.open("filebuf_members-1.txt", std::wios::in); + type handle = f.native_handle(); + + auto native_close = [](HandleT handle) { + if constexpr (std::is_same_v) + std::fclose(handle); // --enable-cstdio=stdio_pure +#if __has_include() + else if constexpr (std::is_same_v) + ::close(handle); // POSIX +#endif +#if __has_include() + else if constexpr (std::is_same_v) + ::CloseHandle(handle); // Windows +#endif + else + VERIFY( false ); + }; + native_close(handle); + + try + { + f.sgetc(); + VERIFY( false ); + } + catch (const std::ios::failure&) + { + } +} + +int main() +{ + test01(); +}