1
/* Test of sprintf(), 'p,X' specifications.
2
$Id: sprintf-5.c,v 1.1 2007/02/18 13:44:46 dmix Exp $ */
10
# define sprintf_P sprintf
15
int retval, const char *retstr)
19
if (retval != (int)strlen (retstr))
21
else if (strcmp_P (retstr, expstr))
27
printf ("\nLine %3d: expect: %3d, \"%s\","
28
"\n output: %3d, \"%s\"\n",
29
line, strlen (expstr), expstr, retval, retstr);
30
code = (line < 256 ? line : 255); /* common OS restriction */
38
/* 'vp' is used to avoid gcc warnings about format string. */
39
#define CHECK(expstr, fmt, ...) do { \
42
int (* volatile vp)(char *, const char *, ...) = sprintf_P; \
43
memset (s, 0, sizeof(s)); \
44
i = vp (s, PSTR(fmt), ##__VA_ARGS__); \
45
Check (__LINE__, PSTR(expstr), i, s); \
51
CHECK ("0 1234 5678 9ABC DEF0",
52
"%X %X %X %X %X", 0, 0x1234, 0x5678, 0x9abc, 0xdef0);
53
CHECK ("0XFEDC 0XBA98 0X7654 0X3210",
54
"%#X %#X %#X %#X", 0xfedc, 0xba98, 0x7654, 0x3210);
60
CHECK ("0x1 0xabcd 0xef02", "%p %p %p", 1, 0xabcd, 0xef02);