-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_commands.c
79 lines (59 loc) · 1.67 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
#ifdef TEST_COMMANDS
#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_init_directory");
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);
// 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, "content_data_content_data_content_data_content_data", 52));
puts("* End");
puts("* Test CAT");
treat(cat(file1));
puts("* End");
puts("* Test RM");
puts("* rm /dossier /home/user/file2");
treat(rm(&allocator, user, "file2"));
treat(rm(&allocator, &root, "dossier"));
tree(&root);
puts("* End");
if (fs_delete_root(&allocator, &root) == FS_ERROR)
puts("Error pour fs_delete_root");
// clean test
free(memory);
return 0;
}
#endif