* src/hc08/gen.c (loadRegFromAop): better use of clra & clrx
[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   //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 xdata
26 # define code
27 #endif
28 #if defined(SDCC_hc08)
29 # define idata
30 #endif
31
32 const char *string1 = "\x00\x01";
33 const char string2[] = "\x00\x01";
34
35 #ifndef PORT_HOST
36 #pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS)
37 //array will be truncated but warning will be suppressed
38 //if truncation is incorrect, other ASSERTs will fail with high probability
39 char STORAGE trunc[2] = {'a', 'b', 'c'};
40 #endif
41
42 char STORAGE array[5] = {'a', 'b', 'c'};
43
44 #if TEST_G
45   struct w {
46     char a;
47     int  b;
48   } STORAGE g[3] = {
49     {'x', 1},
50     {'y'},
51     {'z', 3}
52   };
53 #endif
54
55 struct x {
56   short a;
57   char  b[10];
58 };
59
60 struct x STORAGE teststruct[5] = {
61   { 10, {  1, 2, 3, 4, 5} },
62   { 20, { 11 } },
63   { 30, {  6, 7, 8} }
64 };
65
66 #if FLEXARRAY
67   struct y {
68     short a;
69     char  b[];
70   };
71
72 struct y STORAGE incompletestruct = {
73   10, {1, 2, 3, 4, 5}
74 };
75 #endif
76
77 void
78 testZeropad(void)
79 {
80   ASSERT(string1[1] == '\x01');
81   ASSERT(string2[1] == '\x01');
82
83   ASSERT(array[2] == 'c');
84   ASSERT(array[4] == 0);
85
86 #if TEST_G
87   ASSERT(g[1].a == 'y');
88   ASSERT(g[1].b == 0);
89   ASSERT(g[2].a == 'z');
90   ASSERT(g[2].b == 3);
91 #endif
92
93   ASSERT(teststruct[0].b[1] ==  2);
94   ASSERT(teststruct[0].b[5] ==  0);
95   ASSERT(teststruct[1].b[0] == 11);
96   ASSERT(teststruct[4].b[9] ==  0);
97
98   ASSERT(sizeof(teststruct[2].a) ==  2);
99   ASSERT(sizeof(teststruct[1].b) == 10);
100   ASSERT(sizeof(teststruct[1])   == 12);
101   ASSERT(sizeof(teststruct)      == 60);
102
103 #if FLEXARRAY
104   ASSERT(incompletestruct.a    == 10);
105   ASSERT(incompletestruct.b[0] ==  1);
106   ASSERT(incompletestruct.b[4] ==  5);
107
108   ASSERT(sizeof(incompletestruct) == sizeof(struct y));
109   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
110   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
111 #endif
112 }