| 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 |
// int depth() const |
| 18 |
|
| 19 |
#include <filesystem> |
| 20 |
#include <type_traits> |
| 21 |
#include <set> |
| 22 |
#include <cassert> |
| 23 |
|
| 24 |
#include "assert_macros.h" |
| 25 |
#include "test_macros.h" |
| 26 |
#include "filesystem_test_helper.h" |
| 27 |
namespace fs = std::filesystem; |
| 28 |
using namespace fs; |
| 29 |
|
| 30 |
static void test_depth() |
| 31 |
{ |
| 32 |
static_test_env static_env; |
| 33 |
const path testDir = static_env.Dir; |
| 34 |
const path DirDepth1 = static_env.Dir2; |
| 35 |
const path DirDepth2 = static_env.Dir3; |
| 36 |
const recursive_directory_iterator endIt{}; |
| 37 |
|
| 38 |
std::error_code ec; |
| 39 |
recursive_directory_iterator it(testDir, ec); |
| 40 |
assert(!ec); |
| 41 |
assert(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 |
assert(it.depth() == 0); |
| 51 |
} else if (parent == DirDepth1) { |
| 52 |
assert(it.depth() == 1); |
| 53 |
seen_d1 = true; |
| 54 |
} else if (parent == DirDepth2) { |
| 55 |
assert(it.depth() == 2); |
| 56 |
seen_d2 = true; |
| 57 |
} else { |
| 58 |
assert(!"Unexpected depth while iterating over static env"); |
| 59 |
} |
| 60 |
++it; |
| 61 |
} |
| 62 |
assert(seen_d1 && seen_d2); |
| 63 |
assert(it == endIt); |
| 64 |
} |
| 65 |
|
| 66 |
int main(int, char**) { |
| 67 |
test_depth(); |
| 68 |
|
| 69 |
return 0; |
| 70 |
} |