]> git.sur5r.net Git - cc65/blob - test/val/or1.c
Merge pull request #849 from polluks/patch-4
[cc65] / test / val / or1.c
1 /*
2   !!DESCRIPTION!!
3   !!ORIGIN!!      SDCC regression tests
4   !!LICENCE!!     GPL, read COPYING.GPL
5 */
6
7 #include <stdio.h>
8 #include <limits.h>
9
10 unsigned char success=0;
11 unsigned char failures=0;
12 unsigned char dummy=0;
13
14 #if SUPPORT_BIT_TYPES
15 bit bit0 = 0;
16 bit bit1 = 0;
17 bit bit2 = 0;
18 #endif
19
20 unsigned int uint0 = 0;
21 unsigned int uint1 = 0;
22 unsigned char uchar0 = 0;
23 unsigned char uchar1 = 0;
24 unsigned long ulong0 = 0;
25 unsigned long ulong1 = 0;
26
27 void done()
28 {
29   dummy++;
30 }
31
32 /* uchar0 = 0; */
33 void or_lit2uchar(void)
34 {
35   if(uchar0)
36     failures++;
37
38   uchar0 |= 1;
39
40   if(uchar0 != 1)
41     failures++;
42
43   uchar0 |= 2;
44
45   if(uchar0 != 3)
46     failures++;
47
48   uchar0 |= 0x0e;
49
50   if(uchar0 != 0x0f)
51     failures++;
52 }
53
54 void or_lit2uint(void)
55 {
56   if(uint0)
57     failures++;
58
59   uint0 |= 1;
60   if(uint0 != 1) 
61     failures++;
62
63   uint0 |= 2;
64   if(uint0 != 3) 
65     failures++;
66
67   uint0 |= 0x100;
68   if(uint0 != 0x103) 
69     failures++;
70
71   uint0 |= 0x102;
72   if(uint0 != 0x103) 
73     failures++;
74
75   uint0 |= 0x303;
76   if(uint0 != 0x303) 
77     failures++;
78 }
79
80 void or_lit2ulong(void)
81 {
82   if(ulong0)
83     failures++;
84
85   ulong0 |= 1;
86   if(ulong0 != 1) 
87     failures++;
88
89   ulong0 |= 2;
90   if(ulong0 != 3) 
91     failures++;
92
93   ulong0 |= 0x100;
94   if(ulong0 != 0x103) 
95     failures++;
96
97   ulong0 |= 0x102;
98   if(ulong0 != 0x103) 
99     failures++;
100
101   ulong0 |= 0x303;
102   if(ulong0 != 0x303) 
103     failures++;
104
105   ulong0 |= 0x80000000;
106   if(ulong0 != 0x80000303) 
107     failures++;
108 }
109
110 /*-----------*/
111 void or_uchar2uchar(void)
112 {
113   uchar0 |= uchar1;
114
115   if(uchar0 != 1)
116     failures++;
117
118   uchar1 |= 0x0f;
119
120   uchar0 = uchar1 | 0x10;
121
122   if(uchar0 != 0x1f)
123     failures++;
124 }
125
126 void or_uint2uint(void)
127 {
128   uint0 |= uint1;
129
130   if(uint0 != 1)
131     failures++;
132
133   uint1 |= 0x0f;
134
135   uint0 = uint1 | 0x10;
136
137   if(uint0 != 0x1f)
138     failures++;
139 }
140
141 #if SUPPORT_BIT_TYPES
142
143 void or_bits1(void)
144 {
145   bit0 = bit0 | bit1 | bit2;
146 }
147
148 void or_bits2(void)
149 {
150   bit0 = bit1 | bit2;
151 }
152 #endif
153
154 int  main(void)
155 {
156   or_lit2uchar();
157   or_lit2uint();
158   or_lit2ulong();
159
160   uchar0=0;
161   uchar1=1;
162   or_uchar2uchar();
163
164   uint0=0;
165   uint1=1;
166   or_uint2uint();
167
168 #if SUPPORT_BIT_TYPES
169   or_bits1();
170   if(bit0)
171     failures++;
172
173   or_bits2();
174   if(bit0)
175     failures++;
176
177   bit1=1;
178   or_bits1();
179   if(!bit0)
180     failures++;
181
182   or_bits2();
183   if(!bit0)
184     failures++;
185 #endif
186
187   success = failures;
188   done();
189   printf("failures: %d\n",failures);
190
191   return failures;
192 }