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