Debian Codegraph @

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

raw
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 #include <testsuite_fs.h>
21
22 using std::filesystem::path;
23 using __gnu_test::compare_paths;
24
25 void
26 test01()
27 {
28 for (std::string s : __gnu_test::test_paths)
29 {
30 path p0 = s, p1, p2, p3, p4;
31
32 p1 = s;
33 compare_paths(p0, p1);
34
35 p2 = s.c_str();
36 compare_paths(p0, p2);
37
38 #if _GLIBCXX_USE_WCHAR_T
39 std::wstring ws(s.begin(), s.end());
40
41 p3 = ws;
42 compare_paths(p0, p3);
43
44 p4 = ws.c_str();
45 compare_paths(p0, p4);
46 #endif
47 }
48 }
49
50 void
51 test02()
52 {
53 for (std::string s : __gnu_test::test_paths)
54 {
55 path p0 = s, p1, p2, p3, p4, p5, p6, p7, p8;
56
57 p1.assign(s);
58 compare_paths(p0, p1);
59
60 p2.assign( s.begin(), s.end() );
61 compare_paths(p0, p2);
62
63 p3.assign( s.c_str() );
64 compare_paths(p0, p3);
65
66 p4.assign( s.c_str(), s.c_str() + s.size() );
67 compare_paths(p0, p4);
68
69 #if _GLIBCXX_USE_WCHAR_T
70 std::wstring ws(s.begin(), s.end());
71
72 p5.assign(ws);
73 compare_paths(p0, p5);
74
75 p6.assign( ws.begin(), ws.end() );
76 compare_paths(p0, p6);
77
78 p7.assign( ws.c_str() );
79 compare_paths(p0, p7);
80
81 p8.assign( ws.c_str(), ws.c_str() + ws.size() );
82 compare_paths(p0, p8);
83 #endif
84 }
85 }
86
87 int
88 main()
89 {
90 test01();
91 test02();
92 }