Debian Codegraph @

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

raw
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
13 // <filesystem>
14
15 // class recursive_directory_iterator
16
17 // recursive_directory_iterator(recursive_directory_iterator&&) noexcept;
18
19 #include <filesystem>
20 #include <type_traits>
21 #include <set>
22 #include <cassert>
23
24 #include "test_macros.h"
25 #include "filesystem_test_helper.h"
26 namespace fs = std::filesystem;
27 using namespace fs;
28
29 static void test_constructor_signature()
30 {
31 using D = recursive_directory_iterator;
32 static_assert(std::is_nothrow_move_constructible<D>::value, "");
33 }
34
35 static void test_move_end_iterator()
36 {
37 const recursive_directory_iterator endIt;
38 recursive_directory_iterator endIt2{};
39
40 recursive_directory_iterator it(std::move(endIt2));
41 assert(it == endIt);
42 assert(endIt2 == endIt);
43 }
44
45 static void test_move_valid_iterator()
46 {
47 static_test_env static_env;
48 const path testDir = static_env.Dir;
49 const recursive_directory_iterator endIt{};
50
51 // build 'it' up with "interesting" non-default state so we can test
52 // that it gets copied. We want to get 'it' into a state such that:
53 // it.options() != directory_options::none
54 // it.depth() != 0
55 // it.recursion_pending() != true
56 const directory_options opts = directory_options::skip_permission_denied;
57 recursive_directory_iterator it(testDir, opts);
58 assert(it != endIt);
59 while (it.depth() == 0) {
60 ++it;
61 assert(it != endIt);
62 }
63 it.disable_recursion_pending();
64 assert(it.options() == opts);
65 assert(it.depth() == 1);
66 assert(it.recursion_pending() == false);
67 const path entry = *it;
68
69 // OPERATION UNDER TEST //
70 const recursive_directory_iterator it2(std::move(it));
71 // ------------------- //
72
73 assert(it2 != endIt);
74 assert(*it2 == entry);
75 assert(it2.depth() == 1);
76 assert(it2.recursion_pending() == false);
77 }
78
79 int main(int, char**) {
80 test_constructor_signature();
81 test_move_end_iterator();
82 test_move_valid_iterator();
83
84 return 0;
85 }