r18160: - pread and pwrite replacements need to be non-static
[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                 int 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         /* FIXME */
150         return true;
151 }
152
153 static int test_vsyslog(void)
154 {
155         /* FIXME */
156         return true;
157 }
158
159 static int test_timegm(void)
160 {
161         /* FIXME */
162         return true;
163 }
164
165 static int test_setenv(void)
166 {
167         /* FIXME */
168         return true;
169 }
170
171 static int test_strndup(void)
172 {
173         /* FIXME */
174         return true;
175 }
176
177 static int test_strnlen(void)
178 {
179         /* FIXME */
180         return true;
181 }
182
183 static int test_waitpid(void)
184 {
185         /* FIXME */
186         return true;
187 }
188
189 static int test_seteuid(void)
190 {
191         /* FIXME */
192         return true;
193 }
194
195 static int test_setegid(void)
196 {
197         /* FIXME */
198         return true;
199 }
200
201 static int test_asprintf(void)
202 {
203         /* FIXME */
204         return true;
205 }
206
207 static int test_snprintf(void)
208 {
209         /* FIXME */
210         return true;
211 }
212
213 static int test_vasprintf(void)
214 {
215         /* FIXME */
216         return true;
217 }
218
219 static int test_vsnprintf(void)
220 {
221         /* FIXME */
222         return true;
223 }
224
225 static int test_opendir(void)
226 {
227         /* FIXME */
228         return true;
229 }
230
231 static int test_readdir(void)
232 {
233         /* FIXME */
234         return true;
235 }
236
237 static int test_telldir(void)
238 {
239         /* FIXME */
240         return true;
241 }
242
243 static int test_seekdir(void)
244 {
245         /* FIXME */
246         return true;
247 }
248
249 static int test_dlopen(void)
250 {
251         /* FIXME: test dlopen, dlsym, dlclose, dlerror */
252         return true;
253 }
254
255
256 static int test_chroot(void)
257 {
258         /* FIXME: chroot() */
259         return true;
260 }
261
262 static int test_bzero(void)
263 {
264         /* FIXME: bzero */
265         return true;
266 }
267
268 static int test_strerror(void)
269 {
270         /* FIXME */
271         return true;
272 }
273
274 static int test_errno(void)
275 {
276         /* FIXME */
277         return true;
278 }
279
280 static int test_mkdtemp(void)
281 {
282         /* FIXME */
283         return true;
284 }
285
286 static int test_mkstemp(void)
287 {
288         /* FIXME */
289         return true;
290 }
291
292 static int test_pread(void)
293 {
294         /* FIXME */
295         return true;
296 }
297
298 static int test_pwrite(void)
299 {
300         /* FIXME */
301         return true;
302 }
303
304 static int test_getpass(void)
305 {
306         /* FIXME */
307         return true;
308 }
309
310 static int test_inet_ntoa(void)
311 {
312         /* FIXME */
313         return true;
314 }
315
316 static int test_strtoll(void)
317 {
318         /* FIXME */
319         return true;
320 }
321
322 static int test_strtoull(void)
323 {
324         /* FIXME */
325         return true;
326 }
327
328 /* 
329 FIXME:
330 Types:
331 bool
332 socklen_t
333 uint_t
334 uint{8,16,32,64}_t
335 int{8,16,32,64}_t
336 intptr_t
337
338 Constants:
339 PATH_NAME_MAX
340 UINT{16,32,64}_MAX
341 INT32_MAX
342 */
343
344 static int test_va_copy(void)
345 {
346         /* FIXME */
347         return true;
348 }
349
350 static int test_FUNCTION(void)
351 {
352         /* FIXME: test __FUNCTION__ macro */
353         return true;
354 }
355
356 static int test_MIN(void)
357 {
358         /* FIXME */
359         return true;
360 }
361
362 static int test_MAX(void)
363 {
364         /* FIXME */
365         return true;
366 }
367
368 int torture_local_replace(void *ctx)
369 {
370         int ret = true;
371         ret &= test_ftruncate();
372         ret &= test_strlcpy();
373         ret &= test_strlcat();
374         ret &= test_mktime();
375         ret &= test_innetgr();
376         ret &= test_initgroups();
377         ret &= test_memmove();
378         ret &= test_strdup();
379         ret &= test_setlinebuf();
380         ret &= test_vsyslog();
381         ret &= test_timegm();
382         ret &= test_setenv();
383         ret &= test_strndup();
384         ret &= test_strnlen();
385         ret &= test_waitpid();
386         ret &= test_seteuid();
387         ret &= test_setegid();
388         ret &= test_asprintf();
389         ret &= test_snprintf();
390         ret &= test_vasprintf();
391         ret &= test_vsnprintf();
392         ret &= test_opendir();
393         ret &= test_readdir() ;
394         ret &= test_telldir();
395         ret &= test_seekdir();
396         ret &= test_dlopen();
397         ret &= test_chroot();
398         ret &= test_bzero();
399         ret &= test_strerror();
400         ret &= test_errno();
401         ret &= test_mkdtemp();
402         ret &= test_mkstemp();
403         ret &= test_pread();
404         ret &= test_pwrite();
405         ret &= test_getpass();
406         ret &= test_inet_ntoa();
407         ret &= test_strtoll();
408         ret &= test_strtoll();
409         ret &= test_strtoull();
410         ret &= test_va_copy();
411         ret &= test_FUNCTION();
412         ret &= test_MIN();
413         ret &= test_MAX();
414
415         return ret;
416 }
417
418 #if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9))
419 int main(void)
420 {
421         if (!torture_local_replace(NULL)) {
422                 printf("ERROR: TESTSUITE FAILED\n");
423                 return -1;
424         }
425         return 0;
426 }
427 #endif