Debian Codegraph @

libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/depth.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 // UNSUPPORTED: availability-filesystem-missing
13
14 // <filesystem>
15
16 // class recursive_directory_iterator
17
18 // int depth() const
19
20 #include <filesystem>
21 #include <type_traits>
22 #include <set>
23 #include <cassert>
24
25 #include "assert_macros.h"
26 #include "test_macros.h"
27 #include "filesystem_test_helper.h"
28 namespace fs = std::filesystem;
29 using namespace fs;
30
31 static void test_depth()
32 {
33 static_test_env static_env;
34 const path testDir = static_env.Dir;
35 const path DirDepth1 = static_env.Dir2;
36 const path DirDepth2 = static_env.Dir3;
37 const recursive_directory_iterator endIt{};
38
39 std::error_code ec;
40 recursive_directory_iterator it(testDir, ec);
41 assert(!ec);
42 assert(it.depth() == 0);
43
44 bool seen_d1, seen_d2;
45 seen_d1 = seen_d2 = false;
46
47 while (it != endIt) {
48 const path entry = *it;
49 const path parent = entry.parent_path();
50 if (parent == testDir) {
51 assert(it.depth() == 0);
52 } else if (parent == DirDepth1) {
53 assert(it.depth() == 1);
54 seen_d1 = true;
55 } else if (parent == DirDepth2) {
56 assert(it.depth() == 2);
57 seen_d2 = true;
58 } else {
59 assert(!"Unexpected depth while iterating over static env");
60 }
61 ++it;
62 }
63 assert(seen_d1 && seen_d2);
64 assert(it == endIt);
65 }
66
67 int main(int, char**) {
68 test_depth();
69
70 return 0;
71 }