struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / zeropad.c.in
blob158acbf6ec3594ddec936be8a856aea5b11af9e6
1 /** Zeropad tests.
3 storage: auto, __idata, __pdata, __xdata, __code,
4 */
5 #ifndef STORAGE
6 #define STORAGE_{storage}
7 #define STORAGE {storage}
8 #endif
10 #if defined (__GNUC__) && defined (__alpha__) && (__GNUC__ < 3)
11 /* since g fails on GCC 2.95.4 on alpha... */
12 #define FLEXARRAY 0
13 #define TEST_G 0
14 #elif defined (STORAGE_auto)
15 /* only static flexible arrays are allowed */
16 #define FLEXARRAY 0
17 #define TEST_G 1
18 #else
19 #define FLEXARRAY 1
20 #define TEST_G 1
21 #endif
23 #include <testfwk.h>
24 #include <stddef.h>
26 #ifndef __SDCC_pdk14 // Lack of memory
28 #if defined (STORAGE_auto)
29 void Zeropad(void)
31 #else
32 extern char STORAGE bug1470790[3];
33 char STORAGE bug1470790[] = {1, };
35 #endif //STORAGE_auto
37 const char *string1 = "\x00\x01";
38 const char string2[] = "\x00\x01";
40 #ifndef PORT_HOST
41 #pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS)
42 #pragma disable_warning 85 //no warning about unreferenced variables (W_NO_REFERENCE)
43 //array will be truncated but warning will be suppressed
44 //if truncation is incorrect, other ASSERTs will fail with high probability
45 char STORAGE trunc[2] = {'a', 'b', 'c'};
46 #endif
48 char STORAGE array[5] = {'a', 'b', 'c'};
50 #if TEST_G
51 struct w {
52 char a;
53 int b;
54 } STORAGE g[3] = {
55 {'x', 1},
56 {'y'},
57 {'z', 3}
59 #endif
61 struct x {
62 short a;
63 char b[10];
66 struct x STORAGE teststruct[5] = {
67 { 10, { 1, 2, 3, 4, 5} },
68 { 20, { 11 } },
69 { 30, { 6, 7, 8} }
72 #if FLEXARRAY
73 struct y {
74 short a;
75 char b[];
78 struct y STORAGE incompletestruct = {
79 10, {1, 2, 3, 4, 5}
81 #endif
83 struct z {
84 short a;
85 void (*fp)(void);
88 //see bug 2881971
89 struct z STORAGE funcptrstruct = {
93 #if !defined (STORAGE_auto)
94 void
95 Zeropad (void)
97 ASSERT (bug1470790[0] == 1);
98 ASSERT (bug1470790[1] == 0);
99 #endif //STORAGE_auto
101 ASSERT (string1[0] == '\x00');
102 ASSERT (string1[1] == '\x01');
103 ASSERT (string2[0] == '\x00');
104 ASSERT (string2[1] == '\x01');
106 ASSERT (array[2] == 'c');
107 ASSERT (array[4] == 0);
109 #if TEST_G
110 ASSERT (g[1].a == 'y');
111 ASSERT (g[1].b == 0);
112 ASSERT (g[2].a == 'z');
113 ASSERT (g[2].b == 3);
114 #endif
116 ASSERT (teststruct[0].b[1] == 2);
117 ASSERT (teststruct[0].b[5] == 0);
118 ASSERT (teststruct[1].b[0] == 11);
119 ASSERT (teststruct[4].b[9] == 0);
121 ASSERT (sizeof(teststruct[2].a) == 2);
122 ASSERT (sizeof(teststruct[1].b) == 10);
123 ASSERT (sizeof(teststruct[1]) == 12);
124 ASSERT (sizeof(teststruct) == 60);
126 #if FLEXARRAY
127 ASSERT (incompletestruct.a == 10);
128 ASSERT (incompletestruct.b[0] == 1);
129 ASSERT (incompletestruct.b[4] == 5);
131 ASSERT (sizeof (incompletestruct) == sizeof (struct y));
132 ASSERT (sizeof (incompletestruct) == offsetof (struct y, b));
133 ASSERT (sizeof (incompletestruct) == offsetof (struct x, b));
134 #endif
136 #if defined (STORAGE_auto)
137 array[4] = 1;
138 #if TEST_G
139 g[1].b = 1;
140 #endif
141 teststruct[0].b[5] = 1;
142 teststruct[4].b[9] = 1;
143 #endif //STORAGE_auto
145 #endif
147 void
148 testZeropad (void)
150 #ifndef __SDCC_pdk14 // Lack of memory
151 Zeropad ();
153 #if defined (STORAGE_auto)
154 Zeropad (); //test reinitialization
155 #endif //STORAGE_auto
156 #endif