| 1 |
// { dg-do run { target c++17 } } |
| 2 |
|
| 3 |
// Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 8.4.1 path constructors [path.construct] |
| 21 |
|
| 22 |
#include <filesystem> |
| 23 |
#include <string> |
| 24 |
#include <testsuite_fs.h> |
| 25 |
#include <testsuite_iterators.h> |
| 26 |
|
| 27 |
using std::filesystem::path; |
| 28 |
using __gnu_test::compare_paths; |
| 29 |
|
| 30 |
void |
| 31 |
test01() |
| 32 |
{ |
| 33 |
for (std::string s : __gnu_test::test_paths) |
| 34 |
{ |
| 35 |
path p1 = s; |
| 36 |
path p2( s.begin(), s.end() ); |
| 37 |
path p3( s.c_str() ); |
| 38 |
path p4( s.c_str(), s.c_str() + s.size() ); |
| 39 |
|
| 40 |
compare_paths(p1, p2); |
| 41 |
compare_paths(p1, p3); |
| 42 |
compare_paths(p1, p4); |
| 43 |
|
| 44 |
#if _GLIBCXX_USE_WCHAR_T |
| 45 |
std::wstring ws(s.begin(), s.end()); |
| 46 |
path p5 = ws; |
| 47 |
path p6( ws.begin(), ws.end() ); |
| 48 |
path p7( ws.c_str() ); |
| 49 |
path p8( ws.c_str(), ws.c_str() + ws.size() ); |
| 50 |
|
| 51 |
compare_paths(p1, p5); |
| 52 |
compare_paths(p1, p6); |
| 53 |
compare_paths(p1, p7); |
| 54 |
compare_paths(p1, p8); |
| 55 |
#endif |
| 56 |
|
| 57 |
using __gnu_test::test_container; |
| 58 |
using __gnu_test::input_iterator_wrapper; |
| 59 |
// Test with input iterators and const value_types |
| 60 |
|
| 61 |
test_container<char, input_iterator_wrapper> |
| 62 |
r1((char*)s.c_str(), (char*)s.c_str() + s.size()); |
| 63 |
path p9(r1.begin(), r1.end()); |
| 64 |
compare_paths(p1, p9); |
| 65 |
|
| 66 |
test_container<char, input_iterator_wrapper> |
| 67 |
r2((char*)s.c_str(), (char*)s.c_str() + s.size() + 1); // includes null-terminator |
| 68 |
path p10(r2.begin()); |
| 69 |
compare_paths(p1, p10); |
| 70 |
|
| 71 |
test_container<const char, input_iterator_wrapper> |
| 72 |
r3(s.c_str(), s.c_str() + s.size()); |
| 73 |
path p11(r3.begin(), r3.end()); |
| 74 |
compare_paths(p1, p11); |
| 75 |
|
| 76 |
test_container<const char, input_iterator_wrapper> |
| 77 |
r4(s.c_str(), s.c_str() + s.size() + 1); // includes null-terminator |
| 78 |
path p12(r4.begin()); |
| 79 |
compare_paths(p1, p12); |
| 80 |
|
| 81 |
#if _GLIBCXX_USE_WCHAR_T |
| 82 |
// Test with input iterators and const value_types |
| 83 |
test_container<wchar_t, input_iterator_wrapper> |
| 84 |
r5((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size()); |
| 85 |
path p13(r5.begin(), r5.end()); |
| 86 |
compare_paths(p1, p13); |
| 87 |
|
| 88 |
test_container<wchar_t, input_iterator_wrapper> |
| 89 |
r6((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size() + 1); // includes null-terminator |
| 90 |
path p14(r6.begin()); |
| 91 |
compare_paths(p1, p14); |
| 92 |
|
| 93 |
test_container<const wchar_t, input_iterator_wrapper> |
| 94 |
r7(ws.c_str(), ws.c_str() + ws.size()); |
| 95 |
path p15(r7.begin(), r7.end()); |
| 96 |
compare_paths(p1, p15); |
| 97 |
|
| 98 |
test_container<const wchar_t, input_iterator_wrapper> |
| 99 |
r8(ws.c_str(), ws.c_str() + ws.size() + 1); // includes null-terminator |
| 100 |
path p16(r8.begin()); |
| 101 |
compare_paths(p1, p16); |
| 102 |
#endif |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
int |
| 107 |
main() |
| 108 |
{ |
| 109 |
test01(); |
| 110 |
} |