aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs/test/fstree_from_file2.c
blob: ab372c9d228a9e686e7c6a58d843a52fa34dd2d7 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * fstree_from_file2.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"

#include "util/test.h"
#include "io/mem.h"
#include "mkfs.h"

const char *listing =
"dir /test 0755 0 0\n"
"file /test/file1 0644 0 0\n"
"file /test/file2 0644 0 0 completely/different/path\n"
"file /test/file3 0644 0 0 /absolute/path\n"
"file /test/file4 0644 0 0 \"/ \x21 \"\n";

int main(int argc, char **argv)
{
	fstree_defaults_t fsd;
	sqfs_istream_t *file;
	tree_node_t *n;
	fstree_t fs;
	(void)argc; (void)argv;

	file = istream_memory_create("memfile", 7, listing, strlen(listing));
	TEST_NOT_NULL(file);

	TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
	TEST_ASSERT(fstree_init(&fs, &fsd) == 0);
	TEST_ASSERT(fstree_from_file_stream(&fs, file, NULL) == 0);
	sqfs_drop(file);

	fstree_post_process(&fs);
	TEST_EQUAL_UI(fs.root->link_count, 3);
	TEST_EQUAL_UI(fs.root->mode, S_IFDIR | 0755);
	TEST_EQUAL_UI(fs.root->uid, 0);
	TEST_EQUAL_UI(fs.root->gid, 0);

	n = fs.root->data.children;
	TEST_NOT_NULL(n);

	TEST_EQUAL_UI(n->mode, S_IFDIR | 0755);
	TEST_EQUAL_UI(n->uid, 0);
	TEST_EQUAL_UI(n->gid, 0);
	TEST_EQUAL_UI(n->link_count, 6);
	TEST_STR_EQUAL(n->name, "test");
	TEST_NULL(n->next);

	n = n->data.children;
	TEST_NOT_NULL(n);

	TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
	TEST_EQUAL_UI(n->uid, 0);
	TEST_EQUAL_UI(n->gid, 0);
	TEST_EQUAL_UI(n->link_count, 1);
	TEST_STR_EQUAL(n->name, "file1");
	TEST_NOT_NULL(n->data.file.input_file);
	TEST_STR_EQUAL(n->data.file.input_file, "test/file1");
	TEST_NOT_NULL(n->next);
	n = n->next;

	TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
	TEST_EQUAL_UI(n->uid, 0);
	TEST_EQUAL_UI(n->gid, 0);
	TEST_EQUAL_UI(n->link_count, 1);
	TEST_STR_EQUAL(n->name, "file2");
	TEST_NOT_NULL(n->data.file.input_file);
	TEST_STR_EQUAL(n->data.file.input_file, "completely/different/path");
	TEST_NOT_NULL(n->next);
	n = n->next;

	TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
	TEST_EQUAL_UI(n->uid, 0);
	TEST_EQUAL_UI(n->gid, 0);
	TEST_EQUAL_UI(n->link_count, 1);
	TEST_STR_EQUAL(n->name, "file3");
	TEST_NOT_NULL(n->data.file.input_file);
	TEST_STR_EQUAL(n->data.file.input_file, "/absolute/path");
	TEST_NOT_NULL(n->next);
	n = n->next;

	TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
	TEST_EQUAL_UI(n->uid, 0);
	TEST_EQUAL_UI(n->gid, 0);
	TEST_EQUAL_UI(n->link_count, 1);
	TEST_STR_EQUAL(n->name, "file4");
	TEST_NOT_NULL(n->data.file.input_file);
	TEST_STR_EQUAL(n->data.file.input_file, "/ ! ");
	TEST_NULL(n->next);

	fstree_cleanup(&fs);
	return EXIT_SUCCESS;
}