]> git.ozlabs.org Git - ccan/blob - ccan/noerr/test/run.c
Move modules to ccan/ tools to tools/
[ccan] / ccan / noerr / test / run.c
1 #include "noerr/noerr.h"
2 #include "tap/tap.h"
3 #include "noerr/noerr.c"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <assert.h>
9
10 int main(int argc, char *argv[])
11 {
12         /* tempnam(3) is generally a bad idea, but OK here. */
13         char *name = tempnam(NULL, "noerr");
14         int fd;
15
16         plan_tests(12);
17         /* Should fail to unlink. */
18         ok1(unlink(name) != 0);
19         ok1(errno == ENOENT);
20
21         /* This one should not set errno. */
22         errno = 100;
23         ok1(unlink_noerr(name) == ENOENT);
24         ok1(errno == 100);
25
26         /* Should fail to close. */
27         ok1(close(-1) != 0);
28         ok1(errno == EBADF);
29
30         /* This one should not set errno. */
31         errno = 100;
32         ok1(close_noerr(-1) == EBADF);
33         ok1(errno == 100);
34
35         /* Test successful close/unlink doesn't hit errno either. */
36         fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600);
37         assert(fd >= 0);
38
39         errno = 100;
40         ok1(close_noerr(fd) == 0);
41         ok1(errno == 100);
42
43         errno = 100;
44         ok1(unlink_noerr(name) == 0);
45         ok1(errno == 100);
46
47         return exit_status();
48 }