]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / operations / absolute.cc
CommitLineData
641cb5a6
JW
1// { dg-do run { target c++17 } }
2// { dg-require-filesystem-ts "" }
3
a945c346 4// Copyright (C) 2014-2024 Free Software Foundation, Inc.
641cb5a6
JW
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
21// C++17 30.10.14.1 Absolute [fs.op.absolute]
22
23#include <filesystem>
24#include <testsuite_fs.h>
25#include <testsuite_hooks.h>
26
27using std::filesystem::path;
28
29void
30test01()
31{
4a7c7999 32 for (const path p : __gnu_test::test_paths)
8a49324e
JW
33 {
34 std::error_code ec;
35 path abs = absolute(p, ec);
36 VERIFY( ec || abs.is_absolute() );
37 }
641cb5a6
JW
38}
39
40void
41test02()
42{
9534a5e6
JW
43 std::error_code ec = make_error_code(std::errc::invalid_argument);
44 path root = __gnu_test::root_path();
45 VERIFY( absolute(root) == root );
46 VERIFY( absolute(root, ec) == root && !ec );
47 VERIFY( absolute(path{}, ec).empty() && ec );
48
49#if defined(__MINGW32__) || defined(__MINGW64__)
50 path p1("/");
51 VERIFY( absolute(p1) != p1 );
52 path p2("/foo");
53 VERIFY( absolute(p2) != p2 );
54 path p3("foo");
55 VERIFY( absolute(p3) != p3 );
56 path p4("C:\\");
57 VERIFY( absolute(p4) == p4 );
58#else
641cb5a6
JW
59 path p1("/");
60 VERIFY( absolute(p1) == p1 );
61 path p2("/foo");
62 VERIFY( absolute(p2) == p2 );
63 path p3("foo");
64 VERIFY( absolute(p3) != p3 );
65 VERIFY( absolute(p3) == (std::filesystem::current_path()/p3) );
9534a5e6 66#endif
641cb5a6
JW
67}
68
854a5c77
JW
69void
70test03()
71{
72 // PR libstdc++/90299
73 const path p = __gnu_test::nonexistent_path();
74 std::error_code ec;
75 const path pabs = absolute(p, ec);
76 VERIFY( !ec );
77 VERIFY( pabs.is_absolute() );
78
79 const path pabs2 = absolute(p);
80 VERIFY( pabs2 == pabs );
81
82 const path eabs = absolute(path{}, ec);
83 VERIFY( ec == std::errc::invalid_argument );
84 VERIFY( eabs.empty() );
85
86 try {
f7a14830 87 (void) absolute(path{});
854a5c77
JW
88 VERIFY( false );
89 } catch (const std::filesystem::filesystem_error& e) {
90 VERIFY( e.code() == std::errc::invalid_argument );
91 VERIFY( e.path1().empty() );
92 VERIFY( e.path2().empty() );
93 }
94}
95
641cb5a6
JW
96int
97main()
98{
99 test01();
100 test02();
854a5c77 101 test03();
641cb5a6 102}