struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / scott-add.c
blob5fb229b42536da101cf7b88bad09f785296ec1a0
1 /* Addition tests
2 */
3 #include <testfwk.h>
5 /* bit types are not ANSI - so provide a way of disabling bit types
6 * if this file is used to test other compilers besides SDCC */
7 #define SUPPORT_BIT_TYPES 0
9 /* Some compilers that support bit types do not support bit arithmetic
10 * (like bitx = bity + bitz;) */
11 #define SUPPORT_BIT_ARITHMETIC 0
13 #if SUPPORT_BIT_TYPES
15 bit bit0 = 0;
16 bit bit1 = 0;
17 bit bit2 = 0;
18 bit bit3 = 0;
19 bit bit4 = 0;
20 bit bit5 = 0;
21 bit bit6 = 0;
22 bit bit7 = 0;
23 bit bit8 = 0;
24 bit bit9 = 0;
25 bit bit10 = 0;
26 bit bit11 = 0;
28 #endif
30 unsigned int aint0 = 0;
31 unsigned int aint1 = 0;
32 unsigned char achar0 = 0;
33 unsigned char achar1 = 0;
34 unsigned char achar2 = 0;
35 unsigned char achar3 = 0;
36 unsigned char *acharP = 0;
38 void
39 test_add_lit2uchar(void)
41 achar0 = achar0 + 5;
43 ASSERT(achar0 == 5);
45 achar0 += 10;
47 ASSERT(achar0 == 15);
49 achar0 = achar0 +1; // Should be an increment
51 ASSERT(achar0 == 16);
53 for(achar1 = 0; achar1 < 100; achar1++)
54 achar0 += 2;
56 ASSERT(achar0 == 216);
59 void
60 test_add_uchar2uchar_setup(void)
62 achar0=16;
63 achar1=0;
66 void
67 test_add_uchar2uchar(void)
69 achar1 = achar1 + achar0;
71 ASSERT(achar1 == 16);
73 for(achar2 = 0; achar2<7; achar2++)
74 achar1 += achar0;
76 ASSERT(achar1 == 128);
79 // assumes
80 // achar0 = 0
81 // achar1 = 32
82 // achar2, achar3 can be anything.
84 void
85 test_add_uchar2uchar2_setup(void)
87 achar0 = 0;
88 achar1 = 32;
91 void
92 test_add_uchar2uchar2(void)
94 achar0++;
95 achar0 = achar0 + 1;
96 achar0 = achar0 + 2;
97 achar0 = achar0 + 3;
99 ASSERT(achar0 == 7);
101 achar1 += achar0;
102 ASSERT(achar1 == 39);
104 achar2 = achar1 + achar0;
105 ASSERT(achar2 == 46);
107 achar3 = achar2 + achar1 + achar0;
108 ASSERT(achar3 == 92);
112 #if SUPPORT_BIT_TYPES
113 void add_bits(void)
116 bit1 = bit0;
118 bit0 = 1;
120 if(bit1 != 0)
121 failures++;
123 bit1 = bit1+bit0;
124 ASSERT(bit1 == 1);
126 #if SUPPORT_BIT_ARITHMETIC
127 bit2 = bit1+bit3;
128 ASSERT(bit2 != 0);
130 bit3 = bit4+bit5+bit6+bit7+bit0;
131 ASSERT(bit3 == 0);
132 #endif
135 /* add_bit2uchar(void) - assumes bit0 = 1, achar0 = 7 */
137 void
138 disabled_test_add_bit2uchar(void)
140 achar0 += bit0;
142 ASSERT(achar0 == 8);
144 ASSERT(achar0 == bit0);
147 void
148 disabled_test_add_bit2uint(void)
150 ASSERT(aint0 == bit11);
152 aint0 += bit0;
153 ASSERT(aint0 == 1);
155 #endif