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