-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_test.c
More file actions
151 lines (106 loc) · 4.03 KB
/
copy_test.c
File metadata and controls
151 lines (106 loc) · 4.03 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "copy.c"
#include "test.c"
static MunitResult test_copy_file(const MunitParameter params[], void *data) {
const char *c = __func__;
char *f = test_create_file(c, "file");
char *d = test_create_dir(c, "dir");
copy_yank(f, false);
copy_paste(d);
usleep(TEST_SLEEP);
test_assert_file_exists(c, "file");
test_assert_file_exists(c, "dir/file");
return test_cleanup_files(c);
}
static MunitResult test_copy_directory(const MunitParameter params[], void *data) {
const char *c = __func__;
char *src = test_create_dir(c, "source");
test_create_file(c, "source/file");
char *target = test_create_dir(c, "target");
copy_yank(src, false);
copy_paste(target);
usleep(TEST_SLEEP);
test_assert_file_exists(c, "source/file");
test_assert_file_exists(c, "target/source/file");
return test_cleanup_files(c);
}
static MunitResult test_move_file(const MunitParameter params[], void *data) {
const char *c = __func__;
char *f = test_create_file(c, "file");
char *target = test_create_dir(c, "target");
copy_yank(f, true);
copy_paste(target);
usleep(TEST_SLEEP);
test_assert_file_not_exists(c, "file");
test_assert_file_exists(c, "target/file");
return test_cleanup_files(c);
}
static MunitResult test_move_directory(const MunitParameter params[], void *data) {
const char *c = __func__;
char *src = test_create_dir(c, "source");
test_create_file(c, "source/file");
char *target = test_create_dir(c, "target");
copy_yank(src, true);
copy_paste(target);
usleep(TEST_SLEEP);
test_assert_file_not_exists(c, "source/file");
test_assert_dir_not_exists(c, "source");
test_assert_file_exists(c, "target/source/file");
return test_cleanup_files(c);
}
static MunitResult test_copy_file_free_file_name_before_pasting(const MunitParameter params[], void *data) {
const char *c = __func__;
char *f = test_create_file(c, "file");
char *d = test_create_dir(c, "dir");
copy_yank(f, false);
free(f);
copy_paste(d);
usleep(TEST_SLEEP);
test_assert_file_exists(c, "file");
test_assert_file_exists(c, "dir/file");
return test_cleanup_files(c);
}
static MunitResult test_copy_file_copy_twice(const MunitParameter params[], void *data) {
return MUNIT_SKIP; // TODO
// Expected behavior is to ignore the first copy
const char *c = __func__;
char *f1 = test_create_file(c, "file1");
char *f2 = test_create_file(c, "file2");
char *d = test_create_dir(c, "dir");
copy_yank(f1, false);
copy_yank(f2, false);
copy_paste(d);
usleep(TEST_SLEEP);
test_assert_file_exists(c, "file1");
test_assert_file_exists(c, "file2");
test_assert_file_not_exists(c, "dir/file1");
test_assert_file_exists(c, "dir/file2");
return test_cleanup_files(c);
}
static MunitResult test_copy_file_paste_twice(const MunitParameter params[], void *data) {
return MUNIT_SKIP; // TODO
// Expected behavior is to fail on the second paste
const char *c = __func__;
char *f = test_create_file(c, "file");
char *d1 = test_create_dir(c, "dir1");
char *d2 = test_create_dir(c, "dir2");
copy_yank(f, false);
copy_paste(d1);
copy_paste(d2);
usleep(TEST_SLEEP);
test_assert_file_exists(c, "file");
test_assert_file_exists(c, "dir1/file");
test_assert_file_not_exists(c, "dir2/file");
return test_cleanup_files(c);
}
MunitTest copy_tests[] = {
{"/copy_file", test_copy_file, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{"/copy_directory", test_copy_directory, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{"/move_file", test_move_file, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{"/move_directory", test_move_directory, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
// edge cases
{"/copy_file_free_file_name_before_pasting", test_copy_file_free_file_name_before_pasting, NULL, NULL,
MUNIT_TEST_OPTION_NONE, NULL},
{"/copy_file_copy_twice", test_copy_file_copy_twice, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{"/copy_file_paste_twice", test_copy_file_paste_twice, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
};