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 // <experimental/filesystem> 13 14 // class recursive_directory_iterator 15 16 // recursive_directory_iterator& operator=(recursive_directory_iterator const&); 17 18 #include <experimental/filesystem> 19 #include <type_traits> 20 #include <set> 21 #include <cassert> 22 23 #include "test_macros.h" 24 #include "rapid-cxx-test.hpp" 25 #include "filesystem_test_helper.hpp" 26 27 using namespace std::experimental::filesystem; 28 TEST_SUITE(recursive_directory_iterator_copy_assign_tests)29TEST_SUITE(recursive_directory_iterator_copy_assign_tests) 30 31 recursive_directory_iterator createInterestingIterator() 32 // Create an "interesting" iterator where all fields are 33 // in a non-default state. The returned 'it' is in a 34 // state such that: 35 // it.options() == directory_options::skip_permission_denied 36 // it.depth() == 1 37 // it.recursion_pending() == true 38 { 39 const path testDir = StaticEnv::Dir; 40 const recursive_directory_iterator endIt; 41 recursive_directory_iterator it(testDir, 42 directory_options::skip_permission_denied); 43 TEST_ASSERT(it != endIt); 44 while (it.depth() != 1) { 45 ++it; 46 TEST_ASSERT(it != endIt); 47 } 48 TEST_ASSERT(it.depth() == 1); 49 it.disable_recursion_pending(); 50 return it; 51 } 52 53 createDifferentInterestingIterator()54recursive_directory_iterator createDifferentInterestingIterator() 55 // Create an "interesting" iterator where all fields are 56 // in a non-default state. The returned 'it' is in a 57 // state such that: 58 // it.options() == directory_options::follow_directory_symlink 59 // it.depth() == 2 60 // it.recursion_pending() == false 61 { 62 const path testDir = StaticEnv::Dir; 63 const recursive_directory_iterator endIt; 64 recursive_directory_iterator it(testDir, 65 directory_options::follow_directory_symlink); 66 TEST_ASSERT(it != endIt); 67 while (it.depth() != 2) { 68 ++it; 69 TEST_ASSERT(it != endIt); 70 } 71 TEST_ASSERT(it.depth() == 2); 72 return it; 73 } 74 TEST_CASE(test_assignment_signature)75TEST_CASE(test_assignment_signature) { 76 using D = recursive_directory_iterator; 77 static_assert(std::is_copy_assignable<D>::value, ""); 78 } 79 TEST_CASE(test_copy_to_end_iterator)80TEST_CASE(test_copy_to_end_iterator) 81 { 82 const recursive_directory_iterator endIt; 83 84 const recursive_directory_iterator from = createInterestingIterator(); 85 const path entry = *from; 86 87 recursive_directory_iterator to; 88 to = from; 89 TEST_REQUIRE(to == from); 90 TEST_CHECK(*to == entry); 91 TEST_CHECK(to.options() == from.options()); 92 TEST_CHECK(to.depth() == from.depth()); 93 TEST_CHECK(to.recursion_pending() == from.recursion_pending()); 94 } 95 96 TEST_CASE(test_copy_from_end_iterator)97TEST_CASE(test_copy_from_end_iterator) 98 { 99 const recursive_directory_iterator from; 100 recursive_directory_iterator to = createInterestingIterator(); 101 102 to = from; 103 TEST_REQUIRE(to == from); 104 TEST_CHECK(to == recursive_directory_iterator{}); 105 } 106 TEST_CASE(test_copy_valid_iterator)107TEST_CASE(test_copy_valid_iterator) 108 { 109 const recursive_directory_iterator endIt; 110 111 const recursive_directory_iterator it = createInterestingIterator(); 112 const path entry = *it; 113 114 recursive_directory_iterator it2 = createDifferentInterestingIterator(); 115 TEST_REQUIRE(it2 != it); 116 TEST_CHECK(it2.options() != it.options()); 117 TEST_CHECK(it2.depth() != it.depth()); 118 TEST_CHECK(it2.recursion_pending() != it.recursion_pending()); 119 TEST_CHECK(*it2 != entry); 120 121 it2 = it; 122 TEST_REQUIRE(it2 == it); 123 TEST_CHECK(it2.options() == it.options()); 124 TEST_CHECK(it2.depth() == it.depth()); 125 TEST_CHECK(it2.recursion_pending() == it.recursion_pending()); 126 TEST_CHECK(*it2 == entry); 127 } 128 TEST_CASE(test_returns_reference_to_self)129TEST_CASE(test_returns_reference_to_self) 130 { 131 const recursive_directory_iterator it; 132 recursive_directory_iterator it2; 133 recursive_directory_iterator& ref = (it2 = it); 134 TEST_CHECK(&ref == &it2); 135 } 136 TEST_CASE(test_self_copy)137TEST_CASE(test_self_copy) 138 { 139 // Create two non-equal iterators that have exactly the same state. 140 recursive_directory_iterator it = createInterestingIterator(); 141 recursive_directory_iterator it2 = createInterestingIterator(); 142 TEST_CHECK(it != it2); 143 TEST_CHECK(it2.options() == it.options()); 144 TEST_CHECK(it2.depth() == it.depth()); 145 TEST_CHECK(it2.recursion_pending() == it.recursion_pending()); 146 TEST_CHECK(*it2 == *it); 147 148 // perform a self-copy and check that the state still matches the 149 // other unmodified iterator. 150 recursive_directory_iterator const& cit = it; 151 it = cit; 152 TEST_CHECK(it2.options() == it.options()); 153 TEST_CHECK(it2.depth() == it.depth()); 154 TEST_CHECK(it2.recursion_pending() == it.recursion_pending()); 155 TEST_CHECK(*it2 == *it); 156 } 157 158 TEST_SUITE_END() 159