Debian Codegraph @

libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc

raw
1 // Copyright (C) 2017-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 c++17 } }
19
20 #include <filesystem>
21 #include <string.h>
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
24
25 using std::filesystem::path;
26
27 void
28 test01()
29 {
30 // path(string_type&&, format)
31 auto s = [&]() -> path::string_type { return path("foo/bar").native(); };
32 path p0(s());
33 path p1(s(), path::auto_format);
34 VERIFY( p1 == p0 );
35 path p2(s(), path::native_format);
36 VERIFY( p2 == p0 );
37 path p3(s(), path::generic_format);
38 VERIFY( p3 == p0 );
39 }
40
41 void
42 test02()
43 {
44 // path(const Source&, format)
45 const path::string_type s = path("foo/bar").native();
46 path p0(s);
47 path p1(s, path::auto_format);
48 VERIFY( p1 == p0 );
49 path p2(s, path::native_format);
50 VERIFY( p2 == p0 );
51 path p3(s, path::generic_format);
52 VERIFY( p3 == p0 );
53 }
54
55 void
56 test03()
57 {
58 // path(const Source&, format)
59 const std::string s = "foo/bar";
60 path p0(s);
61 path p1(s, path::auto_format);
62 VERIFY( p1 == p0 );
63 path p2(s, path::native_format);
64 VERIFY( p2 == p0 );
65 path p3(s, path::generic_format);
66 VERIFY( p3 == p0 );
67 }
68
69 void
70 test04()
71 {
72 #ifdef _GLIBCXX_USE_WCHAR_T
73 // path(const Source&, format)
74 const std::wstring s = L"foo/bar";
75 path p0(s);
76 path p1(s, path::auto_format);
77 VERIFY( p1 == p0 );
78 path p2(s, path::native_format);
79 VERIFY( p2 == p0 );
80 path p3(s, path::generic_format);
81 VERIFY( p3 == p0 );
82 #endif
83 }
84
85 void
86 test05()
87 {
88 // path(const Source&, format)
89 const char* s = "foo/bar";
90 path p0(s);
91 path p1(s, path::auto_format);
92 VERIFY( p1 == p0 );
93 path p2(s, path::native_format);
94 VERIFY( p2 == p0 );
95 path p3(s, path::generic_format);
96 VERIFY( p3 == p0 );
97 }
98
99 void
100 test06()
101 {
102 // path(InputIterator, InputIterator, format)
103 const char s[] = "foo/bar";
104 using namespace __gnu_test;
105 const test_container<const char, input_iterator_wrapper> c(s, s + strlen(s));
106 auto c0 = c;
107 path p0(std::begin(c0), std::end(c0));
108 auto c1 = c;
109 path p1(std::begin(c1), std::end(c1), path::auto_format);
110 VERIFY( p1 == p0 );
111 auto c2 = c;
112 path p2(std::begin(c2), std::end(c2), path::native_format);
113 VERIFY( p2 == p0 );
114 auto c3 = c;
115 path p3(std::begin(c3), std::end(c3), path::generic_format);
116 VERIFY( p3 == p0 );
117 }
118
119 void
120 test07()
121 {
122 // path(const Source&, const locale&, format)
123 const char* s = "foo/bar";
124 std::locale loc;
125 path p0(s, loc);
126 path p1(s, loc, path::auto_format);
127 VERIFY( p1 == p0 );
128 path p2(s, loc, path::native_format);
129 VERIFY( p2 == p0 );
130 path p3(s, loc, path::generic_format);
131 VERIFY( p3 == p0 );
132 }
133
134 void
135 test08()
136 {
137 // path(InputIterator, InputIterator, const locale&, format)
138 const char s[] = "foo/bar";
139 using namespace __gnu_test;
140 const test_container<const char, input_iterator_wrapper> c(s, s + strlen(s));
141 std::locale loc;
142 auto c0 = c;
143 path p0(std::begin(c0), std::end(c0), loc);
144 auto c1 = c;
145 path p1(std::begin(c1), std::end(c1), loc, path::auto_format);
146 VERIFY( p1 == p0 );
147 auto c2 = c;
148 path p2(std::begin(c2), std::end(c2), loc, path::native_format);
149 VERIFY( p2 == p0 );
150 auto c3 = c;
151 path p3(std::begin(c3), std::end(c3), loc, path::generic_format);
152 VERIFY( p3 == p0 );
153 }
154
155 int
156 main()
157 {
158 test01();
159 test02();
160 test03();
161 test04();
162 test05();
163 test06();
164 test07();
165 test08();
166 }