| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target { *-*-*mingw* *-*-cygwin } } } |
| 19 |
// { dg-require-effective-target c++17 } |
| 20 |
|
| 21 |
#include <filesystem> |
| 22 |
#include <testsuite_hooks.h> |
| 23 |
|
| 24 |
void |
| 25 |
test01() |
| 26 |
{ |
| 27 |
using std::filesystem::path; |
| 28 |
path p; |
| 29 |
|
| 30 |
// PR libstdc++/94063 |
| 31 |
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS |
| 32 |
p = L"C"; |
| 33 |
p += path(L":"); |
| 34 |
VERIFY( p.has_root_name() ); |
| 35 |
VERIFY( p.root_name() == p ); |
| 36 |
p += path(L"\\"); |
| 37 |
VERIFY( p.has_root_name() ); |
| 38 |
VERIFY( p.has_root_directory() ); |
| 39 |
VERIFY( p.root_name() == L"C:" ); |
| 40 |
VERIFY( p.root_directory() == L"\\" ); |
| 41 |
|
| 42 |
p = L"C"; |
| 43 |
p += L':'; |
| 44 |
VERIFY( p.has_root_name() ); |
| 45 |
VERIFY( p.root_name() == p ); |
| 46 |
p += L'\\'; |
| 47 |
VERIFY( p.has_root_name() ); |
| 48 |
VERIFY( p.has_root_directory() ); |
| 49 |
VERIFY( p.root_name() == L"C:" ); |
| 50 |
VERIFY( p.root_directory() == L"\\" ); |
| 51 |
|
| 52 |
p = L"C:"; |
| 53 |
p += path(L"/foo"); |
| 54 |
VERIFY( p.has_root_name() ); |
| 55 |
VERIFY( p.has_root_directory() ); |
| 56 |
VERIFY( p.root_name() == L"C:" ); |
| 57 |
VERIFY( p.root_directory() == L"/" ); |
| 58 |
VERIFY( p.filename() == L"foo" ); |
| 59 |
|
| 60 |
p = L"C:"; |
| 61 |
p += L"/foo"; |
| 62 |
VERIFY( p.has_root_name() ); |
| 63 |
VERIFY( p.has_root_directory() ); |
| 64 |
VERIFY( p.root_name() == L"C:" ); |
| 65 |
VERIFY( p.root_directory() == L"/" ); |
| 66 |
VERIFY( p.filename() == L"foo" ); |
| 67 |
|
| 68 |
p = L"C"; |
| 69 |
p += path(L":/foo"); |
| 70 |
VERIFY( p.has_root_name() ); |
| 71 |
VERIFY( p.has_root_directory() ); |
| 72 |
VERIFY( p.root_name() == L"C:" ); |
| 73 |
VERIFY( p.root_directory() == L"/" ); |
| 74 |
VERIFY( p.filename() == L"foo" ); |
| 75 |
|
| 76 |
p = L"C"; |
| 77 |
p += L":/foo"; |
| 78 |
VERIFY( p.has_root_name() ); |
| 79 |
VERIFY( p.has_root_directory() ); |
| 80 |
VERIFY( p.root_name() == L"C:" ); |
| 81 |
VERIFY( p.root_directory() == L"/" ); |
| 82 |
VERIFY( p.filename() == L"foo" ); |
| 83 |
#elif defined __CYGWIN__ |
| 84 |
p = "/"; |
| 85 |
p += path("/x"); |
| 86 |
VERIFY( p.has_root_name() ); |
| 87 |
VERIFY( p.root_name() == p ); |
| 88 |
|
| 89 |
p = "/"; |
| 90 |
p += "/x"; |
| 91 |
VERIFY( p.has_root_name() ); |
| 92 |
VERIFY( p.root_name() == p ); |
| 93 |
|
| 94 |
p = "/"; |
| 95 |
p += path("/"); |
| 96 |
VERIFY( !p.has_root_name() ); |
| 97 |
VERIFY( p.has_root_directory() ); |
| 98 |
|
| 99 |
p = "/"; |
| 100 |
p += "/"; |
| 101 |
VERIFY( !p.has_root_name() ); |
| 102 |
VERIFY( p.has_root_directory() ); |
| 103 |
#endif |
| 104 |
} |
| 105 |
|
| 106 |
int |
| 107 |
main() |
| 108 |
{ |
| 109 |
test01(); |
| 110 |
} |