From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id CFD563858D33; Fri, 15 Sep 2023 23:17:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFD563858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694819856; bh=Ks/XS9l3tfSqu8KRRBrRHkOE1EZV+soztL3Kx3DjtR8=; h=From:To:Subject:Date:From; b=CEQeey5NCNk8RKIm+PjE4yAgGsYoAmIsnvy03S5I9umV4Qn7BkrnpChNzQWCea67Z SRqEKihG1ulQEyS+Z4AX3O8aIzcJdXzNxgEox3fQvO736Ua9cuTyGWho74kBVsbQrn R+bI1UZh3YqzCgjkd0SOGksvLK9NK+8CuDxLZPVY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-4061] libstdc++: Add missing tests for std::basic_filebuf::native_handle() X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: c4baeaecbbf7d0626d44ac0b69b3c8456dddb01a X-Git-Newrev: 6693bd900419862a7df97caa347f8289e88c2fe7 Message-Id: <20230915231736.CFD563858D33@sourceware.org> Date: Fri, 15 Sep 2023 23:17:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6693bd900419862a7df97caa347f8289e88c2fe7 commit r14-4061-g6693bd900419862a7df97caa347f8289e88c2fe7 Author: Jonathan Wakely Date: Sat Sep 16 00:09:53 2023 +0100 libstdc++: Add missing tests for std::basic_filebuf::native_handle() 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. Diff: --- .../27_io/basic_filebuf/native_handle/char/1.cc | 61 ++++++++++++++++++++++ .../27_io/basic_filebuf/native_handle/wchar_t/1.cc | 55 +++++++++++++++++++ 2 files changed, 116 insertions(+) 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(); +}