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