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 // FILE_DEPENDENCIES: ../../Inputs/static_test_env
10 // UNSUPPORTED: c++98, c++03
11 
12 // <filesystem>
13 
14 // class recursive_directory_iterator
15 
16 // int depth() const
17 
18 #include "filesystem_include.h"
19 #include <type_traits>
20 #include <set>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "rapid-cxx-test.h"
25 #include "filesystem_test_helper.h"
26 
27 using namespace fs;
28 
29 TEST_SUITE(recursive_directory_iterator_depth_tests)
30 
31 TEST_CASE(test_depth)
32 {
33     const path testDir = StaticEnv::Dir;
34     const path DirDepth1 = StaticEnv::Dir2;
35     const path DirDepth2 = StaticEnv::Dir3;
36     const recursive_directory_iterator endIt{};
37 
38     std::error_code ec;
39     recursive_directory_iterator it(testDir, ec);
40     TEST_REQUIRE(!ec);
41     TEST_CHECK(it.depth() == 0);
42 
43     bool seen_d1, seen_d2;
44     seen_d1 = seen_d2 = false;
45 
46     while (it != endIt) {
47         const path entry = *it;
48         const path parent = entry.parent_path();
49         if (parent == testDir) {
50             TEST_CHECK(it.depth() == 0);
51         } else if (parent == DirDepth1) {
52             TEST_CHECK(it.depth() == 1);
53             seen_d1 = true;
54         } else if (parent == DirDepth2) {
55             TEST_CHECK(it.depth() == 2);
56             seen_d2 = true;
57         } else {
58             TEST_CHECK(!"Unexpected depth while iterating over static env");
59         }
60         ++it;
61     }
62     TEST_REQUIRE(seen_d1 && seen_d2);
63     TEST_CHECK(it == endIt);
64 }
65 
66 TEST_SUITE_END()
67