1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 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_include.hpp" 22 #include <type_traits> 23 #include <cassert> 24 25 #include "test_macros.h" 26 #include "rapid-cxx-test.hpp" 27 #include "filesystem_test_helper.hpp" 28 29 TEST_SUITE(directory_entry_ctor_suite) 30 31 TEST_CASE(test_copy_assign_operator) { 32 using namespace fs; 33 // Copy 34 { 35 static_assert(std::is_copy_assignable<directory_entry>::value, 36 "directory_entry must be copy assignable"); 37 static_assert(!std::is_nothrow_copy_assignable<directory_entry>::value, 38 "directory_entry's copy assignment cannot be noexcept"); 39 const path p("foo/bar/baz"); 40 const path p2("abc"); 41 const directory_entry e(p); 42 directory_entry e2; 43 assert(e.path() == p && e2.path() == path()); 44 e2 = e; 45 assert(e.path() == p && e2.path() == p); 46 directory_entry e3(p2); 47 e2 = e3; 48 assert(e2.path() == p2 && e3.path() == p2); 49 } 50 } 51 52 TEST_CASE(copy_assign_copies_cache) { 53 using namespace fs; 54 scoped_test_env env; 55 const path dir = env.create_dir("dir"); 56 const path file = env.create_file("dir/file", 42); 57 const path sym = env.create_symlink("dir/file", "sym"); 58 59 { 60 directory_entry ent(sym); 61 62 fs::remove(sym); 63 64 directory_entry ent_cp; 65 ent_cp = ent; 66 TEST_CHECK(ent_cp.path() == sym); 67 TEST_CHECK(ent_cp.is_symlink()); 68 } 69 70 { 71 directory_entry ent(file); 72 73 fs::remove(file); 74 75 directory_entry ent_cp; 76 ent_cp = ent; 77 TEST_CHECK(ent_cp.path() == file); 78 TEST_CHECK(ent_cp.is_regular_file()); 79 } 80 } 81 82 TEST_SUITE_END() 83