rewind_tc.c 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include <string.h>
  3. static int rewind_entry(void)
  4. {
  5. long l;
  6. char s[81] = {0};
  7. char c;
  8. int ret = 0;
  9. FILE* stream = fopen("fopen_file.txt","w+");
  10. if(stream == NULL)
  11. {
  12. ret = -1;
  13. perror("fopen");
  14. }
  15. else
  16. {
  17. fprintf(stream,"%s %d %c","a_string",6500,'x');
  18. rewind(stream);
  19. fscanf(stream,"%s",s);
  20. fscanf(stream,"%ld",&l);
  21. fscanf(stream," %c",&c);
  22. if((strcmp(s,"a_string") != 0) || (l != 6500) || (c != 'x'))
  23. {
  24. ret = -1;
  25. }
  26. fclose(stream);
  27. }
  28. return ret;
  29. }
  30. #include <utest.h>
  31. static void test_rewind(void)
  32. {
  33. uassert_int_equal(rewind_entry(), 0);
  34. }
  35. static void testcase(void)
  36. {
  37. UTEST_UNIT_RUN(test_rewind);
  38. }
  39. UTEST_TC_EXPORT(testcase, "posix.stdio_h.rewind.c", RT_NULL, RT_NULL, 10);