aboutsummaryrefslogtreecommitdiff
path: root/tests/get_path.c
blob: 8ca0ce07a36306e7d965eef1a0b5753647d3709f (plain)
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
48
49
50
51
52
53
54
55
56
57
58
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * get_path.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"

#include "fstree.h"
#include "test.h"

int main(void)
{
	tree_node_t *a, *b, *c, *d;
	struct stat sb;
	fstree_t fs;
	char *str;

	TEST_ASSERT(fstree_init(&fs, NULL) == 0);

	memset(&sb, 0, sizeof(sb));
	sb.st_mode = S_IFDIR | 0750;
	sb.st_uid = 1000;
	sb.st_gid = 100;

	a = fstree_add_generic(&fs, "foo", &sb, NULL);
	b = fstree_add_generic(&fs, "foo/bar", &sb, NULL);
	c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL);
	d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL);

	str = fstree_get_path(fs.root);
	TEST_NOT_NULL(str);
	TEST_STR_EQUAL(str, "/");
	free(str);

	str = fstree_get_path(a);
	TEST_NOT_NULL(str);
	TEST_STR_EQUAL(str, "/foo");
	free(str);

	str = fstree_get_path(b);
	TEST_NOT_NULL(str);
	TEST_STR_EQUAL(str, "/foo/bar");
	free(str);

	str = fstree_get_path(c);
	TEST_NOT_NULL(str);
	TEST_STR_EQUAL(str, "/foo/bar/baz");
	free(str);

	str = fstree_get_path(d);
	TEST_NOT_NULL(str);
	TEST_STR_EQUAL(str, "/foo/bar/baz/dir");
	free(str);

	fstree_cleanup(&fs);
	return EXIT_SUCCESS;
}