| 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.4.4 path concatenation [path.concat] |
| 23 |
|
| 24 |
#include <experimental/filesystem> |
| 25 |
#include <testsuite_hooks.h> |
| 26 |
#include <testsuite_iterators.h> |
| 27 |
|
| 28 |
using std::experimental::filesystem::path; |
| 29 |
|
| 30 |
void |
| 31 |
test01() |
| 32 |
{ |
| 33 |
path p("/"); |
| 34 |
p += std::string("foo"); |
| 35 |
VERIFY( p.filename().string() == "foo" ); |
| 36 |
p += "bar"; |
| 37 |
VERIFY( p.filename().string() == "foobar" ); |
| 38 |
p += '/'; |
| 39 |
VERIFY( p.parent_path().string() == "/foobar" ); |
| 40 |
VERIFY( p.filename().string() == "." ); |
| 41 |
#if _GLIBCXX_USE_WCHAR_T |
| 42 |
VERIFY( p.parent_path().wstring() == L"/foobar" ); |
| 43 |
VERIFY( p.filename().wstring() == L"." ); |
| 44 |
p += L"baz.txt"; |
| 45 |
#else |
| 46 |
p += "baz.txt"; |
| 47 |
#endif |
| 48 |
VERIFY( p.filename().string() == "baz.txt" ); |
| 49 |
p.concat("/dir/"); |
| 50 |
// N.B. on Windows p.parent_path() is "/foobar\\baz.txt\\dir" |
| 51 |
VERIFY( p.parent_path() == path("/foobar/baz.txt/dir") ); |
| 52 |
VERIFY( p.filename().string() == "." ); |
| 53 |
const char file[] = "file"; |
| 54 |
__gnu_test::test_container<const char, __gnu_test::input_iterator_wrapper> |
| 55 |
input(file, file + 4); |
| 56 |
p.concat(input.begin(), input.end()); |
| 57 |
VERIFY( p.filename().string() == file ); |
| 58 |
} |
| 59 |
|
| 60 |
int |
| 61 |
main() |
| 62 |
{ |
| 63 |
test01(); |
| 64 |
} |