setbuf_tc.c 794 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #include <string.h>
  3. static char outbuf[BUFSIZ];
  4. static int setbuf_entry(void)
  5. {
  6. FILE *stream;
  7. char test_data[] = "test setbuf";
  8. int ret = 0;
  9. stream = fopen("fopen_file.txt","w");
  10. if (stream == NULL)
  11. {
  12. perror("fopen fail");
  13. ret = -1;
  14. goto __exit;
  15. }
  16. setbuf(stream, outbuf);
  17. fwrite(test_data, sizeof(test_data), 1,stream);
  18. if(strcmp(test_data, outbuf))
  19. {
  20. printf("setbuf test:%s\n",test_data);
  21. ret = -1;
  22. }
  23. fclose(stream);
  24. __exit:
  25. return ret;
  26. }
  27. #include <utest.h>
  28. static void test_setbuf(void)
  29. {
  30. uassert_int_equal(setbuf_entry(), 0);
  31. }
  32. static void testcase(void)
  33. {
  34. UTEST_UNIT_RUN(test_setbuf);
  35. }
  36. UTEST_TC_EXPORT(testcase, "posix.stdio_h.setbuf.c", RT_NULL, RT_NULL, 10);