From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 42B023858D33 for ; Fri, 15 Sep 2023 23:17:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42B023858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694819871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7CZueBtS8sv3Nx/9jkzvss8cmhzdJ/wY/7gmAZSIt3Q=; b=EgzG8O5twjTI6jRFgCg+8IebhVKd5EDgaL+ijBjylJDBH51dzfIJU09hFR9HN7niDbkYuo CAfLviJaYHGNEDV31t2CXu8jytb9S+EtCTjw8L+0p6WyxJwz0qLBOpbSAD+QBfIWMXtXkn GKyz+8dyvaahojSQlzxEwJgjg5JR8IU= 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) From: Jonathan Wakely 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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(); +} -- 2.41.0