-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_commands.c
95 lines (73 loc) · 2.04 KB
/
test_commands.c
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
#ifdef TEST_COMMANDS
#include <stdio.h>
#include "tests.h"
#include "commands.h"
void treat(uint8_t return_code)
{
if (return_code == CMD_ERROR)
puts("/!\\ Error /!\\");
}
int main(int argc, char const *argv[])
{
mem_allocator allocator;
uint8_t *memory = malloc(MEM_SIZE);
mem_init(&allocator, memory, MEM_SIZE);
fs_file *root;
if(fs_new_root(&allocator, &root) == FS_ERROR)
puts("Error pour fs_new_root");
if (fs_add_regular(&allocator, root, "monFichierapappapapapapapapapapapapaas", NULL) == FS_ERROR)
puts("Error pour fs_add_file");
fs_file *home, *user, *file1;
fs_add_dir(&allocator, root, "home", &home);
fs_add_dir(&allocator, home, "user", &user);
fs_add_regular(&allocator, user, "file1", &file1);
fs_add_regular(&allocator, user, "file2", NULL);
cmd_filesystem myfilesystem;
myfilesystem.root = myfilesystem.working = root;
// begin tests
puts("* Test LS");
treat(ls(root));
puts("* End");
puts("* Test TREE");
treat(tree(root));
puts("* End");
puts("* Test MKDIR");
treat(mkdir(&allocator, root, "dossier"));
tree(root);
puts("* End");
puts("* Test TOUCH");
treat(touch(&allocator, root, "fileTouched"));
tree(root);
puts("* create twice fileTouched. Assert error.");
treat(touch(&allocator, root, "fileTouched"));
puts("* End");
puts("* Test WRITE");
treat(write(&allocator, file1, (const uint8_t*)"content_data_content_data_content_data_content_data"));
puts("* End");
puts("* Test CAT");
treat(cat(file1));
puts("* End");
puts("* Test RM");
tree(root);
puts("* rm /home/user/file1");
treat(rm(&allocator, file1));
tree(root);
puts("* End");
puts("* Test PWD");
myfilesystem.working = user;
treat(pwd(&allocator, &myfilesystem));
puts("* End");
puts("* Test CD");
char filepath[] = "/home/.././home/./././user/";
printf("in : %s\n", filepath);
treat(cd(&myfilesystem, filepath));
pwd(&allocator, &myfilesystem);
puts("* End");
if (fs_delete_root(&allocator, &root) == FS_ERROR)
puts("Error pour fs_delete_root");
// clean test
mem_debug(&allocator);
free(memory);
return 0;
}
#endif