1
/* Test of sprintf_std(), invalid format.
2
$Id: sprintf_std-inv.c,v 1.1.2.1 2008/03/20 21:42:32 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...)
29
int retval, const char *retstr)
35
else if (strcmp_P (retstr, expstr))
39
PRINTFLN (line, "expect: %3d, \"%s\",\n%8s output: %3d, \"%s\"\n",
40
explen, expstr, " ", retval, retstr);
47
/* 'vp' is used to avoid gcc warnings about format string. */
48
#define CHECK(explen, expstr, fmt, ...) do { \
51
int (* volatile vp)(char *, const char *, ...) = sprintf_P; \
52
memset (s, 0, sizeof(s)); \
53
i = vp (s, PSTR(fmt), ##__VA_ARGS__); \
54
Check (__LINE__, explen, PSTR(expstr), i, s); \
59
#ifdef __AVR__ /* PRINTF_STD */
60
/* Float numbers: are skipped */
61
CHECK (1, "?", "%e", 0.0);
62
CHECK (23, "? e ? f ? g ? E ? F ? G",
63
"%e %c %e %c %e %c %e %c %e %c %e %c",
64
1.0, 'e', 2.0, 'f', 3.0, 'g', 4.0, 'E', 5.0, 'F', 6.0, 'G');
65
CHECK (19, "? 10 ? 11 ? 12 ? 13",
66
"%+e %d %-f %d % g %d %0F %d",
67
10.0, 10, 11.0, 11, 12.0, 12, 13.0, 13);
70
CHECK (17, " ?. ?. ?. ?",
71
"%2e.%3.1f.%+4g.% 5E", 1.0, 2.0, 3.0, 4.0);
73
/* Left pad is work. */
74
CHECK (6, "? .? ", "%-2F.%-03G", 5.0, 6.0);