1
/* Test of sprintf_min(), specification: x.
2
$Id: sprintf_min-5.c,v 1.1.2.1 2008/03/20 21:42:31 joerg_wunsch Exp $ */
5
# define PRINTFLN(line, fmt, ...) \
6
printf("\nLine %2d: " fmt "\n", line, ##__VA_ARGS__)
7
# define EXIT(code) exit ((code) < 255 ? (code) : 255)
8
# define sprintf_P sprintf
10
# if defined(__AVR_ATmega128__)
11
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
12
# define PRINTFLN(line, fmt, ...) \
13
sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
16
# define PRINTFLN(args...)
28
int retval, const char *retstr)
32
if (retval != (int)strlen (retstr))
34
else if (strcmp_P (retstr, expstr))
38
PRINTFLN (line, "expect: %3d, \"%s\",\n%8s output: %3d, \"%s\"\n",
39
strlen(expstr), expstr, " ", retval, retstr);
46
/* 'vp' is used to avoid gcc warnings about format string. */
47
#define CHECK(expstr, fmt, ...) do { \
50
int (* volatile vp)(char *, const char *, ...) = sprintf_P; \
51
memset (s, 0, sizeof(s)); \
52
i = vp (s, PSTR(fmt), ##__VA_ARGS__); \
53
Check (__LINE__, PSTR(expstr), i, s); \
59
CHECK ("0 1234 5678 9ABC DEF0",
60
"%X %X %X %X %X", 0, 0x1234, 0x5678, 0x9abc, 0xdef0);
61
CHECK ("0XFEDC 0XBA98 0X7654 0X3210",
62
"%#X %#X %#X %#X", 0xfedc, 0xba98, 0x7654, 0x3210);
65
#ifdef __AVR__ /* Glibc result: (nil) */
68
CHECK ("0x1 0xabcd 0xef02", "%p %p %p", 1, 0xabcd, 0xef02);