copy.pass.cpp (1865B)
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(const directory_entry&) = default; 17 18 #include "filesystem_include.hpp" 19 #include <type_traits> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "rapid-cxx-test.hpp" 24 #include "filesystem_test_helper.hpp" 25 #include "test_convertible.hpp" 26 27 TEST_SUITE(directory_entry_path_ctor_suite) 28 29 TEST_CASE(copy_ctor) { 30 using namespace fs; 31 // Copy 32 { 33 static_assert(std::is_copy_constructible<directory_entry>::value, 34 "directory_entry must be copy constructible"); 35 static_assert(!std::is_nothrow_copy_constructible<directory_entry>::value, 36 "directory_entry's copy constructor cannot be noexcept"); 37 const path p("foo/bar/baz"); 38 const directory_entry e(p); 39 assert(e.path() == p); 40 directory_entry e2(e); 41 assert(e.path() == p); 42 assert(e2.path() == p); 43 } 44 } 45 46 TEST_CASE(copy_ctor_copies_cache) { 47 using namespace fs; 48 scoped_test_env env; 49 const path dir = env.create_dir("dir"); 50 const path file = env.create_file("dir/file", 42); 51 const path sym = env.create_symlink("dir/file", "sym"); 52 53 { 54 directory_entry ent(sym); 55 56 fs::remove(sym); 57 58 directory_entry ent_cp(ent); 59 TEST_CHECK(ent_cp.path() == sym); 60 TEST_CHECK(ent_cp.is_symlink()); 61 } 62 63 { 64 directory_entry ent(file); 65 66 fs::remove(file); 67 68 directory_entry ent_cp(ent); 69 TEST_CHECK(ent_cp.path() == file); 70 TEST_CHECK(ent_cp.is_regular_file()); 71 } 72 } 73 74 TEST_SUITE_END()