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_directory_iterator(recursive_directory_iterator&&) noexcept;
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"
27namespace fs = std::filesystem;
28using namespace fs;
29
30static void test_constructor_signature()
31{
32 using D = recursive_directory_iterator;
33 static_assert(std::is_nothrow_move_constructible<D>::value, "");
34}
35
36static void test_move_end_iterator()
37{
38 const recursive_directory_iterator endIt;
39 recursive_directory_iterator endIt2{};
40
41 recursive_directory_iterator it(std::move(endIt2));
42 assert(it == endIt);
43 assert(endIt2 == endIt);
44}
45
46static void test_move_valid_iterator()
47{
48 static_test_env static_env;
49 const path testDir = static_env.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 assert(it != endIt);
60 while (it.depth() == 0) {
61 ++it;
62 assert(it != endIt);
63 }
64 it.disable_recursion_pending();
65 assert(it.options() == opts);
66 assert(it.depth() == 1);
67 assert(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 assert(it2 != endIt);
75 assert(*it2 == entry);
76 assert(it2.depth() == 1);
77 assert(it2.recursion_pending() == false);
78}
79
80int main(int, char**) {
81 test_constructor_signature();
82 test_move_end_iterator();
83 test_move_valid_iterator();
84
85 return 0;
86}
87

source code of libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move.pass.cpp