vsprintf_tc.c 761 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <string.h>
  4. static char buf[64] = {0};
  5. static void WriteFrmtd(char *format, ...)
  6. {
  7. va_list args;
  8. va_start(args, format);
  9. vsprintf(buf, format, args);
  10. va_end(args);
  11. }
  12. static int vsprintf_entry(void)
  13. {
  14. char buf[64] = {0};
  15. char test_data[] = "vsprintf test:2021-8-1 3.14 0xff";
  16. sprintf(buf, "vsprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
  17. if(strcmp(buf, test_data))
  18. {
  19. return -1;
  20. }
  21. return 0;
  22. }
  23. #include <utest.h>
  24. static void test_vsprintf(void)
  25. {
  26. uassert_int_equal(vsprintf_entry(), 0);
  27. }
  28. static void testcase(void)
  29. {
  30. UTEST_UNIT_RUN(test_vsprintf);
  31. }
  32. UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);