* support/regression/tests/zeropad.c: never meant to commit the
[fw/sdcc] / support / regression / tests / zeropad.c
1 /** Zeropad tests.
2
3     storage: idata, xdata, code,
4 */
5 #ifndef STORAGE
6 #define STORAGE {storage}
7 #endif
8
9 #if defined __GNUC__
10   #define FLEXARRAY (__GNUC__ >= 3)
11 #else
12   #define FLEXARRAY 1
13 #endif
14
15 #include <testfwk.h>
16
17 typedef unsigned int size_t;
18 #define offsetof(s,m)   (size_t)&(((s *)0)->m)
19
20 #if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
21 # define idata
22 # define xdata
23 # define code
24 #endif
25
26 char STORAGE array[5] = {'a', 'b', 'c'};
27
28 struct w {
29   char a;
30   int  b;
31 } STORAGE g[3] = {
32   {'x', 1},
33   {'y'},
34   {'z', 3}
35 };
36
37 struct x {
38   short a;
39   char  b[10];
40 };
41
42 struct x STORAGE teststruct[5] = {
43   { 10, {  1, 2, 3, 4, 5} },
44   { 20, { 11 } },
45   { 30, {  6, 7, 8} }
46 };
47
48 #if FLEXARRAY
49   struct y {
50     short a;
51     char  b[];
52   };
53
54 struct y STORAGE incompletestruct = {
55   10, {1, 2, 3, 4, 5}
56 };
57 #endif
58
59 void
60 testZeropad(void)
61 {
62   ASSERT(array[2] == 'c');
63   ASSERT(array[4] == 0);
64
65   ASSERT(g[1].a == 'y');
66   ASSERT(g[1].b == 0);
67   ASSERT(g[2].a == 'z');
68   ASSERT(g[2].b == 3);
69
70   ASSERT(teststruct[0].b[1] ==  2);
71   ASSERT(teststruct[0].b[5] ==  0);
72   ASSERT(teststruct[1].b[0] == 11);
73   ASSERT(teststruct[4].b[9] ==  0);
74
75   ASSERT(sizeof(teststruct[2].a) ==  2);
76   ASSERT(sizeof(teststruct[1].b) == 10);
77   ASSERT(sizeof(teststruct[1])   == 12);
78   ASSERT(sizeof(teststruct)      == 60);
79
80 #if FLEXARRAY
81   ASSERT(incompletestruct.a    == 10);
82   ASSERT(incompletestruct.b[0] ==  1);
83   ASSERT(incompletestruct.b[4] ==  5);
84
85   ASSERT(sizeof(incompletestruct) == sizeof(struct y));
86   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
87   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
88 #endif
89 }