summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/filesystem')
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/path/construct/90281.cc55
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/path/factory/u8path.cc68
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/path/native/alloc.cc93
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/path/native/string.cc27
4 files changed, 243 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90281.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90281.cc
new file mode 100644
index 00000000000..3640b00ec53
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90281.cc
@@ -0,0 +1,55 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-lstdc++fs" }
+// { dg-do run { target c++11 } }
+// { dg-require-filesystem-ts "" }
+
+#include <experimental/filesystem>
+#include <testsuite_hooks.h>
+
+namespace fs = std::experimental::filesystem;
+
+template<bool B = std::is_same<fs::path::value_type, char>::value>
+typename std::enable_if<B, const char*>::type
+code_units()
+{ return "\xf0\x9d\x84\x9e"; }
+
+template<bool B = std::is_same<fs::path::value_type, wchar_t>::value>
+typename std::enable_if<B, const wchar_t*>::type
+code_units()
+{ return L"\xD834\xDD1E"; }
+
+// PR libstdc++/90281
+void
+test01()
+{
+ const fs::path::string_type expected = code_units();
+
+ fs::path p8 = fs::u8path(u8"\U0001D11E");
+ VERIFY( p8.native() == expected );
+ fs::path p16(u"\U0001D11E");
+ VERIFY( p16.native() == expected );
+ fs::path p32(U"\U0001D11E");
+ VERIFY( p32.native() == expected );
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/factory/u8path.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/factory/u8path.cc
new file mode 100644
index 00000000000..bdeb3946a15
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/filesystem/path/factory/u8path.cc
@@ -0,0 +1,68 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-lstdc++fs" }
+// { dg-do run { target c++11 } }
+// { dg-require-filesystem-ts "" }
+
+#include <experimental/filesystem>
+#include <testsuite_hooks.h>
+
+namespace fs = std::experimental::filesystem;
+
+void
+test01()
+{
+ fs::path p = fs::u8path("");
+ VERIFY( p.empty() );
+
+ p = fs::u8path("filename");
+ VERIFY( p.u8string() == u8"filename" );
+
+ p = fs::u8path("\xf0\x9d\x84\x9e");
+ VERIFY( p.u8string() == u8"\U0001D11E" );
+}
+
+void
+test02()
+{
+ // These calls to u8path are undefined, because they fail to meet the
+ // requirement that the input is valid UTF-8 data. For Windows u8path
+ // will fail. For POSIX constructing an invalid path appears to work,
+ // but will fail when converted to a different encoding.
+
+ try {
+ auto p = fs::u8path("\xf0\x9d"); // incomplete surrogate pair
+ p.u16string();
+ VERIFY( false );
+ } catch(const fs::filesystem_error&) {
+ }
+
+ try {
+ auto p = fs::u8path("\xf0"); // incomplete multibyte character
+ p.u16string();
+ VERIFY( false );
+ } catch(const fs::filesystem_error&) {
+ }
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/native/alloc.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/native/alloc.cc
new file mode 100644
index 00000000000..ef9ea67928f
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/filesystem/path/native/alloc.cc
@@ -0,0 +1,93 @@
+// Copyright (C) 2016-2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-lstdc++fs" }
+// { dg-do run { target c++11 } }
+// { dg-require-filesystem-ts "" }
+
+#include <experimental/filesystem>
+#include <string>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+template<typename C>
+ using alloc = __gnu_test::uneq_allocator<C>;
+
+void
+test01()
+{
+ using namespace std::experimental::filesystem;
+ path p;
+
+ auto str = p.string<char>(alloc<char>(1));
+ VERIFY( str == "" );
+ VERIFY( str.get_allocator() == alloc<char>(1) );
+
+#ifdef _GLIBCXX_USE_CHAR8_T
+ auto str8 = p.string<char8_t>(alloc<char8_t>(1));
+ VERIFY( str8 == u8"" );
+ VERIFY( str8.get_allocator() == alloc<char8_t>(1) );
+#endif
+
+ auto strw = p.string<wchar_t>(alloc<wchar_t>(2));
+ VERIFY( strw == L"" );
+ VERIFY( strw.get_allocator() == alloc<wchar_t>(2) );
+
+ auto str16 = p.string<char16_t>(alloc<char16_t>(3));
+ VERIFY( str16 == u"" );
+ VERIFY( str16.get_allocator() == alloc<char16_t>(3) );
+
+ auto str32 = p.string<char32_t>(alloc<char32_t>(4));
+ VERIFY( str32 == U"" );
+ VERIFY( str32.get_allocator() == alloc<char32_t>(4) );
+}
+
+void
+test02()
+{
+ using namespace std::experimental::filesystem;
+ path p = "abcdefghijklmnopqrstuvwxyz";
+
+ auto str = p.string<char>(alloc<char>(1));
+ VERIFY( str == "abcdefghijklmnopqrstuvwxyz" );
+ VERIFY( str.get_allocator() == alloc<char>(1) );
+
+#ifdef _GLIBCXX_USE_CHAR8_T
+ auto str8 = p.string<char8_t>(alloc<char8_t>(1));
+ VERIFY( str8 == u8"abcdefghijklmnopqrstuvwxyz" );
+ VERIFY( str8.get_allocator() == alloc<char8_t>(1) );
+#endif
+
+ auto strw = p.string<wchar_t>(alloc<wchar_t>(2));
+ VERIFY( strw == L"abcdefghijklmnopqrstuvwxyz" );
+ VERIFY( strw.get_allocator() == alloc<wchar_t>(2) );
+
+ auto str16 = p.string<char16_t>(alloc<char16_t>(3));
+ VERIFY( str16 == u"abcdefghijklmnopqrstuvwxyz" );
+ VERIFY( str16.get_allocator() == alloc<char16_t>(3) );
+
+ auto str32 = p.string<char32_t>(alloc<char32_t>(4));
+ VERIFY( str32 == U"abcdefghijklmnopqrstuvwxyz" );
+ VERIFY( str32.get_allocator() == alloc<char32_t>(4) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/native/string.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/native/string.cc
index d6ee7fe9101..b78ba2b1dbf 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/path/native/string.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/path/native/string.cc
@@ -63,9 +63,36 @@ test02()
VERIFY( str32 == p.u32string() );
}
+void
+test03()
+{
+ std::experimental::filesystem::path p;
+ auto str8 = p.u8string();
+ VERIFY( str8 == u8"" );
+ auto str16 = p.u16string();
+ VERIFY( str16 == u"" );
+ auto str32 = p.u32string();
+ VERIFY( str32 == U"" );
+}
+
+void
+test04()
+{
+ // PR libstdc++/90281
+ auto p = std::experimental::filesystem::u8path("\xf0\x9d\x84\x9e");
+ auto str8 = p.u8string();
+ VERIFY( str8 == u8"\U0001D11E" );
+ auto str16 = p.u16string();
+ VERIFY( str16 == u"\U0001D11E" );
+ auto str32 = p.u32string();
+ VERIFY( str32 == U"\U0001D11E" );
+}
+
int
main()
{
test01();
test02();
+ test03();
+ test04();
}