| 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 |
// UNSUPPORTED: no-filesystem |
| 12 |
|
| 13 |
// <filesystem> |
| 14 |
|
| 15 |
// class recursive_directory_iterator |
| 16 |
|
| 17 |
// recursive_recursive_directory_iterator(recursive_recursive_directory_iterator const&); |
| 18 |
|
| 19 |
#include <filesystem> |
| 20 |
#include <type_traits> |
| 21 |
#include <set> |
| 22 |
#include <cassert> |
| 23 |
|
| 24 |
#include "test_macros.h" |
| 25 |
#include "filesystem_test_helper.h" |
| 26 |
namespace fs = std::filesystem; |
| 27 |
using namespace fs; |
| 28 |
|
| 29 |
static void test_constructor_signature() |
| 30 |
{ |
| 31 |
using D = recursive_directory_iterator; |
| 32 |
static_assert(std::is_copy_constructible<D>::value, ""); |
| 33 |
//static_assert(!std::is_nothrow_copy_constructible<D>::value, ""); |
| 34 |
} |
| 35 |
|
| 36 |
static void test_copy_end_iterator() |
| 37 |
{ |
| 38 |
const recursive_directory_iterator endIt; |
| 39 |
recursive_directory_iterator it(endIt); |
| 40 |
assert(it == endIt); |
| 41 |
} |
| 42 |
|
| 43 |
static void test_copy_valid_iterator() |
| 44 |
{ |
| 45 |
static_test_env static_env; |
| 46 |
const path testDir = static_env.Dir; |
| 47 |
const recursive_directory_iterator endIt{}; |
| 48 |
|
| 49 |
// build 'it' up with "interesting" non-default state so we can test |
| 50 |
// that it gets copied. We want to get 'it' into a state such that: |
| 51 |
// it.options() != directory_options::none |
| 52 |
// it.depth() != 0 |
| 53 |
// it.recursion_pending() != true |
| 54 |
const directory_options opts = directory_options::skip_permission_denied; |
| 55 |
recursive_directory_iterator it(testDir, opts); |
| 56 |
assert(it != endIt); |
| 57 |
while (it.depth() == 0) { |
| 58 |
++it; |
| 59 |
assert(it != endIt); |
| 60 |
} |
| 61 |
it.disable_recursion_pending(); |
| 62 |
assert(it.options() == opts); |
| 63 |
assert(it.depth() == 1); |
| 64 |
assert(it.recursion_pending() == false); |
| 65 |
const path entry = *it; |
| 66 |
|
| 67 |
// OPERATION UNDER TEST // |
| 68 |
const recursive_directory_iterator it2(it); |
| 69 |
// ------------------- // |
| 70 |
|
| 71 |
assert(it2 == it); |
| 72 |
assert(*it2 == entry); |
| 73 |
assert(it2.depth() == 1); |
| 74 |
assert(it2.recursion_pending() == false); |
| 75 |
assert(it != endIt); |
| 76 |
} |
| 77 |
|
| 78 |
int main(int, char**) { |
| 79 |
test_constructor_signature(); |
| 80 |
test_copy_end_iterator(); |
| 81 |
test_copy_valid_iterator(); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |