| 1 | // { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" } |
| 2 | // { dg-do run { target c++11 } } |
| 3 | // { dg-require-filesystem-ts "" } |
| 4 | |
| 5 | // Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 6 | // |
| 7 | // This file is part of the GNU ISO C++ Library. This library is free |
| 8 | // software; you can redistribute it and/or modify it under the |
| 9 | // terms of the GNU General Public License as published by the |
| 10 | // Free Software Foundation; either version 3, or (at your option) |
| 11 | // any later version. |
| 12 | |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | |
| 18 | // You should have received a copy of the GNU General Public License along |
| 19 | // with this library; see the file COPYING3. If not see |
| 20 | // <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | // 8.5 path iterators [path.itr] |
| 23 | |
| 24 | #include <experimental/filesystem> |
| 25 | #include <vector> |
| 26 | #include <algorithm> |
| 27 | #include <testsuite_hooks.h> |
| 28 | #include <testsuite_fs.h> |
| 29 | |
| 30 | using std::experimental::filesystem::path; |
| 31 | |
| 32 | void |
| 33 | test01() |
| 34 | { |
| 35 | path p; |
| 36 | VERIFY( p.begin() == p.end() ); |
| 37 | |
| 38 | std::vector<path> v, v2; |
| 39 | |
| 40 | p = "/"; |
| 41 | v.assign(p.begin(), p.end()); |
| 42 | v2 = { "/" }; |
| 43 | VERIFY( v == v2 ); |
| 44 | |
| 45 | p = "filename"; |
| 46 | v.assign(p.begin(), p.end()); |
| 47 | v2 = { "filename" }; |
| 48 | VERIFY( v == v2 ); |
| 49 | |
| 50 | p = "dir/"; |
| 51 | v.assign(p.begin(), p.end()); |
| 52 | v2 = { "dir", "." }; |
| 53 | VERIFY( v == v2 ); |
| 54 | |
| 55 | p = "//rootname/dir/"; |
| 56 | v.assign(p.begin(), p.end()); |
| 57 | v2 = { "//rootname", "/", "dir", "." }; |
| 58 | VERIFY( v == v2 ); |
| 59 | |
| 60 | p = "//rootname/dir/filename"; |
| 61 | v.assign(p.begin(), p.end()); |
| 62 | v2 = { "//rootname", "/", "dir", "filename" }; |
| 63 | VERIFY( v == v2 ); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | test02() |
| 68 | { |
| 69 | using reverse_iterator = std::reverse_iterator<path::iterator>; |
| 70 | std::vector<path> fwd, rev; |
| 71 | |
| 72 | for (const path p : __gnu_test::test_paths) |
| 73 | { |
| 74 | const auto begin = p.begin(), end = p.end(); |
| 75 | fwd.assign(begin, end); |
| 76 | rev.assign(reverse_iterator(end), reverse_iterator(begin)); |
| 77 | VERIFY( fwd.size() == rev.size() ); |
| 78 | VERIFY( std::equal(fwd.begin(), fwd.end(), rev.rbegin()) ); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | test03() |
| 84 | { |
| 85 | path paths[] = { "single", "multiple/elements" }; |
| 86 | for (const path& p : paths) |
| 87 | for (auto iter = p.begin(); iter != p.end(); ++iter) |
| 88 | { |
| 89 | auto iter2 = iter; |
| 90 | ++iter; |
| 91 | iter2++; |
| 92 | VERIFY( iter2 == iter ); |
| 93 | --iter; |
| 94 | iter2--; |
| 95 | VERIFY( iter2 == iter ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | int |
| 100 | main() |
| 101 | { |
| 102 | test01(); |
| 103 | test02(); |
| 104 | test03(); |
| 105 | } |