* as/mcs51/lkarea.c: removed old K&R style,
[fw/sdcc] / support / regression / tests / zeropad.c
1 /** Zeropad tests.
2
3     storage: idata, pdata, xdata, code,
4 */
5 #ifndef STORAGE
6 #define STORAGE {storage}
7 #endif
8
9 #if defined __GNUC__
10   #define FLEXARRAY (__GNUC__ >= 3)
11   //since g fails on GCC 2.95.4 on alpha and I don't know how to detect alpha...
12   #define TEST_G    (__GNUC__ >= 3)
13 #else
14   #define FLEXARRAY 1
15   #define TEST_G    1
16 #endif
17
18 #include <testfwk.h>
19
20 typedef unsigned int size_t;
21 #define offsetof(s,m)   (size_t)&(((s *)0)->m)
22
23 #if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
24 # define idata
25 # define pdata
26 # define xdata
27 # define code
28 #endif
29
30 #if defined(SDCC_hc08)
31 # define idata data
32 # define pdata data
33 #endif
34
35 const char *string1 = "\x00\x01";
36 const char string2[] = "\x00\x01";
37
38 #ifndef PORT_HOST
39 #pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS)
40 //array will be truncated but warning will be suppressed
41 //if truncation is incorrect, other ASSERTs will fail with high probability
42 char STORAGE trunc[2] = {'a', 'b', 'c'};
43 #endif
44
45 char STORAGE array[5] = {'a', 'b', 'c'};
46
47 #if TEST_G
48   struct w {
49     char a;
50     int  b;
51   } STORAGE g[3] = {
52     {'x', 1},
53     {'y'},
54     {'z', 3}
55   };
56 #endif
57
58 struct x {
59   short a;
60   char  b[10];
61 };
62
63 struct x STORAGE teststruct[5] = {
64   { 10, {  1, 2, 3, 4, 5} },
65   { 20, { 11 } },
66   { 30, {  6, 7, 8} }
67 };
68
69 #if FLEXARRAY
70   struct y {
71     short a;
72     char  b[];
73   };
74
75 struct y STORAGE incompletestruct = {
76   10, {1, 2, 3, 4, 5}
77 };
78 #endif
79
80 void
81 testZeropad(void)
82 {
83   ASSERT(string1[1] == '\x01');
84   ASSERT(string2[1] == '\x01');
85
86   ASSERT(array[2] == 'c');
87   ASSERT(array[4] == 0);
88
89 #if TEST_G
90   ASSERT(g[1].a == 'y');
91   ASSERT(g[1].b == 0);
92   ASSERT(g[2].a == 'z');
93   ASSERT(g[2].b == 3);
94 #endif
95
96   ASSERT(teststruct[0].b[1] ==  2);
97   ASSERT(teststruct[0].b[5] ==  0);
98   ASSERT(teststruct[1].b[0] == 11);
99   ASSERT(teststruct[4].b[9] ==  0);
100
101   ASSERT(sizeof(teststruct[2].a) ==  2);
102   ASSERT(sizeof(teststruct[1].b) == 10);
103   ASSERT(sizeof(teststruct[1])   == 12);
104   ASSERT(sizeof(teststruct)      == 60);
105
106 #if FLEXARRAY
107   ASSERT(incompletestruct.a    == 10);
108   ASSERT(incompletestruct.b[0] ==  1);
109   ASSERT(incompletestruct.b[4] ==  5);
110
111   ASSERT(sizeof(incompletestruct) == sizeof(struct y));
112   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
113   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
114 #endif
115 }