run-failpath.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <ccan/failtest/failtest.c>
  2. #include <stdlib.h>
  3. #include <setjmp.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <ccan/tap/tap.h>
  7. int main(void)
  8. {
  9. int fds[2], fd;
  10. void *p;
  11. plan_tests(14);
  12. failtest_init(0, NULL);
  13. failpath = "mceopwrMCEOPWR";
  14. ok1((p = failtest_malloc(10, "run-failpath.c", 1)) != NULL);
  15. ok1(failtest_calloc(10, 5, "run-failpath.c", 1) != NULL);
  16. ok1((p = failtest_realloc(p, 100, "run-failpath.c", 1)) != NULL);
  17. ok1((fd = failtest_open("failpath-scratch", "run-failpath.c", 1,
  18. O_RDWR|O_CREAT, 0600)) >= 0);
  19. ok1(failtest_pipe(fds, "run-failpath.c", 1) == 0);
  20. ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == 4);
  21. lseek(fd, 0, SEEK_SET);
  22. ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == 4);
  23. /* Now we're into the failures. */
  24. ok1(failtest_malloc(10, "run-failpath.c", 1) == NULL);
  25. ok1(failtest_calloc(10, 5, "run-failpath.c", 1) == NULL);
  26. ok1(failtest_realloc(p, 100, "run-failpath.c", 1) == NULL);
  27. ok1(failtest_open("failpath-scratch", "run-failpath.c", 1,
  28. O_RDWR|O_CREAT, 0600) == -1);
  29. ok1(failtest_pipe(fds, "run-failpath.c", 1) == -1);
  30. ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == -1);
  31. lseek(fd, 0, SEEK_SET);
  32. ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == -1);
  33. return exit_status();
  34. }