]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/operations/relative.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / operations / relative.cc
1 // Copyright (C) 2017-2020 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 // { dg-require-filesystem-ts "" }
21
22 #include <filesystem>
23 #include <testsuite_fs.h>
24 #include <testsuite_hooks.h>
25
26 void
27 test01()
28 {
29 auto p = __gnu_test::nonexistent_path();
30 auto q = __gnu_test::nonexistent_path();
31
32 auto r = relative(p, q);
33 VERIFY( r == ".."/p );
34
35 r = relative(p, p/q);
36 VERIFY( r == ".." );
37
38 r = relative(p/q, p);
39 VERIFY( r == q );
40
41 const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
42 std::error_code ec;
43
44 ec = bad_ec;
45 r = relative(p, q, ec);
46 VERIFY( !ec );
47 VERIFY( r == ".."/p );
48
49 ec = bad_ec;
50 r = relative(p, p/q, ec);
51 VERIFY( !ec );
52 VERIFY( r == ".." );
53
54 ec = bad_ec;
55 r = relative(p/q, p, ec);
56 VERIFY( !ec );
57 VERIFY( r == q );
58 }
59
60 int
61 main()
62 {
63 test01();
64 }