putc_tc.c 785 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. static int putc_entry(void)
  3. {
  4. FILE *stream;
  5. int ch = 'a';
  6. int getc = {0};
  7. size_t size = 0;
  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. putc(ch, stream);
  17. fclose(stream);
  18. stream = fopen("fopen_file.txt","r");
  19. getc = fgetc(stream);
  20. if(getc != ch)
  21. {
  22. printf("fputc test:getc %c",getc);
  23. ret = -1;
  24. }
  25. __exit:
  26. fclose(stream);
  27. return ret;
  28. }
  29. #include <utest.h>
  30. static void test_putc(void)
  31. {
  32. uassert_int_equal(putc_entry(), 0);
  33. }
  34. static void testcase(void)
  35. {
  36. UTEST_UNIT_RUN(test_putc);
  37. }
  38. UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);