diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/filesystem/path')
45 files changed, 2753 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc new file mode 100644 index 00000000000..0942d6fdf7e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc @@ -0,0 +1,88 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.3 path appends [fs.path.append] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + const path p("/foo/bar"); + + path pp = p; + pp /= p; + compare_paths( pp, p ); + + path q("baz"); + + path qq = q; + qq /= q; + compare_paths( qq, "baz/baz" ); + + q /= p; + compare_paths( q, p ); + + path r = ""; + r /= path(); + VERIFY( r.empty() ); + + r /= path("rel"); + VERIFY( !r.is_absolute() ); + + path s = "dir/"; + s /= path("/file"); + compare_paths( s, "/file" ); + + s = "dir/"; + s /= path("file"); + compare_paths( s, "dir/file" ); +} + +void +test02() +{ + // C++17 [fs.path.append] p4 + + path p = path("//host") / "foo"; + compare_paths( p, "//host/foo" ); + + path pp = path("//host/") / "foo"; + compare_paths( pp, "//host/foo" ); + + path q = path("foo") / ""; + compare_paths( q, "foo/" ); + + path qq = path("foo") / "/bar"; + compare_paths( qq, "/bar" ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc new file mode 100644 index 00000000000..d8797cae168 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p0 = s, p1, p2, p3, p4; + + p1 = s; + compare_paths(p0, p1); + + p2 = s.c_str(); + compare_paths(p0, p2); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + + p3 = ws; + compare_paths(p0, p3); + + p4 = ws.c_str(); + compare_paths(p0, p4); +#endif + } +} + +void +test02() +{ + for (std::string s : __gnu_test::test_paths) + { + path p0 = s, p1, p2, p3, p4, p5, p6, p7, p8; + + p1.assign(s); + compare_paths(p0, p1); + + p2.assign( s.begin(), s.end() ); + compare_paths(p0, p2); + + p3.assign( s.c_str() ); + compare_paths(p0, p3); + + p4.assign( s.c_str(), s.c_str() + s.size() ); + compare_paths(p0, p4); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + + p5.assign(ws); + compare_paths(p0, p5); + + p6.assign( ws.begin(), ws.end() ); + compare_paths(p0, p6); + + p7.assign( ws.c_str() ); + compare_paths(p0, p7); + + p8.assign( ws.c_str(), ws.c_str() + ws.size() ); + compare_paths(p0, p8); +#endif + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc new file mode 100644 index 00000000000..27bf00ab126 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +#include <filesystem> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy; + copy = p; + __gnu_test::compare_paths(p, copy); + } +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + path move; + move = std::move(copy); + __gnu_test::compare_paths(p, move); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc new file mode 100644 index 00000000000..e444220ec25 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/foo/bar"); + VERIFY( p.compare(p) == 0 ); + VERIFY( p.compare("/foo//bar") == 0 ); + + path q("/foo/baz"); + VERIFY( p.compare(q) < 0 ); + VERIFY( q.compare(p) > 0 ); + + path r("/foo/bar/."); + VERIFY( p.compare(r) < 0 ); + + VERIFY( path("a/b/").compare("a/b//") == 0 ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc new file mode 100644 index 00000000000..4bed5a23fd5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + const path p0 = "/a/a/b/b"; + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.compare(p) == 0 ); + int cmp = p.compare(p0); + if (cmp == 0) + VERIFY( p0.compare(p) == 0 ); + else if (cmp < 0) + VERIFY( p0.compare(p) > 0 ); + else if (cmp > 0) + VERIFY( p0.compare(p) < 0 ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc new file mode 100644 index 00000000000..be8f8b0d709 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + const std::string s0 = "/a/a/b/b"; + const path p0 = s0; + for (const std::string& s : __gnu_test::test_paths) + { + path p(s); + VERIFY( p.compare(s) == 0 ); + VERIFY( p.compare(s.c_str()) == 0 ); + VERIFY( p.compare(p0) == p.compare(s0) ); + VERIFY( p.compare(p0) == p.compare(s0.c_str()) ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc new file mode 100644 index 00000000000..1a987c1966b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.4 path concatenation [fs.path.concat] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + const path p("/foo/bar"); + + path pp = p; + pp += p; + compare_paths( pp, "/foo/bar/foo/bar" ); + + path q("foo/bar"); + + path qq = q; + qq += q; + compare_paths( qq, "foo/barfoo/bar" ); + + q += p; + compare_paths( q, "foo/bar/foo/bar" ); +} + +void +test02() +{ + for (path p : __gnu_test::test_paths) + { + auto prior_native = p.native(); + path x("//blah/di/blah"); + p += x; + VERIFY( p.native() == prior_native + x.native() ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc new file mode 100644 index 00000000000..8d298f8a57d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.4 path concatenation [fs.path.concat] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/"); + p += path::string_type("foo"); + VERIFY( p.filename() == "foo" ); + p += "bar"; + VERIFY( p.filename() == "foobar" ); + p += '/'; + VERIFY( p.parent_path() == "/foobar" && p.filename() == "" ); +#if _GLIBCXX_USE_WCHAR_T + p += L"baz.txt"; +#else + p += "baz.txt"; +#endif + VERIFY( p.filename() == "baz.txt" ); + p.concat("/dir/"); + VERIFY( p.parent_path() == "/foobar/baz.txt/dir" && p.filename() == "" ); + std::string file = "file"; + p.concat(file.begin(), file.end()); + VERIFY( p.filename() == "file" ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc new file mode 100644 index 00000000000..cb084bdfeda --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + __gnu_test::compare_paths(p, copy); + } +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + path move = std::move(copy); + __gnu_test::compare_paths(p, move); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc new file mode 100644 index 00000000000..85ce129436d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p; + VERIFY( p.empty() ); + VERIFY( !p.has_root_path() ); + VERIFY( !p.has_root_name() ); + VERIFY( !p.has_root_directory() ); + VERIFY( !p.has_relative_path() ); + VERIFY( !p.has_parent_path() ); + VERIFY( !p.has_filename() ); + VERIFY( !p.has_stem() ); + VERIFY( !p.has_extension() ); + VERIFY( !p.is_absolute() ); + VERIFY( p.is_relative() ); + VERIFY( std::distance(p.begin(), p.end()) == 0 ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc new file mode 100644 index 00000000000..e7ed19cafe9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc @@ -0,0 +1,116 @@ +// Copyright (C) 2017 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 "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + auto s = [&]() -> path::string_type { return "foo/bar"; }; + path p0(s()); + path p1(s(), path::auto_format); + VERIFY( p1 == p0 ); + path p2(s(), path::native_format); + VERIFY( p2 == p0 ); + path p3(s(), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test02() +{ + path::string_type s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test03() +{ + const char* s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test04() +{ + const char s[] = "foo/bar"; + path p0(std::begin(s), std::end(s)); + path p1(std::begin(s), std::end(s), path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test05() +{ + const char* s = "foo/bar"; + std::locale loc; + path p0(s, loc); + path p1(s, loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test06() +{ + const char s[] = "foo/bar"; + std::locale loc; + path p0(std::begin(s), std::end(s), loc); + path p1(std::begin(s), std::end(s), loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc new file mode 100644 index 00000000000..8bbff810652 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.1 path constructors [fs.path.construct] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/foo/bar", std::locale::classic()); + VERIFY( p.native() == "/foo/bar" ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc new file mode 100644 index 00000000000..ad2cc18e512 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc @@ -0,0 +1,112 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <string> +#include <testsuite_fs.h> +#include <testsuite_iterators.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p1 = s; + path p2( s.begin(), s.end() ); + path p3( s.c_str() ); + path p4( s.c_str(), s.c_str() + s.size() ); + + compare_paths(p1, p2); + compare_paths(p1, p3); + compare_paths(p1, p4); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + path p5 = ws; + path p6( ws.begin(), ws.end() ); + path p7( ws.c_str() ); + path p8( ws.c_str(), ws.c_str() + ws.size() ); + + compare_paths(p1, p5); + compare_paths(p1, p6); + compare_paths(p1, p7); + compare_paths(p1, p8); +#endif + + using __gnu_test::test_container; + using __gnu_test::input_iterator_wrapper; + // Test with input iterators and const value_types + + test_container<char, input_iterator_wrapper> + r1((char*)s.c_str(), (char*)s.c_str() + s.size()); + path p9(r1.begin(), r1.end()); + compare_paths(p1, p9); + + test_container<char, input_iterator_wrapper> + r2((char*)s.c_str(), (char*)s.c_str() + s.size() + 1); // includes null-terminator + path p10(r2.begin()); + compare_paths(p1, p10); + + test_container<const char, input_iterator_wrapper> + r3(s.c_str(), s.c_str() + s.size()); + path p11(r3.begin(), r3.end()); + compare_paths(p1, p11); + + test_container<const char, input_iterator_wrapper> + r4(s.c_str(), s.c_str() + s.size() + 1); // includes null-terminator + path p12(r4.begin()); + compare_paths(p1, p12); + +#if _GLIBCXX_USE_WCHAR_T + // Test with input iterators and const value_types + test_container<wchar_t, input_iterator_wrapper> + r5((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size()); + path p13(r5.begin(), r5.end()); + compare_paths(p1, p13); + + test_container<wchar_t, input_iterator_wrapper> + r6((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size() + 1); // includes null-terminator + path p14(r6.begin()); + compare_paths(p1, p14); + + test_container<const wchar_t, input_iterator_wrapper> + r7(ws.c_str(), ws.c_str() + ws.size()); + path p15(r7.begin(), r7.end()); + compare_paths(p1, p15); + + test_container<const wchar_t, input_iterator_wrapper> + r8(ws.c_str(), ws.c_str() + ws.size() + 1); // includes null-terminator + path p16(r8.begin()); + compare_paths(p1, p16); +#endif + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc new file mode 100644 index 00000000000..b9a52058791 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc @@ -0,0 +1,56 @@ +// { dg-options "-lstdc++fs -std=gnu++17" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2016-2017 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/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <string_view> +#include <string> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p1 = s; + std::string_view sv(s); + path p2 = sv; + compare_paths(p1, p2); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + path p3 = ws; + std::wstring_view wsv(ws); + path p4 = wsv; + compare_paths(p1, p4); +#endif + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc new file mode 100644 index 00000000000..13c9db275a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").extension() == path(".txt") ); + VERIFY( path("/foo/bar.baz.txt").extension() == path(".txt") ); + VERIFY( path(".bar.baz.txt").extension() == path(".txt") ); + + VERIFY( path(".profile").extension() == path("") ); + VERIFY( path(".profile.old").extension() == path(".old") ); + VERIFY( path("..abc").extension() == path(".abc") ); + VERIFY( path("...abc").extension() == path(".abc") ); + VERIFY( path("abc..def").extension() == path(".def") ); + VERIFY( path("abc...def").extension() == path(".def") ); + VERIFY( path("abc.").extension() == path(".") ); + VERIFY( path("abc..").extension() == path(".") ); + VERIFY( path("abc.d.").extension() == path(".") ); + VERIFY( path("..").extension() == path("") ); + VERIFY( path(".").extension() == path("") ); + + VERIFY( path().extension() == path() ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + auto stem = p.stem(); + auto ext = p.extension(); + auto file = p.filename(); + VERIFY( stem.native() + ext.native() == file.native() ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc new file mode 100644 index 00000000000..8ba0fcc8cb9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// C++17 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").filename() == "bar.txt" ); + VERIFY( path("/foo/bar").filename() == "bar" ); + VERIFY( path("/foo/bar/").filename() == "" ); + VERIFY( path("/").filename() == "" ); +#ifdef __CYGWIN__ + VERIFY( path("//host").filename() == "" ); +#else + VERIFY( path("//host").filename() == "host" ); +#endif + VERIFY( path(".").filename() == "." ); + VERIFY( path("..").filename() == ".." ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path f = p.filename(); + if (p.empty()) + VERIFY( f.empty() ); + else + { + const path back = *--p.end(); + if (back.has_root_path()) + VERIFY( f.empty() ); + else + VERIFY( f == back ); + } + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc new file mode 100644 index 00000000000..c46566dad40 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p0; + VERIFY( p0.parent_path() == p0 ); + path p1 = "foo"; + VERIFY( p1.parent_path() == p0 ); + path p2 = "foo/bar"; + VERIFY( p2.parent_path() == p1 ); + path p3 = "/foo/bar"; + VERIFY( p3.parent_path() == path("/foo") ); + VERIFY( p3.parent_path().parent_path() == path("/") ); + VERIFY( p3.parent_path().parent_path().parent_path() == path("/") ); + path p4 = "/"; + VERIFY( p4.parent_path() == p4 ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + if (p.begin() == p.end()) + continue; + if (p.has_relative_path()) + { + path pp; + for (auto i = p.begin(), end = --p.end(); i != end; ++i) + { + pp /= *i; + } + VERIFY( p.parent_path() == pp ); + } + else + VERIFY( p.parent_path() == p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc new file mode 100644 index 00000000000..c8649724671 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo"; + VERIFY( p1.relative_path() == p1 ); + path p2 = "foo/bar"; + VERIFY( p2.relative_path() == p2 ); + path p3 = "/foo/bar"; + VERIFY( p3.relative_path() == p2 ); +} + +#include <iostream> // XXX + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + bool after_root = false; + const path prel = p.relative_path(); + VERIFY( !prel.has_root_name() ); + path rel; + for (const auto& cmpt : p) + { + if (!cmpt.has_root_path()) + after_root = true; + if (after_root) + rel /= cmpt; + } + if (prel != rel) + std::cout << prel << ' ' << rel << '\n'; + VERIFY( prel == rel ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc new file mode 100644 index 00000000000..8cd1976a946 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo/bar"; + VERIFY( p1.root_directory() == path() ); + path p2 = "/foo/bar"; + VERIFY( p2.root_directory() == path("/") ); + path p3 = "//foo"; + VERIFY( p3.root_directory() == path("/") ); + path p4 = "///foo"; + VERIFY( p4.root_directory() == path("/") ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path rootdir = p.root_directory(); + VERIFY( !rootdir.has_relative_path() ); + VERIFY( rootdir.empty() || rootdir.native() == "/"); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc new file mode 100644 index 00000000000..5bb2ccd177e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").extension() == ".txt" ); + VERIFY( path("/foo/bar.baz.txt").extension() == ".txt" ); + VERIFY( path(".").extension().empty() ); + VERIFY( path("..").extension().empty() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc new file mode 100644 index 00000000000..bce0134a447 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// C++17 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo/bar"; + VERIFY( p1.root_path() == path() ); + path p2 = "/foo/bar"; + VERIFY( p2.root_path() == path("/") ); +} + +#undef VERIFY +#define VERIFY(X) do { if (!(X)) { __builtin_puts("FAIL: " #X); } } while(false) +#define DUMP(X, Y, Z) do { if (!(Y == Z)) { __builtin_printf("%s %s %s\n", X.c_str(), Y.c_str(), Z.c_str()); } } while(false) + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path rootp = p.root_path(); + path rootn = p.root_name(); + path rootd = p.root_directory(); + VERIFY( rootp == (rootn / rootd) ); + DUMP(p, rootp , (rootn / rootd) ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc new file mode 100644 index 00000000000..aec64e172ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").stem() == path("bar") ); + path p = "foo.bar.baz.tar"; + std::vector<std::string> v; + for (; !p.extension().empty(); p = p.stem()) + v.push_back(p.extension().native()); + VERIFY( v.at(0) == ".tar" ); + VERIFY( v.at(1) == ".baz" ); + VERIFY( v.at(2) == ".bar" ); + + VERIFY( path(".profile").stem() == path(".profile") ); + VERIFY( path(".profile.old").stem() == path(".profile") ); + VERIFY( path("..abc").stem() == path(".") ); + VERIFY( path("...abc").stem() == path("..") ); + VERIFY( path("abc..def").stem() == path("abc.") ); + VERIFY( path("abc...def").stem() == path("abc..") ); + VERIFY( path("abc.").stem() == path("abc") ); + VERIFY( path("abc..").stem() == path("abc.") ); + VERIFY( path("abc.d.").stem() == path("abc.d") ); + VERIFY( path("..").stem() == path("..") ); + VERIFY( path(".").stem() == path(".") ); + + VERIFY( path().stem() == path() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc new file mode 100644 index 00000000000..df3b7154ab3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc @@ -0,0 +1,128 @@ +// Copyright (C) 2017 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 "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p2 + compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" ); + compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" ); +} + +void +test02() +{ + compare_paths( path("foo/../bar").lexically_normal(), "bar" ); + compare_paths( path("../foo/../bar").lexically_normal(), "../bar" ); + compare_paths( path("foo/../").lexically_normal(), "." ); + compare_paths( path("../../").lexically_normal(), "../.." ); + compare_paths( path("../").lexically_normal(), ".." ); + compare_paths( path("./").lexically_normal(), "." ); + compare_paths( path().lexically_normal(), "" ); + + compare_paths( path("/..").lexically_normal(), "/" ); + + // PR libstdc++/82777 + compare_paths( path("./a/b/c/../.././b/c").lexically_normal(), "a/b/c" ); + compare_paths( path("/a/b/c/../.././b/c").lexically_normal(), "/a/b/c" ); +} + +void +test03() +{ + struct + { + const char* input; + const char* normalized; + } testcases[] = { + {"" , "" }, + {"." , "." }, + {".." , ".." }, + {"/" , "/" }, + {"//" , "//" }, + + {"/foo" , "/foo" }, + {"/foo/" , "/foo/" }, + {"/foo/." , "/foo/" }, + {"/foo/bar/.." , "/foo/" }, + {"/foo/.." , "/" }, + + {"/." , "/" }, + {"/./" , "/" }, + {"/./." , "/" }, + {"/././" , "/" }, + {"/././." , "/" }, + + {"./" , "." }, + {"./." , "." }, + {"././" , "." }, + {"././." , "." }, + {"./././" , "." }, + {"./././." , "." }, + + {"foo/.." , "." }, + {"foo/../" , "." }, + {"foo/../.." , ".." }, + + // with root name (OS-dependent): +#if defined(_WIN32) && !defined(__CYGWIN__) + {"C:bar/.." , "C:." }, +#else + {"C:bar/.." , "." }, +#endif + {"C:/bar/.." , "C:/" }, + {"C:" , "C:" }, +#ifdef __CYGWIN__ + {"//host/bar/.." , "//host/" }, + {"//host" , "//host" }, +#else + {"//host/bar/.." , "/host/" }, + {"//host" , "/host" }, +#endif + + // a few others: + {"foo/../foo/.." , "." }, + {"foo/../foo/../.." , ".." }, + {"../foo/../foo/.." , ".." }, + {"../.f/../f" , "../f" }, + {"../f/../.f" , "../.f" }, + {".././../." , "../.." }, + {".././.././" , "../.." }, + {"/.." , "/" }, + }; + for (auto& test : testcases) + compare_paths( path(test.input).lexically_normal(), test.normalized ); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc new file mode 100644 index 00000000000..ee77e16d1f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2017 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 "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p5 + compare_paths( path("/a/d").lexically_proximate("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_proximate("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c"), "." ); + compare_paths( path("a/b").lexically_proximate("c/d"), "../../a/b" ); +} + +void +test02() +{ + path p = "a/b/c"; + compare_paths( p.lexically_proximate(p), "." ); + compare_paths( p.lexically_proximate("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_proximate("../../../"), p ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc new file mode 100644 index 00000000000..3e78344a618 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2017 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 "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p5 + compare_paths( path("/a/d").lexically_relative("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_relative("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_relative("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_relative("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_relative("a/b/c"), "." ); + compare_paths( path("a/b").lexically_relative("c/d"), "../../a/b" ); +} + +void +test02() +{ + path p = "a/b/c"; + compare_paths( p.lexically_relative(p), "." ); + compare_paths( p.lexically_relative("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_relative("../../../"), "" ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc new file mode 100644 index 00000000000..78224339b42 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2017 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/>. + +// C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path().generic_string() == "" ); + VERIFY( path("/").generic_string() == "/" ); + VERIFY( path("////").generic_string() == "/" ); +#ifdef __CYGWIN__ + VERIFY( path("//a").generic_string() == "//a" ); + VERIFY( path("//a/").generic_string() == "//a/" ); + VERIFY( path("//a/b").generic_string() == "//a/b" ); +#else + VERIFY( path("//a").generic_string() == "/a" ); + VERIFY( path("//a/").generic_string() == "/a/" ); + VERIFY( path("//a/b").generic_string() == "/a/b" ); +#endif + VERIFY( path("/a//b").generic_string() == "/a/b" ); + VERIFY( path("/a//b/").generic_string() == "/a/b/" ); + VERIFY( path("/a//b//").generic_string() == "/a/b/" ); + VERIFY( path("/a//b//.").generic_string() == "/a/b/." ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc new file mode 100644 index 00000000000..7754140a714 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc @@ -0,0 +1,127 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// C++17 30.10.7.5 path iterators [fs.path.itr] + +#include <filesystem> +#include <vector> +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p; + VERIFY( p.begin() == p.end() ); + + std::vector<path> v, v2; + + p = "/"; + v.assign(p.begin(), p.end()); + v2 = { "/" }; + VERIFY( v == v2 ); + + p = "filename"; + v.assign(p.begin(), p.end()); + v2 = { "filename" }; + VERIFY( v == v2 ); + + p = "dir/."; + v.assign(p.begin(), p.end()); + v2 = { "dir", "." }; + VERIFY( v == v2 ); + + p = "dir/"; + v.assign(p.begin(), p.end()); + v2 = { "dir", "" }; + VERIFY( v == v2 ); + + p = "//rootname/dir/."; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "." }; +#else + v2 = { "/", "rootname", "dir", "." }; +#endif + VERIFY( v == v2 ); + + p = "//rootname/dir/"; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "" }; +#else + v2 = { "/", "rootname", "dir", "" }; +#endif + VERIFY( v == v2 ); + + p = "//rootname/dir/filename"; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "filename" }; +#else + v2 = { "/", "rootname", "dir", "filename" }; +#endif + VERIFY( v == v2 ); +} + +void +test02() +{ + using reverse_iterator = std::reverse_iterator<path::iterator>; + std::vector<path> fwd, rev; + + for (const path& p : __gnu_test::test_paths) + { + const auto begin = p.begin(), end = p.end(); + fwd.assign(begin, end); + rev.assign(reverse_iterator(end), reverse_iterator(begin)); + VERIFY( fwd.size() == rev.size() ); + VERIFY( std::equal(fwd.begin(), fwd.end(), rev.rbegin()) ); + } +} + +void +test03() +{ + path paths[] = { "single", "multiple/elements" }; + for (const path& p : paths) + for (auto iter = p.begin(); iter != p.end(); ++iter) + { + auto iter2 = iter; + ++iter; + iter2++; + VERIFY( iter2 == iter ); + --iter; + iter2--; + VERIFY( iter2 == iter ); + } +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc new file mode 100644 index 00000000000..31d984f1aa0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.5 path modifiers [path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + for (path p : __gnu_test::test_paths) + { + path empty; + p.clear(); + VERIFY( p.empty() ); + __gnu_test::compare_paths(p, empty); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc new file mode 100644 index 00000000000..6e306a41c2b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +template<typename T, T sep> +struct checker +{ + static void check(const char* s) { } +}; + +template<> +struct checker<char, '/'> +{ + static void check() + { + VERIFY( path("foo/bar").make_preferred() == "foo/bar" ); + } +}; + +template<> +struct checker<wchar_t, L'\\'> +{ + static void check() + { + VERIFY( path("foo/bar").make_preferred() == L"foo\\bar" ); + } +}; + +void +test01() +{ + checker<path::value_type, path::preferred_separator>::check(); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc new file mode 100644 index 00000000000..cb764cd1585 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// C++17 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.modifiers] p8 + compare_paths( path("foo/bar").remove_filename(), "foo/" ); + compare_paths( path("foo/").remove_filename() , "foo/" ); + compare_paths( path("/foo").remove_filename() , "/" ); + compare_paths( path("/").remove_filename() , "/" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2(p); + p2.remove_filename(); + p2 /= p.filename(); + compare_paths( p2, p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc new file mode 100644 index 00000000000..fca189ce040 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + compare_paths( path("/foo.txt").replace_extension("cpp"), "/foo.cpp" ); + compare_paths( path("/foo.txt").replace_extension(".cpp"), "/foo.cpp" ); + compare_paths( path("/").replace_extension("bar"), "/.bar" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2 = p; + compare_paths( p2.replace_extension(p2.extension()), p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc new file mode 100644 index 00000000000..d5c36565aca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// C++17 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.modifiers] p11 + compare_paths( path("/foo").replace_filename("bar"), "/bar" ); + compare_paths( path("/").replace_filename("bar") , "/bar" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2(p); + p2.replace_filename(p.filename()); + compare_paths( p2, p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc new file mode 100644 index 00000000000..f1276042a95 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.5 path modifiers [path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + const path p("/foo/bar"); + path p1; + path p2 = p; + p1.swap(p2); + VERIFY( p2.empty() ); + __gnu_test::compare_paths(p1, p); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc new file mode 100644 index 00000000000..23d79700d97 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2016-2017 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 "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std::filesystem; + const std::string s = "abc"; + path p(s); + + VERIFY( p.native() == s ); + VERIFY( p.c_str() == s ); + VERIFY( static_cast<std::string>(p) == s ); + + std::string s2 = p; // implicit conversion + VERIFY( s2 == p.native() ); +} + +void +test02() +{ + using namespace std::filesystem; + const char* s = "abc"; + path p(s); + + auto str = p.string<char>(); + VERIFY( str == u"abc" ); + VERIFY( str == p.string() ); + + auto strw = p.string<wchar_t>(); + VERIFY( strw == L"abc" ); + VERIFY( strw == p.wstring() ); + + auto str16 = p.string<char16_t>(); + VERIFY( str16 == u"abc" ); + VERIFY( str16 == p.u16string() ); + + auto str32 = p.string<char32_t>(); + VERIFY( str32 == U"abc" ); + VERIFY( str32 == p.u32string() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc new file mode 100644 index 00000000000..20f42ac6ee5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.6 path non-member functions [path.non-member] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( hash_value(path("a//b")) == hash_value(path("a/b")) ); + VERIFY( hash_value(path("a/")) == hash_value(path("a//")) ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path pp = p.native(); + VERIFY( hash_value(p) == hash_value(pp) ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc new file mode 100644 index 00000000000..76277a0c9ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const std::string& s : __gnu_test::test_paths) + { + VERIFY( s.empty() == path(s).empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc new file mode 100644 index 00000000000..693bd389dcd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_extension() == !p.extension().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc new file mode 100644 index 00000000000..ce99af3025f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_filename() == !p.filename().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc new file mode 100644 index 00000000000..4e23b249607 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_parent_path() == !p.parent_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc new file mode 100644 index 00000000000..25e2dd5ea29 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_relative_path() == !p.relative_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc new file mode 100644 index 00000000000..66c8df20976 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_directory() == !p.root_directory().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc new file mode 100644 index 00000000000..f9d7157d646 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_name() == !p.root_name().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc new file mode 100644 index 00000000000..f0bdb8156c6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_path() == !p.root_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc new file mode 100644 index 00000000000..18bf0159825 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_stem() == !p.stem().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc new file mode 100644 index 00000000000..c6f6c7f98b1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 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/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.is_relative() == !p.is_absolute() ); + } +} + +int +main() +{ + test01(); +} |