Numerous bug fixes in PIC Port (pointers, shifting, bank selection,...)
[fw/sdcc] / src / regression / compare5.c
1 //
2 // compare5.c
3 // regression testing program for comparing longs
4 //
5
6 #define  COMPARE_OUT_OF_RANGE 1
7
8 unsigned char success = 0;
9 unsigned char failures = 0;
10 unsigned char dummy = 0;
11
12 bit bit0 = 0;
13 int int0 = 0;
14 int int1 = 0;
15 char char0 = 0;
16 char char1 = 0;
17 long long0 = 0;
18 long long1 = 0;
19 unsigned long ulong0 = 0;
20 unsigned long ulong1 = 0;
21
22 void
23 done ()
24 {
25
26   dummy++;
27
28 }
29
30 // compare to 0
31 // assumes
32 // long0 == 0
33 // ulong0 == 0
34
35 void c_0(void)
36 {
37
38   if(long0 != 0)
39     failures++;
40
41   if(long0 > 0)
42     failures++;
43
44   if(ulong0 != 0)
45     failures++;
46
47   if(ulong0 > 0)
48     failures++;
49
50 }
51
52 // compare to 1
53 // assumes
54 // long1 == 1
55 // ulong1 == 1
56
57 void c_1(void)
58 {
59
60   if(long0 == 1)
61     failures++;
62
63   if(long1 != 1)
64     failures++;
65
66   if(ulong0 == 1)
67     failures++;
68
69   if(ulong1 != 1)
70     failures++;
71
72   if(long1 < 0)
73     failures++;
74
75   if(long1 < 1)
76     failures++;
77
78   if(ulong1 < 1)
79     failures++;
80
81   if(long1 > 1)
82     failures++;
83
84   if(ulong1 > 1)
85     failures++;
86 }
87
88 // compare to 2
89 // assumes
90 // long0 == 2
91 // ulong0  == 2
92
93 void c_2(void)
94 {
95
96   if(long0 != 2)
97     failures++;
98
99   if(ulong0 != 2)
100     failures++;
101
102   if(long1 == 2)
103     failures++;
104
105   if(ulong1 == 2)
106     failures++;
107
108 }
109
110 // compare to 0xff
111 // assumes
112 // achar0 == 0xff
113 // aint0  == 0xff
114
115 void c_ff(void)
116 {
117
118   if(long0 != 0xff)
119     failures++;
120
121   if(ulong0 != 0xff)
122     failures++;
123
124   if(long1 == 0xff)
125     failures++;
126
127   if(ulong1 == 0xff)
128     failures++;
129
130
131 }
132
133 // compare to 0x200
134 // assumes
135 // achar0 == 0x200
136 // aint0  == 0x200
137
138 void c_200(void)
139 {
140
141   if(long0 != 0x200)
142     failures++;
143
144   if(ulong0 != 0x200)
145     failures++;
146
147   if(long1 == 0x200)
148     failures++;
149
150   if(ulong1 == 0x200)
151     failures++;
152
153
154 }
155
156 // compare to 0x20000
157 // assumes
158 // long0  == 0x20000
159 // ulong0 == 0x20000
160 // long1  != 0x20000
161 // ulong1 != 0x20000
162
163 void c_20000(void)
164 {
165
166   if(long0 != 0x20000)
167     failures++;
168
169   if(ulong0 != 0x20000)
170     failures++;
171
172   if(long1 == 0x20000)
173     failures++;
174
175   if(ulong1 == 0x20000)
176     failures++;
177
178   if(long0 <= 0x10000)
179     failures++;
180
181   if(long0 < 0x10000)
182     failures++;
183
184 /*  if(long0 < 0x12345)
185     failures++;
186 */
187   if(long0 == 0)
188     failures++;
189 }
190
191 // compare to 0x00a5
192 // assumes
193 // char0  == 0xa5
194 // int0  == 0x00a5
195
196 void c_a5(void)
197 {
198
199   if(char0 != 0xa5)
200     failures++;
201
202   if(int0 != 0xa5)
203     failures++;
204
205   if(int0 == 0xa4)
206     failures++;
207
208   if(int0 == 0xa500)
209     failures++;
210
211 }
212
213 // compare to 0xa500
214 // assumes
215 // char0  == 0xa5
216 // int0  == 0xa500
217
218 void c_a500(void)
219 {
220
221 #ifdef COMPARE_OUT_OF_RANGE
222   if(char0 == 0xa500)
223     failures++;
224 #endif
225
226   if(int0 != 0xa500)
227     failures++;
228
229   if(int0 == 0xa400)
230     failures++;
231
232   if(int0 == 0x00a5)
233     failures++;
234
235 }
236
237 // compare to 0xabcd
238 // assumes
239 // char0  == 0xa5
240 // int0  == 0xabcd
241
242 void c_abcd(void)
243 {
244 #ifdef COMPARE_OUT_OF_RANGE
245   if(char0 == 0xabcd)
246     failures++;
247 #endif
248
249   if(int0 != 0xabcd)
250     failures++;
251
252   if(int0 == 0xab00)
253     failures++;
254
255   if(int0 == 0x00cd)
256     failures++;
257
258   if(int0 == 0x05cd)
259     failures++;
260
261   if(int0 == 0xab05)
262     failures++;
263
264   if(int0 == 0xab01)
265     failures++;
266
267   if(int0 == 0x01cd)
268     failures++;
269
270   if(int0 > 0)
271     failures++;
272
273 #ifdef COMPARE_OUT_OF_RANGE
274   if(int0 == 0x1234abcd)
275     failures++;
276 #endif
277
278 }
279
280 // assumes char1 == 0
281 void c_ifelse1(void)
282 {
283
284   if(char0)
285     char0 = char1;
286   else
287     char0 = 0;
288
289   if(char0)
290     failures++;
291 }
292
293 // assumes char0 = -1
294 // assumes int0 = -1
295
296 void c_minus1(void)
297 {
298   if(long0 != -1)
299     failures++;
300
301   if(long0 > 0)
302     failures++;
303
304   if(long1 < 0)
305     failures++;
306 /*
307   if(long1 < 2)
308     failures++;
309 */
310 }
311
312 // assumes
313 // long0 = long1 = ulong0 = ulong1 == 0
314
315 void c_long2long_eq(void)
316 {
317
318   if(long0 != long1)
319     failures++;
320
321   if(ulong0 != ulong1)
322     failures++;
323
324   if(long0 != ulong1)
325     failures++;
326
327   if(long0 > long1)
328     failures++;
329
330   if(long0 < long1)
331     failures++;
332
333   if(long0 > ulong0)
334     failures++;
335
336   if(long0 < ulong0)
337     failures++;
338 }
339
340 // assumes
341 // long0 = ulong0 == 0
342 // long1 = ulong1 == 1
343
344 void c_long2long_neq(void)
345 {
346
347   if(long0 == long1)
348     failures++;
349
350   if(ulong0 == ulong1)
351     failures++;
352
353   if(long1 != ulong1)
354     failures++;
355
356   if(long1 < long0)
357     failures++;
358
359   if(long1 <= long0)
360     failures++;
361
362   if(ulong1 < ulong0)
363     failures++;
364
365   if(ulong1 <= ulong0)
366     failures++;
367
368 }
369
370
371 //  long0=-100;
372 //  long1=-1000;
373 void
374 c_long2neglit(void)
375 {
376
377   if(long0>0)
378     failures++;
379   if(long1>0)
380     failures++;
381
382   if(long1 > long0)
383     failures++;
384
385   if(long1 > 100)
386     failures++;
387
388   if(long0 > -50)
389     failures++;
390
391   if(long1 < -5000)
392     failures++;
393 }
394
395 void
396 main (void)
397 {
398
399   c_0();
400
401   c_long2long_eq();
402
403   long1 = 1;
404   ulong1 = 1;
405   c_1();
406   c_long2long_neq();
407
408   long0 = 2;
409   ulong0 = 2;
410   c_2();
411
412   long0 = 0xff;
413   ulong0 = 0xff;
414   c_ff();
415
416   long0 = 0x200;
417   ulong0 = 0x200;
418   c_200();
419
420   long0 = 0x20000;
421   ulong0 = 0x20000;
422   c_20000();
423
424   long0 = -1;
425   c_minus1();
426
427   long0=-100;
428   long1=-1000;
429   c_long2neglit();
430
431   success = failures;
432   done ();
433 }