File: u-dir.c

package info (click to toggle)
git 1%3A2.51.0%2Bnext.20250825-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,548 kB
  • sloc: ansic: 305,207; sh: 260,479; perl: 25,943; tcl: 21,754; makefile: 4,176; python: 3,442; javascript: 772; csh: 45
file content (47 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "unit-test.h"
#include "dir.h"

#define TEST_WITHIN_DEPTH(path, depth, max_depth, expect) do { \
		int actual = within_depth(path, strlen(path), \
					  depth, max_depth); \
		if (actual != expect) \
			cl_failf("path '%s' with depth '%d' and max-depth '%d': expected %d, got %d", \
				 path, depth, max_depth, expect, actual); \
	} while (0)

void test_dir__within_depth(void)
{
	/* depth = 0; max_depth = 0 */
	TEST_WITHIN_DEPTH("",         0, 0, 1);
	TEST_WITHIN_DEPTH("file",     0, 0, 1);
	TEST_WITHIN_DEPTH("a",        0, 0, 1);
	TEST_WITHIN_DEPTH("a/file",   0, 0, 0);
	TEST_WITHIN_DEPTH("a/b",      0, 0, 0);
	TEST_WITHIN_DEPTH("a/b/file", 0, 0, 0);

	/* depth = 0; max_depth = 1 */
	TEST_WITHIN_DEPTH("",         0, 1, 1);
	TEST_WITHIN_DEPTH("file",     0, 1, 1);
	TEST_WITHIN_DEPTH("a",        0, 1, 1);
	TEST_WITHIN_DEPTH("a/file",   0, 1, 1);
	TEST_WITHIN_DEPTH("a/b",      0, 1, 1);
	TEST_WITHIN_DEPTH("a/b/file", 0, 1, 0);

	/* depth = 1; max_depth = 1 */
	TEST_WITHIN_DEPTH("",         1, 1, 1);
	TEST_WITHIN_DEPTH("file",     1, 1, 1);
	TEST_WITHIN_DEPTH("a",        1, 1, 1);
	TEST_WITHIN_DEPTH("a/file",   1, 1, 0);
	TEST_WITHIN_DEPTH("a/b",      1, 1, 0);
	TEST_WITHIN_DEPTH("a/b/file", 1, 1, 0);

	/* depth = 1; max_depth = 0 */
	TEST_WITHIN_DEPTH("",         1, 0, 0);
	TEST_WITHIN_DEPTH("file",     1, 0, 0);
	TEST_WITHIN_DEPTH("a",        1, 0, 0);
	TEST_WITHIN_DEPTH("a/file",   1, 0, 0);
	TEST_WITHIN_DEPTH("a/b",      1, 0, 0);
	TEST_WITHIN_DEPTH("a/b/file", 1, 0, 0);


}