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 directory_iterator 15 16 // directory_iterator& operator=(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 29 TEST_SUITE(directory_iterator_copy_assign_tests) 30 31 TEST_CASE(test_assignment_signature) 32 { 33 using D = directory_iterator; 34 static_assert(std::is_copy_assignable<D>::value, ""); 35 } 36 37 TEST_CASE(test_copy_to_end_iterator) 38 { 39 const path testDir = StaticEnv::Dir; 40 41 const directory_iterator from(testDir); 42 TEST_REQUIRE(from != directory_iterator{}); 43 const path entry = *from; 44 45 directory_iterator to{}; 46 to = from; 47 TEST_REQUIRE(to == from); 48 TEST_CHECK(*to == entry); 49 TEST_CHECK(*from == entry); 50 } 51 52 53 TEST_CASE(test_copy_from_end_iterator) 54 { 55 const path testDir = StaticEnv::Dir; 56 57 const directory_iterator from{}; 58 59 directory_iterator to(testDir); 60 TEST_REQUIRE(to != directory_iterator{}); 61 62 to = from; 63 TEST_REQUIRE(to == from); 64 TEST_CHECK(to == directory_iterator{}); 65 } 66 67 TEST_CASE(test_copy_valid_iterator) 68 { 69 const path testDir = StaticEnv::Dir; 70 const directory_iterator endIt{}; 71 72 directory_iterator it_obj(testDir); 73 const directory_iterator& it = it_obj; 74 TEST_REQUIRE(it != endIt); 75 ++it_obj; 76 TEST_REQUIRE(it != endIt); 77 const path entry = *it; 78 79 directory_iterator it2(testDir); 80 TEST_REQUIRE(it2 != it); 81 const path entry2 = *it2; 82 TEST_CHECK(entry2 != entry); 83 84 it2 = it; 85 TEST_REQUIRE(it2 == it); 86 TEST_CHECK(*it2 == entry); 87 } 88 89 TEST_CASE(test_returns_reference_to_self) 90 { 91 const directory_iterator it; 92 directory_iterator it2; 93 directory_iterator& ref = (it2 = it); 94 TEST_CHECK(&ref == &it2); 95 } 96 97 98 TEST_SUITE_END() 99