1
0
mirror of https://github.com/samba-team/samba.git synced 2025-06-22 07:17:05 +03:00
samba-mirror/lib/ccan/failtest/test/run-failpath.c
Rusty Russell 361f3ea9ee lib/ccan: import failtest and required ccan modules for TDB2 unit tests.
New modules: failtest, list, time, read_write_all and tlist.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-03-07 13:16:16 +11:00

40 lines
1.2 KiB
C

#include <ccan/failtest/failtest.c>
#include <stdlib.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdarg.h>
#include <ccan/tap/tap.h>
int main(void)
{
int fds[2], fd;
void *p;
plan_tests(14);
failtest_init(0, NULL);
failpath = "mceopwrMCEOPWR";
ok1((p = failtest_malloc(10, "run-failpath.c", 1)) != NULL);
ok1(failtest_calloc(10, 5, "run-failpath.c", 1) != NULL);
ok1((p = failtest_realloc(p, 100, "run-failpath.c", 1)) != NULL);
ok1((fd = failtest_open("failpath-scratch", "run-failpath.c", 1,
O_RDWR|O_CREAT, 0600)) >= 0);
ok1(failtest_pipe(fds, "run-failpath.c", 1) == 0);
ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == 4);
lseek(fd, 0, SEEK_SET);
ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == 4);
/* Now we're into the failures. */
ok1(failtest_malloc(10, "run-failpath.c", 1) == NULL);
ok1(failtest_calloc(10, 5, "run-failpath.c", 1) == NULL);
ok1(failtest_realloc(p, 100, "run-failpath.c", 1) == NULL);
ok1(failtest_open("failpath-scratch", "run-failpath.c", 1,
O_RDWR|O_CREAT, 0600) == -1);
ok1(failtest_pipe(fds, "run-failpath.c", 1) == -1);
ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == -1);
lseek(fd, 0, SEEK_SET);
ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == -1);
return exit_status();
}