1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 00:07:21 +00:00
cc65/test/ref/switch2.c
Jesse Rosenstock 18246278c5 switch2.c: Remove use of REFCC and UNSIGNED_CHARS
Explicitly use `signed char` or `unsigned char`, rather than
```

signed char k;
char k;

signed char k;
char k;
```
This should have resulted in the same thing; however, note that
`REFCC` was never defined, and `common.h` was not included, so
the old code in fact tested `char` then `unsigned char`,
which are the same.

The only difference is that a switch using plain `char` is not
tested, but since this is the same as either `signed char` or
`unsigned char`, the lack of test coverage seems relatively safe.
2020-06-25 13:18:08 +02:00

231 lines
6.5 KiB
C

/*
!!DESCRIPTION!! switch test
!!ORIGIN!!
!!LICENCE!! public domain
*/
/*#define STANDALONE*/
#include <stdio.h>
void testlimits(int i) {
printf("%d:",i);
switch(i) {
case -1: /* works */
/* case 0xffff: */ /* 'range error' (-1) */
printf("-1\n");
break;
/* max int */
/* case 0x7fff: */ /* works */
case 32767: /* works */
/* case 32768: */ /* 'range error' (correct for that one!) */
printf("max\n");
break;
/* min int */
case -32768: /* 'warning. constant is long' */
/* case 0x8000: */ /* 'range error' */
/* case -32769: */ /* 'range error' (correct for that one!) */
printf("min\n");
break;
}
printf("\n");
}
void testdefault1(unsigned char i) {
signed char k;
for(;i<254;) {
k = i;
printf(">%d\n",i);i++;
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 17:
break;
/* triggers bug ? */
/* gcc warning: case label value exceeds maximum value for type */
/* cc65 error: range error */
/*
case 170:
break;
*/
case 18:
break;
case 19:
break;
case 20:
break;
case 21:
break;
case 22:
break;
case 23:
break;
case 24:
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
case 6:
case 7:
break;
case 8:
case 9:
break;
}
break;
case 100:
break;
default:
printf(">>>default\n");
/* triggers bug if this break; is missing? */
/* break; */
}
}
}
void testdefault2(unsigned char i) {
unsigned char k;
for(;i<254;) {
k = i;
printf(">%d\n",i);i++;
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 17:
break;
/* triggers bug ? */
case 170:
break;
case 18:
break;
case 19:
break;
case 20:
break;
case 21:
break;
case 22:
break;
case 23:
break;
case 24:
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
case 6:
case 7:
break;
case 8:
case 9:
break;
}
break;
case 100:
break;
default:
printf(">>>default\n");
/* triggers bug if this break; is missing? */
/* break; */
}
}
}
int main(void) {
testlimits(32767);
testlimits(-32768);
testlimits(-1);
testdefault1(1);
testdefault1(2);
testdefault1(3);
testdefault1(4);
testdefault2(1);
testdefault2(2);
testdefault2(3);
testdefault2(4);
return 0;
}