aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-09-16 00:09:53 +0100
committerJonathan Wakely <jwakely@redhat.com>2023-09-16 00:10:44 +0100
commit6693bd900419862a7df97caa347f8289e88c2fe7 (patch)
tree0c37987d37bc773cc395b588078aea30e88b1f60
parentc4baeaecbbf7d0626d44ac0b69b3c8456dddb01a (diff)
downloadgcc-6693bd900419862a7df97caa347f8289e88c2fe7.zip
gcc-6693bd900419862a7df97caa347f8289e88c2fe7.tar.gz
gcc-6693bd900419862a7df97caa347f8289e88c2fe7.tar.bz2
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.
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc55
2 files changed, 116 insertions, 0 deletions
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 0000000..749451a
--- /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 <fstream>
+
+#ifndef __cpp_lib_fstream_native_handle
+# error "Feature-test macro for fstream_native_handle missing in <fstream>"
+#elif __cpp_lib_fstream_native_handle != 202306L
+# error "Feature-test macro for fstream_native_handle has wrong value in <fstream>"
+#endif
+
+using type = std::basic_filebuf<char>::native_handle_type;
+
+#include <cstdio> // std::fclose(FILE*)
+#if __has_include(<unistd.h>)
+# include <unistd.h> // close(int)
+#endif
+#if __has_include(<handleapi.h>)
+# include <handleapi.h> // CloseHandle(HANDLE)
+#endif
+
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::filebuf f;
+ f.open("filebuf_members-1.txt", std::ios::in);
+ type handle = f.native_handle();
+
+ auto native_close = []<typename HandleT>(HandleT handle) {
+ if constexpr (std::is_same_v<HandleT, std::FILE*>)
+ std::fclose(handle); // --enable-cstdio=stdio_pure
+#if __has_include(<unistd.h>)
+ else if constexpr (std::is_same_v<HandleT, int>)
+ ::close(handle); // POSIX
+#endif
+#if __has_include(<handleapi.h>)
+ else if constexpr (std::is_same_v<HandleT, void*>)
+ ::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 0000000..7ee5e4e
--- /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 <fstream>
+
+using type = std::basic_filebuf<wchar_t>::native_handle_type;
+
+#include <cstdio> // std::fclose(FILE*)
+#if __has_include(<unistd.h>)
+# include <unistd.h> // close(int)
+#endif
+#if __has_include(<handleapi.h>)
+# include <handleapi.h> // CloseHandle(HANDLE)
+#endif
+
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::wfilebuf f;
+ f.open("filebuf_members-1.txt", std::wios::in);
+ type handle = f.native_handle();
+
+ auto native_close = []<typename HandleT>(HandleT handle) {
+ if constexpr (std::is_same_v<HandleT, std::FILE*>)
+ std::fclose(handle); // --enable-cstdio=stdio_pure
+#if __has_include(<unistd.h>)
+ else if constexpr (std::is_same_v<HandleT, int>)
+ ::close(handle); // POSIX
+#endif
+#if __has_include(<handleapi.h>)
+ else if constexpr (std::is_same_v<HandleT, void*>)
+ ::CloseHandle(handle); // Windows
+#endif
+ else
+ VERIFY( false );
+ };
+ native_close(handle);
+
+ try
+ {
+ f.sgetc();
+ VERIFY( false );
+ }
+ catch (const std::ios::failure&)
+ {
+ }
+}
+
+int main()
+{
+ test01();
+}