1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // REQUIRES: can-create-symlinks |
10 | // UNSUPPORTED: c++03, c++11, c++14 |
11 | |
12 | // <filesystem> |
13 | |
14 | // class directory_entry |
15 | |
16 | // directory_entry& operator=(directory_entry const&) = default; |
17 | // directory_entry& operator=(directory_entry&&) noexcept = default; |
18 | // void assign(path const&); |
19 | // void replace_filename(path const&); |
20 | |
21 | #include <filesystem> |
22 | #include <type_traits> |
23 | #include <cassert> |
24 | |
25 | #include "test_macros.h" |
26 | #include "filesystem_test_helper.h" |
27 | namespace fs = std::filesystem; |
28 | |
29 | static void test_copy_assign_operator() { |
30 | using namespace fs; |
31 | // Copy |
32 | { |
33 | static_assert(std::is_copy_assignable<directory_entry>::value, |
34 | "directory_entry must be copy assignable"); |
35 | static_assert(!std::is_nothrow_copy_assignable<directory_entry>::value, |
36 | "directory_entry's copy assignment cannot be noexcept"); |
37 | const path p("foo/bar/baz"); |
38 | const path p2("abc"); |
39 | const directory_entry e(p); |
40 | directory_entry e2; |
41 | assert(e.path() == p && e2.path() == path()); |
42 | e2 = e; |
43 | assert(e.path() == p && e2.path() == p); |
44 | directory_entry e3(p2); |
45 | e2 = e3; |
46 | assert(e2.path() == p2 && e3.path() == p2); |
47 | } |
48 | } |
49 | |
50 | static void copy_assign_copies_cache() { |
51 | using namespace fs; |
52 | scoped_test_env env; |
53 | const path dir = env.create_dir("dir"); |
54 | const path file = env.create_file("dir/file", 42); |
55 | const path sym = env.create_symlink("dir/file", "sym"); |
56 | |
57 | { |
58 | directory_entry ent(sym); |
59 | |
60 | fs::remove(p: sym); |
61 | |
62 | directory_entry ent_cp; |
63 | ent_cp = ent; |
64 | assert(ent_cp.path() == sym); |
65 | assert(ent_cp.is_symlink()); |
66 | } |
67 | |
68 | { |
69 | directory_entry ent(file); |
70 | |
71 | fs::remove(p: file); |
72 | |
73 | directory_entry ent_cp; |
74 | ent_cp = ent; |
75 | assert(ent_cp.path() == file); |
76 | assert(ent_cp.is_regular_file()); |
77 | } |
78 | } |
79 | |
80 | int main(int, char**) { |
81 | test_copy_assign_operator(); |
82 | copy_assign_copies_cache(); |
83 | |
84 | return 0; |
85 | } |
86 |