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 // UNSUPPORTED: c++03
10 
11 // <filesystem>
12 
13 // class directory_iterator
14 
15 // directory_iterator& operator=(directory_iterator const&);
16 
17 #include "filesystem_include.h"
18 #include <type_traits>
19 #include <set>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "rapid-cxx-test.h"
24 #include "filesystem_test_helper.h"
25 
26 using namespace fs;
27 
28 TEST_SUITE(directory_iterator_copy_assign_tests)
29 
TEST_CASE(test_assignment_signature)30 TEST_CASE(test_assignment_signature)
31 {
32     using D = directory_iterator;
33     static_assert(std::is_copy_assignable<D>::value, "");
34 }
35 
TEST_CASE(test_copy_to_end_iterator)36 TEST_CASE(test_copy_to_end_iterator)
37 {
38     static_test_env static_env;
39     const path testDir = static_env.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 
TEST_CASE(test_copy_from_end_iterator)53 TEST_CASE(test_copy_from_end_iterator)
54 {
55     static_test_env static_env;
56     const path testDir = static_env.Dir;
57 
58     const directory_iterator from{};
59 
60     directory_iterator to(testDir);
61     TEST_REQUIRE(to != directory_iterator{});
62 
63     to = from;
64     TEST_REQUIRE(to == from);
65     TEST_CHECK(to == directory_iterator{});
66 }
67 
TEST_CASE(test_copy_valid_iterator)68 TEST_CASE(test_copy_valid_iterator)
69 {
70     static_test_env static_env;
71     const path testDir = static_env.Dir;
72     const directory_iterator endIt{};
73 
74     directory_iterator it_obj(testDir);
75     const directory_iterator& it = it_obj;
76     TEST_REQUIRE(it != endIt);
77     ++it_obj;
78     TEST_REQUIRE(it != endIt);
79     const path entry = *it;
80 
81     directory_iterator it2(testDir);
82     TEST_REQUIRE(it2 != it);
83     const path entry2 = *it2;
84     TEST_CHECK(entry2 != entry);
85 
86     it2 = it;
87     TEST_REQUIRE(it2 == it);
88     TEST_CHECK(*it2 == entry);
89 }
90 
TEST_CASE(test_returns_reference_to_self)91 TEST_CASE(test_returns_reference_to_self)
92 {
93     const directory_iterator it;
94     directory_iterator it2;
95     directory_iterator& ref = (it2 = it);
96     TEST_CHECK(&ref == &it2);
97 }
98 
99 
100 TEST_SUITE_END()
101