Debian Codegraph @

libstdc++-v3/testsuite/27_io/filesystem/operations/hard_link_count.cc

raw
1 // { dg-do run { target c++17 } }
2 // { dg-require-filesystem-ts "" }
3
4 #include <filesystem>
5 #include <testsuite_hooks.h>
6 #include <testsuite_fs.h>
7
8 namespace fs = std::filesystem;
9
10 void test01()
11 {
12 // PR libstdc++/113663
13
14 fs::path p1 = __gnu_test::nonexistent_path();
15 VERIFY( !fs::exists(p1) );
16
17 __gnu_test::scoped_file f1(p1);
18 VERIFY( fs::exists(p1) );
19
20 VERIFY( fs::hard_link_count(p1) == 1 );
21
22 fs::path p2 = __gnu_test::nonexistent_path();
23 VERIFY( !fs::exists(p2) );
24
25 fs::create_hard_link(p1, p2);
26 __gnu_test::scoped_file f2(p2, __gnu_test::scoped_file::adopt_file);
27 VERIFY( fs::exists(p2) );
28
29 VERIFY( fs::hard_link_count(p1) == 2 );
30 VERIFY( fs::hard_link_count(p2) == 2 );
31 }
32
33 void
34 test02()
35 {
36 std::error_code ec;
37 fs::path p1 = __gnu_test::nonexistent_path();
38 VERIFY( fs::hard_link_count(p1, ec) == -1 );
39 VERIFY( ec == std::errc::no_such_file_or_directory );
40
41 #if __cpp_exceptions
42 try {
43 fs::hard_link_count(p1); // { dg-warning "ignoring return value" }
44 VERIFY( false );
45 } catch (const fs::filesystem_error& e) {
46 VERIFY( e.path1() == p1 );
47 VERIFY( e.path2().empty() );
48 }
49 #endif
50
51 __gnu_test::scoped_file f1(p1);
52 fs::hard_link_count(f1.path, ec); // { dg-warning "ignoring return value" }
53 VERIFY( !ec ); // Should be cleared on success.
54 }
55
56 int
57 main()
58 {
59 test01();
60 test02();
61 }