]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/filesystem_error/cons.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / filesystem_error / cons.cc
CommitLineData
a945c346 1// Copyright (C) 2018-2024 Free Software Foundation, Inc.
7f00fdb2
JW
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
ed0b4bb2 18// { dg-options "-lstdc++fs" }
7f00fdb2
JW
19// { dg-do run { target c++11 } }
20// { dg-require-filesystem-ts "" }
21
22#include <experimental/filesystem>
23#include <testsuite_hooks.h>
24
25using std::experimental::filesystem::filesystem_error;
26using std::experimental::filesystem::path;
27
28bool contains(std::string what_str, std::string expected)
29{
30 return what_str.find(expected) != std::string::npos;
31}
32
33void
34test01()
35{
36 const char* const str = "error test";
37 const std::error_code ec = make_error_code(std::errc::is_a_directory);
38 const path p1 = "test/path/one";
39 const path p2 = "/test/path/two";
40
41 const filesystem_error e1(str, ec);
42 VERIFY( contains(e1.what(), str) );
43 VERIFY( !contains(e1.what(), "[]") ); // no "empty path" in the string
44 VERIFY( e1.path1().empty() );
45 VERIFY( e1.path2().empty() );
46 VERIFY( e1.code() == ec );
47
48 const filesystem_error e2(str, p1, ec);
49 VERIFY( e2.path1() == p1 );
50 VERIFY( e2.path2().empty() );
51 VERIFY( contains(e2.what(), str) );
52 VERIFY( contains(e2.what(), p1.string()) );
53 VERIFY( e2.code() == ec );
54
55 const filesystem_error e3(str, path{}, ec);
56 VERIFY( e3.path1().empty() );
57 VERIFY( e3.path2().empty() );
58 VERIFY( contains(e3.what(), str) );
59 VERIFY( e3.code() == ec );
60
61 const filesystem_error e4(str, p1, p2, ec);
62 VERIFY( e4.path1() == p1 );
63 VERIFY( e4.path2() == p2 );
64 VERIFY( contains(e4.what(), str) );
65 VERIFY( contains(e4.what(), p1.string()) );
66 VERIFY( contains(e4.what(), p2.string()) );
67 VERIFY( !contains(e4.what(), "[]") );
68 VERIFY( e4.code() == ec );
69
70 const filesystem_error e5(str, p1, path{}, ec);
71 VERIFY( e5.path1() == p1 );
72 VERIFY( e5.path2().empty() );
73 VERIFY( contains(e5.what(), str) );
74 VERIFY( contains(e5.what(), p1.string()) );
75 VERIFY( e5.code() == ec );
76
77 const filesystem_error e6(str, path{}, p2, ec);
78 VERIFY( e6.path1().empty() );
79 VERIFY( e6.path2() == p2 );
80 VERIFY( contains(e6.what(), str) );
81 VERIFY( contains(e6.what(), "[]") );
82 VERIFY( contains(e6.what(), p2.string()) );
83 VERIFY( e6.code() == ec );
84}
85
86int
87main()
88{
89 test01();
90}