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