Git fork
1#include "unit-test.h"
2#include "dir.h"
3
4#define TEST_WITHIN_DEPTH(path, depth, max_depth, expect) do { \
5 int actual = within_depth(path, strlen(path), \
6 depth, max_depth); \
7 if (actual != expect) \
8 cl_failf("path '%s' with depth '%d' and max-depth '%d': expected %d, got %d", \
9 path, depth, max_depth, expect, actual); \
10 } while (0)
11
12void test_dir__within_depth(void)
13{
14 /* depth = 0; max_depth = 0 */
15 TEST_WITHIN_DEPTH("", 0, 0, 1);
16 TEST_WITHIN_DEPTH("file", 0, 0, 1);
17 TEST_WITHIN_DEPTH("a", 0, 0, 1);
18 TEST_WITHIN_DEPTH("a/file", 0, 0, 0);
19 TEST_WITHIN_DEPTH("a/b", 0, 0, 0);
20 TEST_WITHIN_DEPTH("a/b/file", 0, 0, 0);
21
22 /* depth = 0; max_depth = 1 */
23 TEST_WITHIN_DEPTH("", 0, 1, 1);
24 TEST_WITHIN_DEPTH("file", 0, 1, 1);
25 TEST_WITHIN_DEPTH("a", 0, 1, 1);
26 TEST_WITHIN_DEPTH("a/file", 0, 1, 1);
27 TEST_WITHIN_DEPTH("a/b", 0, 1, 1);
28 TEST_WITHIN_DEPTH("a/b/file", 0, 1, 0);
29
30 /* depth = 1; max_depth = 1 */
31 TEST_WITHIN_DEPTH("", 1, 1, 1);
32 TEST_WITHIN_DEPTH("file", 1, 1, 1);
33 TEST_WITHIN_DEPTH("a", 1, 1, 1);
34 TEST_WITHIN_DEPTH("a/file", 1, 1, 0);
35 TEST_WITHIN_DEPTH("a/b", 1, 1, 0);
36 TEST_WITHIN_DEPTH("a/b/file", 1, 1, 0);
37
38 /* depth = 1; max_depth = 0 */
39 TEST_WITHIN_DEPTH("", 1, 0, 0);
40 TEST_WITHIN_DEPTH("file", 1, 0, 0);
41 TEST_WITHIN_DEPTH("a", 1, 0, 0);
42 TEST_WITHIN_DEPTH("a/file", 1, 0, 0);
43 TEST_WITHIN_DEPTH("a/b", 1, 0, 0);
44 TEST_WITHIN_DEPTH("a/b/file", 1, 0, 0);
45
46
47}