2 type: INT, LONG, STRING, FLOAT, PTR
25 } static const cases
[] = {
27 {0xab, "%04x", "00ab"},
28 {0xffff, "0x%02X", "0xFFFF"},
29 {0xffffu
, "%u", "65535"},
30 {1234, "%+6d", " +1234"},
31 {12345, "% d", " 12345"},
32 {-1234, "%d", "-1234"},
33 {32767, "%8d", " 32767"},
35 {1001, "%08i", "00001001"},
36 {101, "%-+8d", "+101 "},
37 {01234, "%o(oct)", "1234(oct)"},
39 // do we want to check these:
40 #if defined(__SDCC) && !defined(__SDCC_z80) && CHECK_B
41 {0x4142, "%bc %bx", "\x41 42"}, /* non-std: print as bytes! */
42 {0xfffe, "0x%02bX%02bx", "0xFFfe"}, /* non-std: print as bytes! */
43 #elif defined(__SDCC) && defined(__SDCC_z80) && CHECK_B
44 {0x4142, "%bc %bx", "\x42 41"}, /* non-std: print as bytes! */
45 {0xfffe, "0x%02bX%02bx", "0xFEff"}, /* non-std: print as bytes! */
56 } static const cases
[] = {
58 {0x12345678, "0x%lx", "0x12345678"},
59 {0x7fffFFFF, "%10lx", " 7fffffff"},
60 {0x789abcde, "0x%-10lX", "0x789ABCDE "},
61 {0x1000a, "0x%02lX", "0x1000A"},
62 {0x80000000, "%lu", "2147483648"},
63 {-2147483648, "%li", "-2147483648"},
64 {-1234, "%+6ld", " -1234"},
65 {012345670123, "%lo(oct)", "12345670123(oct)"},
66 {0xffffFFFF, "%lo(oct)", "37777777777(oct)"},
68 // do we want to check these:
69 #if defined(__SDCC) && !defined(__SDCC_z80) && CHECK_B
70 {0xfedcba98, "0x%bX%bX%bx%bx", "0xFEDCba98"}, /* non-std: print as bytes! */
71 #elif defined(__SDCC) && defined(__SDCC_z80) && CHECK_B
72 {0xfedcba98, "0x%bX%bX%bx%bx", "0x98BAdcfe"}, /* non-std: print as bytes! */
83 } static const cases
[] = {
85 {"abcd", "%s", "abcd"},
86 {"abcd", "%3s", "abcd"},
87 {"abcd", "%5s", " abcd"},
88 {"abcd", "%-5s", "abcd "},
89 {"abcd", "%.2s", "ab"},
90 {"XYZ\\", "%s", "XYZ\x5c"},
91 {"ab\x1b\x7f", "%s", "ab\x1b\x7f"},
92 {"ab\tcd\n", "%s", "ab\tcd\n"},
102 } static const cases
[] = {
104 // ... there should be more ...
105 #if defined(__SDCC) && !defined(__SDCC_ds390) && !(defined(__SDCC_mcs51) && (defined(__SDCC_USE_XSTACK) || defined(__SDCC_MODEL_HUGE)))
106 {1.0, "%f", "<NO FLOAT>"},
108 {1.0, "%f", "1.000000"},
109 {1.96, "%3.1f", "2.0"},
119 #if defined(__SDCC) && (defined(__SDCC_mcs51) || defined(__SDCC_ds390))
120 __idata
unsigned char __at(0xAA) var_idata
;
121 __pdata
unsigned char __at(0xAA) var_pdata
;
122 __xdata
unsigned char __at(0xAABB) var_xdata
;
123 __code
unsigned char __at(0xAABB) var_code
;
131 } static const cases
[] = {
133 #if defined(__SDCC) && defined(__SDCC_ds390)
134 // Special cases for ds390 covering different address spaces.
135 {var_idata
, "%p", "I:0x0000aa"},
136 {var_pdata
, "%p", "P:0x0000aa"},
137 {var_xdata
, "%p", "X:0x00aabb"},
138 {var_code
, "%p", "C:0x00aabb"},
140 {var_idata
, "%P", "I:0x0000AA"},
141 {var_pdata
, "%P", "P:0x0000AA"},
142 {var_xdata
, "%P", "X:0x00AABB"},
143 {var_code
, "%P", "C:0x00AABB"},
145 #elif defined(__SDCC) && defined(__SDCC_mcs51)
146 // Special cases for mcs51 covering different address spaces.
147 {var_idata
, "%p", "I:0xaa"},
148 {var_pdata
, "%p", "P:0xaa"},
149 {var_xdata
, "%p", "X:0xaabb"},
150 {var_code
, "%p", "C:0xaabb"},
152 {var_idata
, "%P", "I:0xAA"},
153 {var_pdata
, "%P", "P:0xAA"},
154 {var_xdata
, "%P", "X:0xAABB"},
155 {var_code
, "%P", "C:0xAABB"},
158 {(void *)0xAABB, "%p", "0xaabb"},
160 {(void *)0xAABB, "%P", "0xAABB"},
170 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
172 unsigned char buf
[32];
175 memset (buf
, 0xfe, sizeof buf
); /* cookies all over */
177 for (i
= 0; i
< sizeof cases
/ sizeof cases
[0]; i
++)
179 sprintf (buf
, cases
[i
].fmt
, cases
[i
].arg
);
180 DEBUG (__prints ("Test"));
181 DEBUG (__printd (i
));
182 DEBUG (__prints (" should be: '"));
183 DEBUG (__prints (cases
[i
].result
));
184 DEBUG (__prints ("' is: '"));
185 DEBUG (__prints (buf
));
186 DEBUG (__prints ("'\n"));
187 ASSERT (!strcmp (buf
, cases
[i
].result
));
190 ASSERT (buf
[sizeof buf
- 10] == 0xfe); /* check for cookie */