vfprintf_tc.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <string.h>
  4. static void WriteFrmtd(FILE *stream ,char *format, ...)
  5. {
  6. va_list args;
  7. va_start(args, format);
  8. vfprintf(stream, format, args);
  9. va_end(args);
  10. }
  11. static int vfprintf_entry(void)
  12. {
  13. int ret = 0;
  14. char buf[64] = {0};
  15. char test_data[] = "vfprintf test:2021-8-1 3.14 0xff";
  16. FILE *stream = fopen("fopen_file.txt", "w");
  17. if(stream)
  18. {
  19. WriteFrmtd(stream, "vfprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
  20. fclose(stream);
  21. stream = fopen("fopen_file.txt","r");
  22. fread(buf, 1, sizeof(test_data), stream);
  23. if(strcmp(buf, test_data))
  24. {
  25. ret = -1;
  26. }
  27. fclose(stream);
  28. }
  29. else
  30. {
  31. ret = -1;
  32. }
  33. return ret;
  34. }
  35. #include <utest.h>
  36. static void test_vfprintf(void)
  37. {
  38. uassert_int_equal(vfprintf_entry(), 0);
  39. }
  40. static void testcase(void)
  41. {
  42. UTEST_UNIT_RUN(test_vfprintf);
  43. }
  44. UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);