fprintf_tc.c 878 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include <string.h>
  3. static int fdopen_entry(void)
  4. {
  5. FILE *stream;
  6. char test_data[] = "1a2bxx";
  7. char gets[sizeof(test_data)] = {0};
  8. size_t size = 0;
  9. int ret = 0;
  10. stream = fopen("fopen_file.txt","w");
  11. if (stream == NULL)
  12. {
  13. perror("fopen fail");
  14. ret = -1;
  15. goto __exit;
  16. }
  17. fprintf(stream, "%d%c%d%c%s",1,'a',2,'b',"xx");
  18. fclose(stream);
  19. stream = fopen("fopen_file.txt","r");
  20. fgets(gets, sizeof(gets), stream);
  21. if(strcmp(test_data, gets))
  22. {
  23. printf("%s\n",gets);
  24. ret = -1;
  25. }
  26. __exit:
  27. fclose(stream);
  28. return ret;
  29. }
  30. #include <utest.h>
  31. static void test_fdopen(void)
  32. {
  33. uassert_int_equal(fdopen_entry(), 0);
  34. }
  35. static void testcase(void)
  36. {
  37. UTEST_UNIT_RUN(test_fdopen);
  38. }
  39. UTEST_TC_EXPORT(testcase, "posix.stdio_h.fprintf.c", RT_NULL, RT_NULL, 10);