aboutsummaryrefslogtreecommitdiff
path: root/tests/get_path.c
blob: 5d2027aaa86339abfc1d05b834f6a36afb8ef85b (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
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include "fstree.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>

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

	assert(fstree_init(&fs, 512, 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);
	assert(str != NULL);
	assert(strcmp(str, "/") == 0);
	free(str);

	str = fstree_get_path(a);
	assert(str != NULL);
	assert(strcmp(str, "/foo") == 0);
	free(str);

	str = fstree_get_path(b);
	assert(str != NULL);
	assert(strcmp(str, "/foo/bar") == 0);
	free(str);

	str = fstree_get_path(c);
	assert(str != NULL);
	assert(strcmp(str, "/foo/bar/baz") == 0);
	free(str);

	str = fstree_get_path(d);
	assert(str != NULL);
	assert(strcmp(str, "/foo/bar/baz/dir") == 0);
	free(str);

	fstree_cleanup(&fs);
	return EXIT_SUCCESS;
}