]> git.sur5r.net Git - cc65/blob - test/val/add2.c
Adjustments in response to latest comments
[cc65] / test / val / add2.c
1 /*
2   !!DESCRIPTION!! Addition tests - mostly int's
3   !!ORIGIN!!      SDCC regression tests
4   !!LICENCE!!     GPL, read COPYING.GPL
5 */
6
7 #include <stdio.h>
8 #include <limits.h>
9
10 unsigned char success=0;
11 unsigned char failures=0;
12 unsigned char dummy=0;
13
14 #ifdef SIZEOF_INT_16BIT
15 #if defined(__LINUX__) || defined(LINUX)
16 unsigned short aint0 = 0;
17 unsigned short aint1 = 0;
18 unsigned short aint2 = 0;
19 unsigned short aint3 = 0;
20
21 #else
22 unsigned int aint0 = 0;
23 unsigned int aint1 = 0;
24 unsigned int aint2 = 0;
25 unsigned int aint3 = 0;
26
27 #endif
28
29 #else
30 unsigned int aint0 = 0;
31 unsigned int aint1 = 0;
32 unsigned int aint2 = 0;
33 unsigned int aint3 = 0;
34
35 #endif
36
37 unsigned char achar0 = 0;
38 unsigned char achar1 = 0;
39 unsigned char achar2 = 0;
40 unsigned char achar3 = 0;
41 unsigned char *acharP = 0;
42
43 #ifdef SUPPORT_BIT_TYPES
44
45 bit bit0 = 0;
46 bit bit1 = 0;
47 bit bit2 = 0;
48 bit bit3 = 0;
49 bit bit4 = 0;
50 bit bit5 = 0;
51 bit bit6 = 0;
52 bit bit7 = 0;
53 bit bit8 = 0;
54 bit bit9 = 0;
55 bit bit10 = 0;
56 bit bit11 = 0;
57
58 #endif
59
60 void done()
61 {
62   dummy++;
63 }
64
65 void add_lit2uint(void)
66 {
67   aint0 = aint0 + 5;
68
69   if(aint0 != 5)
70     failures++;
71
72   aint0 += 10;
73
74   if(aint0 != 15)
75     failures++;
76
77   aint0 = aint0 +1;  /* Should be an increment */
78   if(aint0 != 16)
79     failures++;
80
81   for(aint1 = 0; aint1 < 100; aint1++)
82     aint0 += 2;
83
84   if(aint0 != 216)
85     failures++;
86 }
87
88 void add_uint2uint (void)
89 {
90   aint1 = aint1 + aint0;
91
92   if(aint1 != 16)
93     failures++;
94
95   for(aint2 = 0; aint2<7; aint2++)
96     aint1 += aint0;
97
98   if(aint1 != 128)
99     failures++;
100 }
101
102 /* assumes
103   aint0 = 0
104   aint1 = 32
105   aint2, aint3 can be anything.
106 */
107 void add_uint2uint2(void)
108 {
109   aint0++;
110   aint0 = aint0 + 1;
111   aint0 = aint0 + 2;
112   aint0 = aint0 + 3;
113   if(aint0 != 7)
114     failures++;
115
116   aint1 += aint0;
117   if(aint1 != 0x27)
118     failures++;
119
120   aint2 = aint1 + aint0;
121   if(aint2 != 0x2e)
122     failures++;
123
124   aint3 = aint2 + aint1 + aint0;
125   if(aint3 != 0x5c)
126     failures++;
127
128   aint3 += 0xa0;
129   if(aint3 != 0xfc)
130     failures++;
131
132   aint3 += aint0;
133   if(aint3 != 0x103)
134     failures++;
135
136   aint1 += 0xffc0;
137   if(aint1 != 0xffe7)
138     failures++;
139
140   aint3 = aint2 + aint1 + aint0;
141   if(aint3 != 0x1c)
142     failures++;
143 }
144
145 #ifdef SUPPORT_BIT_TYPES
146 void add_bits(void)
147 {
148   bit1 = bit0;
149
150   bit0 = 1;
151
152   if(bit1 != 0)
153     failures++;
154
155   bit1 = bit1+bit0;
156   if(bit1 != 1)
157     failures++;
158
159   bit2 = bit1+bit3;
160   if(!bit2)
161     failures++;
162
163   bit3 = bit4+bit5+bit6+bit7+bit0;
164   if(!bit3)
165     failures++;
166 }
167
168 /* add_bit2uchar(void) - assumes bit0 = 1, aint0 = 7  */
169
170 void add_bit2uchar(void)
171 {
172   achar0 += bit0;
173
174   if(achar0 != 8)
175     failures++;
176
177   if(achar0 == bit0)
178     failures++;
179 }
180
181 void add_bit2uint(void)
182 {
183   if(aint0 != bit11)
184     failures++;
185
186   aint0 += bit0;
187   if(aint0!=1)
188     failures++;
189 }
190 #endif
191
192 /***********************************/
193
194 void addlits(void)
195 {
196   aint0 += 0x0001;
197
198   if(aint0 != 1)
199     failures++;
200
201   aint0 += 0x00;
202
203   if(aint0 != 1)
204     failures++;
205
206   aint0 += 0x00fe;
207   if(aint0 != 0x00ff)
208     failures++;
209
210   aint0 += 0x0001;
211
212   if(aint0 != 0x0100)
213     failures++;
214
215   aint0++;
216   if(aint0 != 0x0101)
217     failures++;
218
219   aint0 += 0x00ff;
220   if(aint0 != 0x0200)
221     failures++;
222
223   aint0 += 0x00a0;
224   if(aint0 != 0x02a0)
225     failures++;
226
227   aint0 += 0x0061;
228   if(aint0 != 0x0301)
229     failures++;
230
231   aint0 += 0x0100;
232   if(aint0 != 0x0401)
233     failures++;
234
235   aint0 += 0x0101;
236   if(aint0 != 0x0502)
237     failures++;
238
239   aint0 += 0x00fd;
240   if(aint0 != 0x05ff)
241     failures++;
242
243   aint0 += 0x0101;
244   if(aint0 != 0x0700)
245     failures++;
246
247   aint0 += 0x01ff;
248   if(aint0 != 0x08ff)
249     failures++;
250
251   aint0 += 0x01ff;
252   if(aint0 != 0x0afe)
253     failures++;
254
255   aint0 += 0xff02;
256   if(aint0 != 0x0a00)
257     failures++;
258
259   aint0 += 0xffff;
260   if(aint0 != 0x09ff)
261     failures++;
262
263   aint0 += 0xff01;
264   if(aint0 != 0x0900)
265     failures++;
266
267   aint0 += 0xff00;
268   if(aint0 != 0x0800)
269     failures++;
270
271   aint0 += 0xff01;
272   if(aint0 != 0x0701)
273     failures++;
274
275   aint0 += 0x0300;
276   if(aint0 != 0x0a01)
277     failures++;
278
279   aint0 += 0x03ff;
280   if(aint0 != 0x0e00)
281     failures++;
282
283   aint0 += 0x0301;
284   if(aint0 != 0x1101)
285     failures++;
286
287   aint0 += 0x03fe;
288   if(aint0 != 0x14ff)
289     failures++;
290
291   aint0 += 0x0301;
292   if(aint0 != 0x1800)
293     failures++;
294 }
295
296 int main(void)
297 {
298   add_lit2uint();
299
300   aint0=16;
301   aint1=0;
302   add_uint2uint();
303
304   aint0 = 0;
305   aint1 = 32;
306   aint2 = 0;
307   add_uint2uint2();
308
309 #ifdef SUPPORT_BIT_TYPES
310   add_bits();
311
312   achar0 = 7;
313   add_bit2uchar();
314
315   aint0 = 0;
316   bit0 = 1;
317   add_bit2uint();
318 #endif
319
320   aint0 = 0;
321   addlits();
322
323   success = failures;
324   done();
325   printf("failures: %d\n",failures);
326
327   return failures;
328 }