summaryrefslogtreecommitdiff
path: root/src/tests/evil
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-12-31 19:57:48 +0000
committerAndy Williams <andy@andywilliams.me>2017-12-31 19:57:48 +0000
commit763942d8c7243db84afd59ba13f2e396ceb93b07 (patch)
tree53a6f152bb4a5082cbe4876c51e87062b73baa04 /src/tests/evil
parentd234458dfcd9202c33f75049da6ebdad7888f4c5 (diff)
Fix and simpligy windows behaviour.
Author: Vincent Torri
Diffstat (limited to 'src/tests/evil')
-rw-r--r--src/tests/evil/evil_test_libgen.c308
1 files changed, 308 insertions, 0 deletions
diff --git a/src/tests/evil/evil_test_libgen.c b/src/tests/evil/evil_test_libgen.c
new file mode 100644
index 0000000000..eb8c17f18b
--- /dev/null
+++ b/src/tests/evil/evil_test_libgen.c
@@ -0,0 +1,308 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2017 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdlib.h>
24#include <string.h>
25#include <libgen.h>
26
27#include "evil_suite.h"
28
29START_TEST(evil_libgen_null)
30{
31 char *dname;
32 char *bname;
33
34 dname = dirname(NULL);
35 fail_if(strcmp(dname, ".") != 0);
36 bname = basename(NULL);
37 fail_if(strcmp(bname, ".") != 0);
38}
39END_TEST
40
41START_TEST(evil_libgen_empty)
42{
43 const char *path = "";
44 char *dirc;
45 char *basec;
46 char *dname;
47 char *bname;
48
49 dirc = strdup(path);
50 fail_if(dirc == NULL);
51 basec = strdup(path);
52 fail_if(basec == NULL);
53
54 dname = dirname(dirc);
55 fail_if(strcmp(dname, ".") != 0);
56 bname = basename(basec);
57 fail_if(strcmp(bname, ".") != 0);
58
59 free(dirc);
60 free(basec);
61}
62END_TEST
63
64START_TEST(evil_libgen_path)
65{
66 const char *path = "/usr/lib";
67 char *dirc;
68 char *basec;
69 char *dname;
70 char *bname;
71
72 dirc = strdup(path);
73 fail_if(dirc == NULL);
74 basec = strdup(path);
75 fail_if(basec == NULL);
76
77 dname = dirname(dirc);
78 fail_if(strcmp(dname, "/usr") != 0);
79 bname = basename(basec);
80 fail_if(strcmp(bname, "lib") != 0);
81
82 free(dirc);
83 free(basec);
84}
85END_TEST
86
87START_TEST(evil_libgen_path_with_slash)
88{
89 const char *path = "/usr/";
90 char *dirc;
91 char *basec;
92 char *dname;
93 char *bname;
94
95 dirc = strdup(path);
96 fail_if(dirc == NULL);
97 basec = strdup(path);
98 fail_if(basec == NULL);
99
100 dname = dirname(dirc);
101 fail_if(strcmp(dname, "/") != 0);
102 bname = basename(basec);
103 fail_if(strcmp(bname, "usr") != 0);
104
105 free(dirc);
106 free(basec);
107}
108END_TEST
109
110START_TEST(evil_libgen_folder)
111{
112 const char *path = "usr";
113 char *dirc;
114 char *basec;
115 char *dname;
116 char *bname;
117
118 dirc = strdup(path);
119 fail_if(dirc == NULL);
120 basec = strdup(path);
121 fail_if(basec == NULL);
122
123 dname = dirname(dirc);
124 fail_if(strcmp(dname, ".") != 0);
125 bname = basename(basec);
126 fail_if(strcmp(bname, "usr") != 0);
127
128 free(dirc);
129 free(basec);
130}
131END_TEST
132
133START_TEST(evil_libgen_slash)
134{
135 const char *path = "/";
136 char *dirc;
137 char *basec;
138 char *dname;
139 char *bname;
140
141 dirc = strdup(path);
142 fail_if(dirc == NULL);
143 basec = strdup(path);
144 fail_if(basec == NULL);
145
146 dname = dirname(dirc);
147 fail_if(strcmp(dname, "/") != 0);
148 bname = basename(basec);
149 fail_if(strcmp(bname, "/") != 0);
150
151 free(dirc);
152 free(basec);
153}
154END_TEST
155
156START_TEST(evil_libgen_dot)
157{
158 const char *path = ".";
159 char *dirc;
160 char *basec;
161 char *dname;
162 char *bname;
163
164 dirc = strdup(path);
165 fail_if(dirc == NULL);
166 basec = strdup(path);
167 fail_if(basec == NULL);
168
169 dname = dirname(dirc);
170 fail_if(strcmp(dname, ".") != 0);
171 bname = basename(basec);
172 fail_if(strcmp(bname, ".") != 0);
173
174 free(dirc);
175 free(basec);
176}
177END_TEST
178
179START_TEST(evil_libgen_dot_dot)
180{
181 const char *path = "..";
182 char *dirc;
183 char *basec;
184 char *dname;
185 char *bname;
186
187 dirc = strdup(path);
188 fail_if(dirc == NULL);
189 basec = strdup(path);
190 fail_if(basec == NULL);
191
192 dname = dirname(dirc);
193 fail_if(strcmp(dname, ".") != 0);
194 bname = basename(basec);
195 fail_if(strcmp(bname, "..") != 0);
196
197 free(dirc);
198 free(basec);
199}
200END_TEST
201
202START_TEST(evil_libgen_win_dir_1)
203{
204 const char *path = "c:/foo/bar";
205 char *dirc;
206 char *basec;
207 char *dname;
208 char *bname;
209
210 dirc = strdup(path);
211 fail_if(dirc == NULL);
212 basec = strdup(path);
213 fail_if(basec == NULL);
214
215 dname = dirname(dirc);
216 fail_if(strcmp(dname, "c:/foo") != 0);
217 bname = basename(basec);
218fail_if(strcmp(bname, "bar") != 0);
219
220 free(dirc);
221 free(basec);
222}
223END_TEST
224
225START_TEST(evil_libgen_win_dir_2)
226{
227 const char *path = "c:/foo\\bar";
228 char *dirc;
229 char *basec;
230 char *dname;
231 char *bname;
232
233 dirc = strdup(path);
234 fail_if(dirc == NULL);
235 basec = strdup(path);
236 fail_if(basec == NULL);
237
238 dname = dirname(dirc);
239 fail_if(strcmp(dname, "c:/foo") != 0);
240 bname = basename(basec);
241 fail_if(strcmp(bname, "bar") != 0);
242
243 free(dirc);
244 free(basec);
245}
246END_TEST
247
248START_TEST(evil_libgen_win_dir_3)
249{
250 const char *path = "c:\\foo/bar";
251 char *dirc;
252 char *basec;
253 char *dname;
254 char *bname;
255
256 dirc = strdup(path);
257 fail_if(dirc == NULL);
258 basec = strdup(path);
259 fail_if(basec == NULL);
260
261 dname = dirname(dirc);
262 fail_if(strcmp(dname, "c:\\foo") != 0);
263 bname = basename(basec);
264 fail_if(strcmp(bname, "bar") != 0);
265
266 free(dirc);
267 free(basec);
268}
269END_TEST
270
271START_TEST(evil_libgen_win_dir_4)
272{
273 const char *path = "c:\\foo\\bar";
274 char *dirc;
275 char *basec;
276 char *dname;
277 char *bname;
278
279 dirc = strdup(path);
280 fail_if(dirc == NULL);
281 basec = strdup(path);
282 fail_if(basec == NULL);
283
284 dname = dirname(dirc);
285 fail_if(strcmp(dname, "c:\\foo") != 0);
286 bname = basename(basec);
287 fail_if(strcmp(bname, "bar") != 0);
288
289 free(dirc);
290 free(basec);
291}
292END_TEST
293
294void evil_test_libgen(TCase *tc)
295{
296 tcase_add_test(tc, evil_libgen_null);
297 tcase_add_test(tc, evil_libgen_empty);
298 tcase_add_test(tc, evil_libgen_path);
299 tcase_add_test(tc, evil_libgen_path_with_slash);
300 tcase_add_test(tc, evil_libgen_folder);
301 tcase_add_test(tc, evil_libgen_slash);
302 tcase_add_test(tc, evil_libgen_dot);
303 tcase_add_test(tc, evil_libgen_dot_dot);
304 tcase_add_test(tc, evil_libgen_win_dir_1);
305 tcase_add_test(tc, evil_libgen_win_dir_2);
306 tcase_add_test(tc, evil_libgen_win_dir_3);
307 tcase_add_test(tc, evil_libgen_win_dir_4);
308}