* src/ds390/gen.c (pushSide): fixed 'too few arguments'
[fw/sdcc] / support / regression / tests / staticinit.c
1 /** Tests that the static initialiser code works.
2     As the init code is now clever we have to be careful.
3
4     type: char, int, long
5 */
6
7 #include <testfwk.h>
8
9 static {type} smallDense[] = {
10     1, 2, 3, 4, 5, 6
11 };
12
13 static void
14 testSmallDense(void)
15 {
16     ASSERT(smallDense[0] == 1);
17     ASSERT(smallDense[1] == 2);
18     ASSERT(smallDense[2] == 3);
19     ASSERT(smallDense[3] == 4);
20     ASSERT(smallDense[4] == 5);
21     ASSERT(smallDense[5] == 6);
22 }
23
24 #ifdef SDCC_mcs51
25 idata at 0xa0   /* leave space for the stack */
26 #endif
27 static {type} smallSparse[] = {
28     1, 1, 1, 1, 1, 1, 1, 1, 1
29 };
30
31 static void
32 testSmallSparse(void)
33 {
34     ASSERT(smallSparse[0] == 1);
35     ASSERT(smallSparse[1] == 1);
36     ASSERT(smallSparse[2] == 1);
37     ASSERT(smallSparse[3] == 1);
38     ASSERT(smallSparse[4] == 1);
39     ASSERT(smallSparse[5] == 1);
40     ASSERT(smallSparse[6] == 1);
41     ASSERT(smallSparse[7] == 1);
42     ASSERT(smallSparse[8] == 1);
43 }
44
45 #ifdef SDCC_mcs51
46 idata at 0xd0
47 #endif
48 static {type} smallSparseZero[] = {
49     0, 0, 0, 0, 0, 0, 0, 0, 0
50 };
51
52 static {type} smallSparseZeroTail[] = {
53     1, 2, 3
54 };
55
56 static void
57 testSmallSparseZero(void)
58 {
59     ASSERT(smallSparseZero[0] == 0);
60     ASSERT(smallSparseZero[1] == 0);
61     ASSERT(smallSparseZero[2] == 0);
62     ASSERT(smallSparseZero[3] == 0);
63     ASSERT(smallSparseZero[4] == 0);
64     ASSERT(smallSparseZero[5] == 0);
65     ASSERT(smallSparseZero[6] == 0);
66     ASSERT(smallSparseZero[7] == 0);
67     ASSERT(smallSparseZero[8] == 0);
68
69     // Make the compiler happy
70     ASSERT(smallSparseZeroTail[0] == 1);
71 }
72
73 #ifdef SDCC_mcs51
74 xdata
75 #elif SDCC_pic16
76 code
77 #endif
78 static {type} largeMixed[] = {
79     1, 2, 3, 4, 5, 6, 7,        /* 0-6 */
80     1, 1, 1, 1, 1, 1, 1, 1,
81     1, 1, 1, 1, 1, 1, 1, 1,
82     1, 1, 1, 1, 1, 1, 1, 1,
83     1, 1, 1, 1, 1, 1, 1, 1,
84     1, 1, 1, 1, 1, 1, 1, 1,
85     1, 1, 1, 1, 1, 1, 1, 1,
86     1, 1, 1, 1, 1, 1, 1, 1,
87     1, 1, 1, 1, 1, 1, 1, 1,
88     1, 1, 1, 1, 1, 1, 1, 1,
89     1, 1, 1, 1, 1, 1, 1, 1,
90     1, 1, 1, 1, 1, 1, 1, 1,
91     1, 1, 1, 1, 1, 1, 1, 1,
92     1, 1, 1, 1, 1, 1, 1, 1,
93     1, 1, 1, 1, 1, 1, 1, 1,     /* 8*12 = 96+7 = -102 */
94     1, 1, 1, 1, 1, 1, 1, 1,
95     1, 1, 1, 1, 1, 1, 1, 1,
96     1, 1, 1, 1, 1, 1, 1, 1,
97     3, 4, 5, 6, 3, 4, 5, 6,     /* 8*17 = 136+7 */
98     3, 4, 5, 6, 3, 4, 5, 6,
99     3, 4, 5, 6, 3, 4, 5, 6,
100     3, 4, 5, 6, 3, 4, 5, 6,
101     3, 4, 5, 6, 3, 4, 5, 6,
102     3, 4, 5, 6, 3, 4, 5, 6,
103     3, 4, 5, 6, 3, 4, 5, 6,
104     3, 4, 5, 6, 3, 4, 5, 6,
105     3, 4, 5, 6, 3, 4, 5, 6,
106     3, 4, 5, 6, 3, 4, 5, 6,
107     3, 4, 5, 6, 3, 4, 5, 6,
108     3, 4, 5, 6, 3, 4, 5, 6,
109     3, 4, 5, 6, 3, 4, 5, 6,
110     3, 4, 5, 6, 3, 4, 5, 6,
111     3, 4, 5, 6, 3, 4, 5, 6,
112     3, 4, 5, 6, 3, 4, 5, 6,
113     3, 4, 5, 6, 3, 4, 5, 6
114 };
115
116 static void
117 testLargeMixed(void)
118 {
119     ASSERT(largeMixed[0] == 1);
120     ASSERT(largeMixed[1] == 2);
121     ASSERT(largeMixed[7] == 1);
122     ASSERT(largeMixed[102] == 1);
123     ASSERT(largeMixed[143] == 3);
124     ASSERT(largeMixed[143+8] == 3);
125     ASSERT(largeMixed[143+16] == 3);
126     ASSERT(largeMixed[143+1] == 4);
127     ASSERT(largeMixed[143+8+1] == 4);
128     ASSERT(largeMixed[143+16+1] == 4);
129 }