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