struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / scott-sub.c
blobc48d5704c61840bc43f30d6fbdab938d302d6a4f
1 /*
2 Addition tests
3 */
4 #include <testfwk.h>
6 /* bit types are not ANSI - so provide a way of disabling bit types
7 * if this file is used to test other compilers besides SDCC */
8 #define SUPPORT_BIT_TYPES 0
10 /* Some compilers that support bit types do not support bit arithmetic
11 * (like bitx = bity + bitz;) */
12 #define SUPPORT_BIT_ARITHMETIC 0
14 #if SUPPORT_BIT_TYPES
16 bit bit0 = 0;
17 bit bit1 = 0;
18 bit bit2 = 0;
19 bit bit3 = 0;
20 bit bit4 = 0;
21 bit bit5 = 0;
22 bit bit6 = 0;
23 bit bit7 = 0;
24 bit bit8 = 0;
25 bit bit9 = 0;
26 bit bit10 = 0;
27 bit bit11 = 0;
29 #endif
31 unsigned int aint0 = 0;
32 unsigned int aint1 = 0;
33 unsigned char achar0 = 0;
34 unsigned char achar1 = 0;
35 unsigned char achar2 = 0;
36 unsigned char achar3 = 0;
37 unsigned char *acharP = 0;
39 void sub_lit_from_uchar(void)
42 achar0 = achar0 - 5;
44 ASSERT(!(achar0 != 0xfb));
46 achar0 -= 10;
48 ASSERT(!(achar0 != 0xf1));
50 achar0 = achar0 -1; // Should be a decrement
51 ASSERT(!(achar0 != 0xf0));
53 for(achar1 = 0; achar1 < 100; achar1++)
54 achar0 -= 2;
56 ASSERT(!(achar0 != 40));
60 // achar0 = 1
61 // achar1 = 100
63 void sub_uchar2uchar(void)
66 achar1 = achar1 - achar0;
68 ASSERT(!(achar1 != 99));
70 for(achar2 = 0; achar2<7; achar2++)
71 achar1 -= achar0;
73 ASSERT(!(achar1 != 92));
77 // assumes
78 // achar0 = 10
79 // achar1 = 32
80 // achar2, achar3 can be anything.
82 void sub_uchar2uchar2(void)
86 achar0--;
87 achar0 = achar0 - 1;
88 achar0 = achar0 - 2;
89 achar0 = achar0 - 3;
90 ASSERT(!(achar0 != 3));
93 achar1 -= achar0;
94 ASSERT(!(achar1 != 29));
96 achar2 = achar1 - achar0;
97 ASSERT(!(achar2 != 26));
100 achar3 = achar2 - achar1 - achar0;
101 ASSERT(!(achar3 != 0xfa));
105 // sub_bits
106 // all bit variables are 0 upon entry.
108 #if SUPPORT_BIT_TYPES
109 void sub_bits(void)
112 bit1 = bit0;
114 bit0 = 1;
116 ASSERT(!(bit1 != 0));
118 bit1 = bit0-bit1; // 1 - 0 => 1
119 ASSERT(!(bit1 != 1));
121 #if SUPPORT_BIT_ARITHMETIC
122 bit2 = bit1-bit0; // 1 - 1 => 0
123 ASSERT(!(bit2));
125 bit7 = bit4-bit5;
126 bit6 = bit4+bit5;
127 bit3 = bit4-bit5-bit6-bit7-bit0; // 0-0-0-0-1 => 1
128 ASSERT(!(!bit3));
129 #endif
132 /* sub_bit2uchar(void) - assumes bit0 = 1, achar0 = 7 */
134 void sub_bit2uchar(void)
137 achar0 -= bit0;
139 ASSERT(!(achar0 != 6));
141 ASSERT(!(achar0 == bit0));
145 void sub_bit2uint(void)
148 ASSERT(!(aint0 != bit11));
150 aint0 -= bit0;
151 ASSERT(!(aint0!=0xffff));
154 #endif
156 void
157 testSub(void)
160 sub_lit_from_uchar();
162 achar0=1;
163 achar1=100;
164 sub_uchar2uchar();
167 achar0 = 10;
168 achar1 = 32;
169 sub_uchar2uchar2();
171 #if SUPPORT_BIT_TYPES
172 sub_bits();
174 achar0 = 7;
175 bit0 = 1;
176 sub_bit2uchar();
177 sub_bit2uint();
178 #endif