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(recursive_directory_iterator&&) noexcept;
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
27using namespace std::experimental::filesystem;
28
29TEST_SUITE(recursive_directory_iterator_move_construct_tests)
30
31TEST_CASE(test_constructor_signature)
32{
33    using D = recursive_directory_iterator;
34    static_assert(std::is_nothrow_move_constructible<D>::value, "");
35}
36
37TEST_CASE(test_move_end_iterator)
38{
39    const recursive_directory_iterator endIt;
40    recursive_directory_iterator endIt2{};
41
42    recursive_directory_iterator it(std::move(endIt2));
43    TEST_CHECK(it == endIt);
44    TEST_CHECK(endIt2 == endIt);
45}
46
47TEST_CASE(test_move_valid_iterator)
48{
49    const path testDir = StaticEnv::Dir;
50    const recursive_directory_iterator endIt{};
51
52    // build 'it' up with "interesting" non-default state so we can test
53    // that it gets copied. We want to get 'it' into a state such that:
54    //  it.options() != directory_options::none
55    //  it.depth() != 0
56    //  it.recursion_pending() != true
57    const directory_options opts = directory_options::skip_permission_denied;
58    recursive_directory_iterator it(testDir, opts);
59    TEST_REQUIRE(it != endIt);
60    while (it.depth() == 0) {
61        ++it;
62        TEST_REQUIRE(it != endIt);
63    }
64    it.disable_recursion_pending();
65    TEST_CHECK(it.options() == opts);
66    TEST_CHECK(it.depth() == 1);
67    TEST_CHECK(it.recursion_pending() == false);
68    const path entry = *it;
69
70    // OPERATION UNDER TEST //
71    const recursive_directory_iterator it2(std::move(it));
72    // ------------------- //
73
74    TEST_REQUIRE(it2 != endIt);
75    TEST_CHECK(*it2 == entry);
76    TEST_CHECK(it2.depth() == 1);
77    TEST_CHECK(it2.recursion_pending() == false);
78}
79
80TEST_SUITE_END()
81