fgetc_tc.c 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <string.h>
  3. static int fgetc_entry(void)
  4. {
  5. FILE *stream;
  6. char data[] = "test fgetc";
  7. char getc[sizeof(data)] = {0};
  8. size_t size = 0;
  9. int ret = 0;
  10. int i=0;
  11. stream = fopen("fopen_file.txt","w+");
  12. if (stream == NULL)
  13. {
  14. perror("fopen fail");
  15. ret = -1;
  16. goto __exit;
  17. }
  18. fwrite(data, sizeof(data), 1, stream);
  19. fclose(stream);
  20. stream = fopen("fopen_file.txt","r");
  21. while(1)
  22. {
  23. getc[i] = fgetc(stream);
  24. i++;
  25. if( feof(stream) )
  26. {
  27. break ;
  28. }
  29. }
  30. if(strcmp(getc, data))
  31. {
  32. return -1;
  33. }
  34. fclose(stream);
  35. __exit:
  36. return ret;
  37. }
  38. #include <utest.h>
  39. static void test_fgetc(void)
  40. {
  41. uassert_int_equal(fgetc_entry(), 0);
  42. }
  43. static void testcase(void)
  44. {
  45. UTEST_UNIT_RUN(test_fgetc);
  46. }
  47. UTEST_TC_EXPORT(testcase, "posix.stdio_h.fgetc.c", RT_NULL, RT_NULL, 10);