r19116: fixed a checker warning
[ira/wip.git] / source / lib / replace / test / testsuite.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    libreplace tests
5
6    Copyright (C) Jelmer Vernooij 2006
7
8      ** NOTE! The following LGPL license applies to the talloc
9      ** library. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27 #include "replace.h"
28
29 /*
30   we include all the system/ include files here so that libreplace tests
31   them in the build farm
32 */
33 #include "system/capability.h"
34 #include "system/dir.h"
35 #include "system/filesys.h"
36 #include "system/glob.h"
37 #include "system/iconv.h"
38 #include "system/locale.h"
39 #include "system/network.h"
40 #include "system/passwd.h"
41 #include "system/printing.h"
42 #include "system/readline.h"
43 #include "system/select.h"
44 #include "system/shmem.h"
45 #include "system/syslog.h"
46 #include "system/terminal.h"
47 #include "system/time.h"
48 #include "system/wait.h"
49
50 #define TESTFILE "testfile.dat"
51
52 /*
53   test ftruncate() function
54  */
55 static int test_ftruncate(void)
56 {
57         struct stat st;
58         int fd;
59         const int size = 1234;
60         printf("testing ftruncate\n");
61         unlink(TESTFILE);
62         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
63         if (fd == -1) {
64                 printf("creating '%s' failed - %s\n", TESTFILE, strerror(errno));
65                 return false;
66         }
67         if (ftruncate(fd, size) != 0) {
68                 printf("ftruncate failed - %s\n", strerror(errno));
69                 return false;
70         }
71         if (fstat(fd, &st) != 0) {
72                 printf("fstat failed - %s\n", strerror(errno));
73                 return false;
74         }
75         if (st.st_size != size) {
76                 printf("ftruncate gave wrong size %d - expected %d\n",
77                        (int)st.st_size, size);
78                 return false;
79         }
80         return true;
81 }
82
83 /*
84   test strlcpy() function.
85   see http://www.gratisoft.us/todd/papers/strlcpy.html
86  */
87 static int test_strlcpy(void)
88 {
89         char buf[4];
90         const struct {
91                 const char *src;
92                 size_t result;
93         } tests[] = {
94                 { "abc", 3 },
95                 { "abcdef", 6 },
96                 { "abcd", 4 },
97                 { "", 0 },
98                 { NULL, 0 }
99         };
100         int i;
101         printf("testing strlcpy\n");
102         for (i=0;tests[i].src;i++) {
103                 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
104                         printf("strlcpy test %d failed\n", i);
105                         return false;
106                 }
107         }
108         return true;
109 }
110
111 static int test_strlcat(void)
112 {
113         /* FIXME */
114         return true;
115 }
116
117 static int test_mktime(void)
118 {
119         /* FIXME */
120         return true;
121 }
122
123 static int test_innetgr(void)
124 {
125         /* FIXME */
126         return true;
127 }
128
129 static int test_initgroups(void)
130 {
131         /* FIXME */
132         return true;
133 }
134
135 static int test_memmove(void)
136 {
137         /* FIXME */
138         return true;
139 }
140
141 static int test_strdup(void)
142 {
143         /* FIXME */
144         return true;
145 }       
146
147 static int test_setlinebuf(void)
148 {
149         printf("testing setlinebuf\n");
150         setlinebuf(stdout);
151         return true;
152 }
153
154 static int test_vsyslog(void)
155 {
156         /* FIXME */
157         return true;
158 }
159
160 static int test_timegm(void)
161 {
162         /* FIXME */
163         return true;
164 }
165
166 static int test_setenv(void)
167 {
168         /* FIXME */
169         return true;
170 }
171
172 static int test_strndup(void)
173 {
174         /* FIXME */
175         return true;
176 }
177
178 static int test_strnlen(void)
179 {
180         /* FIXME */
181         return true;
182 }
183
184 static int test_waitpid(void)
185 {
186         /* FIXME */
187         return true;
188 }
189
190 static int test_seteuid(void)
191 {
192         /* FIXME */
193         return true;
194 }
195
196 static int test_setegid(void)
197 {
198         /* FIXME */
199         return true;
200 }
201
202 static int test_asprintf(void)
203 {
204         /* FIXME */
205         return true;
206 }
207
208 static int test_snprintf(void)
209 {
210         /* FIXME */
211         return true;
212 }
213
214 static int test_vasprintf(void)
215 {
216         /* FIXME */
217         return true;
218 }
219
220 static int test_vsnprintf(void)
221 {
222         /* FIXME */
223         return true;
224 }
225
226 static int test_opendir(void)
227 {
228         /* FIXME */
229         return true;
230 }
231
232 extern int test_readdir_os2_delete(void);
233
234 static int test_readdir(void)
235 {
236         printf("testing readdir\n");
237         if (test_readdir_os2_delete() != 0) {
238                 return false;
239         }
240         return true;
241 }
242
243 static int test_telldir(void)
244 {
245         /* FIXME */
246         return true;
247 }
248
249 static int test_seekdir(void)
250 {
251         /* FIXME */
252         return true;
253 }
254
255 static int test_dlopen(void)
256 {
257         /* FIXME: test dlopen, dlsym, dlclose, dlerror */
258         return true;
259 }
260
261
262 static int test_chroot(void)
263 {
264         /* FIXME: chroot() */
265         return true;
266 }
267
268 static int test_bzero(void)
269 {
270         /* FIXME: bzero */
271         return true;
272 }
273
274 static int test_strerror(void)
275 {
276         /* FIXME */
277         return true;
278 }
279
280 static int test_errno(void)
281 {
282         /* FIXME */
283         return true;
284 }
285
286 static int test_mkdtemp(void)
287 {
288         /* FIXME */
289         return true;
290 }
291
292 static int test_mkstemp(void)
293 {
294         /* FIXME */
295         return true;
296 }
297
298 static int test_pread(void)
299 {
300         /* FIXME */
301         return true;
302 }
303
304 static int test_pwrite(void)
305 {
306         /* FIXME */
307         return true;
308 }
309
310 static int test_getpass(void)
311 {
312         /* FIXME */
313         return true;
314 }
315
316 static int test_inet_ntoa(void)
317 {
318         /* FIXME */
319         return true;
320 }
321
322 static int test_strtoll(void)
323 {
324         /* FIXME */
325         return true;
326 }
327
328 static int test_strtoull(void)
329 {
330         /* FIXME */
331         return true;
332 }
333
334 /* 
335 FIXME:
336 Types:
337 bool
338 socklen_t
339 uint_t
340 uint{8,16,32,64}_t
341 int{8,16,32,64}_t
342 intptr_t
343
344 Constants:
345 PATH_NAME_MAX
346 UINT{16,32,64}_MAX
347 INT32_MAX
348 */
349
350 static int test_va_copy(void)
351 {
352         /* FIXME */
353         return true;
354 }
355
356 static int test_FUNCTION(void)
357 {
358         /* FIXME: test __FUNCTION__ macro */
359         return true;
360 }
361
362 static int test_MIN(void)
363 {
364         /* FIXME */
365         return true;
366 }
367
368 static int test_MAX(void)
369 {
370         /* FIXME */
371         return true;
372 }
373
374 struct torture_context;
375
376 bool torture_local_replace(struct torture_context *torture)
377 {
378         bool ret = true;
379         ret &= test_ftruncate();
380         ret &= test_strlcpy();
381         ret &= test_strlcat();
382         ret &= test_mktime();
383         ret &= test_innetgr();
384         ret &= test_initgroups();
385         ret &= test_memmove();
386         ret &= test_strdup();
387         ret &= test_setlinebuf();
388         ret &= test_vsyslog();
389         ret &= test_timegm();
390         ret &= test_setenv();
391         ret &= test_strndup();
392         ret &= test_strnlen();
393         ret &= test_waitpid();
394         ret &= test_seteuid();
395         ret &= test_setegid();
396         ret &= test_asprintf();
397         ret &= test_snprintf();
398         ret &= test_vasprintf();
399         ret &= test_vsnprintf();
400         ret &= test_opendir();
401         ret &= test_readdir();
402         ret &= test_telldir();
403         ret &= test_seekdir();
404         ret &= test_dlopen();
405         ret &= test_chroot();
406         ret &= test_bzero();
407         ret &= test_strerror();
408         ret &= test_errno();
409         ret &= test_mkdtemp();
410         ret &= test_mkstemp();
411         ret &= test_pread();
412         ret &= test_pwrite();
413         ret &= test_getpass();
414         ret &= test_inet_ntoa();
415         ret &= test_strtoll();
416         ret &= test_strtoll();
417         ret &= test_strtoull();
418         ret &= test_va_copy();
419         ret &= test_FUNCTION();
420         ret &= test_MIN();
421         ret &= test_MAX();
422
423         return ret;
424 }
425
426 #if _SAMBA_BUILD_<4
427 int main(void)
428 {
429         if (!torture_local_replace(NULL)) {
430                 printf("ERROR: TESTSUITE FAILED\n");
431                 return -1;
432         }
433         return 0;
434 }
435 #endif