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