run-grab.c 927 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* This is test for grab_file() function
  2. */
  3. #include <ccan/grab_file/grab_file.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <err.h>
  7. #include <sys/stat.h>
  8. #include <ccan/grab_file/grab_file.c>
  9. #include <ccan/tap/tap.h>
  10. #include <ccan/str_talloc/str_talloc.h>
  11. int
  12. main(int argc, char *argv[])
  13. {
  14. unsigned int i;
  15. char **split, *str;
  16. int length;
  17. struct stat st;
  18. str = grab_file(NULL, "test/run-grab.c", NULL);
  19. split = strsplit(str, str, "\n");
  20. length = strlen(split[0]);
  21. ok1(!strcmp(split[0], "/* This is test for grab_file() function"));
  22. for (i = 1; split[i]; i++)
  23. length += strlen(split[i]);
  24. ok1(!strcmp(split[i-1], "/* End of grab_file() test */"));
  25. if (stat("test/run-grab.c", &st) != 0)
  26. /* FIXME: ditto */
  27. if (stat("ccan/grab_file/test/run-grab.c", &st) != 0)
  28. err(1, "Could not stat self");
  29. ok1(st.st_size == length + i);
  30. talloc_free(str);
  31. return 0;
  32. }
  33. /* End of grab_file() test */