struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug1057979.c
blobb16383fbf6f28eb77aaf7567f62fa8576447db0d
1 /*
2 bug1057979.c
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <testfwk.h>
10 char s[12 + 1];
12 void
13 test_sprintf (void)
15 #if !defined( __SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_pic14) // Lack of memory
16 #ifndef __SDCC_pic16
17 s[12] = 0x12;
19 sprintf (s, "%d", 99);
20 ASSERT (0 == strcmp (s, "99"));
21 sprintf (s, "%d", 100);
22 ASSERT (0 == strcmp (s, "100"));
23 sprintf (s, "%d", 2004);
24 ASSERT (0 == strcmp (s, "2004"));
25 sprintf (s, "%ld", 2147483647L);
26 ASSERT (0 == strcmp (s, "2147483647"));
28 //and from bug 1073386
29 sprintf (s, "%04X", 0x8765u);
30 ASSERT (0 == strcmp (s, "8765"));
32 //and from bug 1193299
33 sprintf (s, "%3.3s", "abcd");
34 ASSERT (0 == strcmp (s, "abc"));
35 sprintf (s, "%-3.3s", "abcd");
36 ASSERT (0 == strcmp (s, "abc"));
37 sprintf (s, "%3.3s", "ab");
38 ASSERT (0 == strcmp (s, " ab"));
39 sprintf (s, "%-3.3s", "ab");
40 ASSERT (0 == strcmp (s, "ab "));
42 #if defined(__SDCC_ds390) || defined(PORT_HOST)
43 //and from bug 1358192
44 sprintf (s, "%f", 10.1);
45 LOG ((s));
46 ASSERT (0 == strcmp (s, "10.100000"));
48 //and from bug 1388703
49 sprintf (s, "%4.1f", 1.36);
50 LOG ((s));
51 ASSERT (0 == strcmp (s, " 1.4"));
52 sprintf (s, "%4.1f", -1.37);
53 LOG ((s));
54 ASSERT (0 == strcmp (s, "-1.4"));
55 #endif
57 ASSERT (s[12] == 0x12);
58 #endif
59 #endif