]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / path / construct / string_view.cc
CommitLineData
641cb5a6
JW
1// { dg-options "-lstdc++fs -std=gnu++17" }
2// { dg-do run { target c++17 } }
3// { dg-require-filesystem-ts "" }
4
a5544970 5// Copyright (C) 2016-2019 Free Software Foundation, Inc.
641cb5a6
JW
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 3, or (at your option)
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
21
22// 8.4.1 path constructors [path.construct]
23
24#include <filesystem>
25#include <string_view>
26#include <string>
27#include <testsuite_fs.h>
2017595d 28#include <testsuite_hooks.h>
641cb5a6
JW
29
30using std::filesystem::path;
31using __gnu_test::compare_paths;
32
33void
34test01()
35{
36 for (std::string s : __gnu_test::test_paths)
37 {
38 path p1 = s;
39 std::string_view sv(s);
40 path p2 = sv;
41 compare_paths(p1, p2);
42
43#if _GLIBCXX_USE_WCHAR_T
44 std::wstring ws(s.begin(), s.end());
45 path p3 = ws;
46 std::wstring_view wsv(ws);
47 path p4 = wsv;
48 compare_paths(p1, p4);
49#endif
50 }
51}
52
2017595d
JW
53void
54test02()
55{
56 std::string s;
57 for (int i = 0; i < 10; ++i)
58 s += "0/1/2/3/4/5/6/7/8/9/";
59 // Construct a path with a large number of components:
60 path p = s;
61 auto iter = p.begin();
62 for (int i = 0; i < 100; ++i)
63 {
64 char c = '0' + i % 10;
65 std::string_view sv(&c, 1);
66 VERIFY( iter != p.end() );
67 compare_paths( *iter, sv );
68 ++iter;
69 }
70 VERIFY( iter != p.end() );
71 VERIFY( iter->native().empty() );
72 VERIFY( ++iter == p.end() );
73}
74
641cb5a6
JW
75int
76main()
77{
78 test01();
2017595d 79 test02();
641cb5a6 80}