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