2 #include <winpr/wtypes.h>
3 #include <winpr/string.h>
5 int TestFormatSpecifiers(
int argc,
char* argv[])
17 const char* chk =
"uz:43981 oz:125715 xz:abcd Xz:ABCD";
19 (void)sprintf_s(fmt,
sizeof(fmt),
"uz:%" PRIuz
" oz:%" PRIoz
" xz:%" PRIxz
" Xz:%" PRIXz
"",
22 if (strcmp(fmt, chk) != 0)
24 (void)fprintf(stderr,
"%s failed size_t test: got [%s] instead of [%s]\n", __func__,
33 const char* chk =
"d8:-16 x8:f0 X8:F0";
35 (void)sprintf_s(fmt,
sizeof(fmt),
"d8:%" PRId8
" x8:%" PRIx8
" X8:%" PRIX8
"", arg,
36 (UINT8)arg, (UINT8)arg);
38 if (strcmp(fmt, chk) != 0)
40 (void)fprintf(stderr,
"%s failed INT8 test: got [%s] instead of [%s]\n", __func__, fmt,
49 const char* chk =
"u8:254 o8:376 x8:fe X8:FE";
51 (void)sprintf_s(fmt,
sizeof(fmt),
"u8:%" PRIu8
" o8:%" PRIo8
" x8:%" PRIx8
" X8:%" PRIX8
"",
54 if (strcmp(fmt, chk) != 0)
56 (void)fprintf(stderr,
"%s failed UINT8 test: got [%s] instead of [%s]\n", __func__, fmt,
65 const char* chk =
"d16:-16 x16:fff0 X16:FFF0";
67 (void)sprintf_s(fmt,
sizeof(fmt),
"d16:%" PRId16
" x16:%" PRIx16
" X16:%" PRIX16
"", arg,
68 (UINT16)arg, (UINT16)arg);
70 if (strcmp(fmt, chk) != 0)
72 (void)fprintf(stderr,
"%s failed INT16 test: got [%s] instead of [%s]\n", __func__, fmt,
81 const char* chk =
"u16:65534 o16:177776 x16:fffe X16:FFFE";
83 (void)sprintf_s(fmt,
sizeof(fmt),
84 "u16:%" PRIu16
" o16:%" PRIo16
" x16:%" PRIx16
" X16:%" PRIX16
"", arg, arg,
87 if (strcmp(fmt, chk) != 0)
89 (void)fprintf(stderr,
"%s failed UINT16 test: got [%s] instead of [%s]\n", __func__,
98 const char* chk =
"d32:-16 x32:fffffff0 X32:FFFFFFF0";
100 (void)sprintf_s(fmt,
sizeof(fmt),
"d32:%" PRId32
" x32:%" PRIx32
" X32:%" PRIX32
"", arg,
101 (UINT32)arg, (UINT32)arg);
103 if (strcmp(fmt, chk) != 0)
105 (void)fprintf(stderr,
"%s failed INT32 test: got [%s] instead of [%s]\n", __func__, fmt,
113 UINT32 arg = 0xFFFFFFFE;
114 const char* chk =
"u32:4294967294 o32:37777777776 x32:fffffffe X32:FFFFFFFE";
116 (void)sprintf_s(fmt,
sizeof(fmt),
117 "u32:%" PRIu32
" o32:%" PRIo32
" x32:%" PRIx32
" X32:%" PRIX32
"", arg, arg,
120 if (strcmp(fmt, chk) != 0)
122 (void)fprintf(stderr,
"%s failed UINT16 test: got [%s] instead of [%s]\n", __func__,
131 const char* chk =
"d64:-16 x64:fffffffffffffff0 X64:FFFFFFFFFFFFFFF0";
133 (void)sprintf_s(fmt,
sizeof(fmt),
"d64:%" PRId64
" x64:%" PRIx64
" X64:%" PRIX64
"", arg,
134 (UINT64)arg, (UINT64)arg);
136 if (strcmp(fmt, chk) != 0)
138 (void)fprintf(stderr,
"%s failed INT64 test: got [%s] instead of [%s]\n", __func__, fmt,
146 UINT64 arg = 0xFFFFFFFFFFFFFFFE;
147 const char* chk =
"u64:18446744073709551614 o64:1777777777777777777776 "
148 "x64:fffffffffffffffe X64:FFFFFFFFFFFFFFFE";
150 (void)sprintf_s(fmt,
sizeof(fmt),
151 "u64:%" PRIu64
" o64:%" PRIo64
" x64:%016" PRIx64
" X64:%016" PRIX64
"",
154 if (strcmp(fmt, chk) != 0)
156 (void)fprintf(stderr,
"%s failed UINT64 test: got [%s] instead of [%s]\n", __func__,
164 (void)fprintf(stderr,
"%s produced %u errors\n", __func__, errors);