struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / compare.c.in
blob6f91f711dd2bc055bf6cadcf349983c039b50eb9
1 /** Test the comparison operators.
3 type: char, int, long
4 storage: static,
5 attr: volatile
6 */
7 #include <testfwk.h>
9 static void
10 testCmpAroundZero(void)
12 {attr} {storage} signed {type} i;
14 i = 5;
16 ASSERT(0 < i);
17 ASSERT(i > 0);
18 ASSERT(0 <= i);
19 ASSERT(i >= 0);
20 #if !defined(__SDCC_pdk14) // Lack of memory
21 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
22 i = -33;
23 ASSERT(0 > i);
24 ASSERT(i < 0);
25 ASSERT(0 >= i);
26 ASSERT(i <= 0);
28 i = 0;
29 ASSERT(0 == i);
30 ASSERT(0 <= i);
31 ASSERT(0 >= i);
32 #endif
33 #endif
36 static void
37 testCompareConstants(void)
39 {attr} {storage} signed {type} i;
41 i = 12;
42 ASSERT(i < 23);
43 ASSERT(i > 3);
44 ASSERT(i > -14);
45 #if !defined(__SDCC_pdk14) // Lack of memory
46 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
47 ASSERT(i <= 23);
48 ASSERT(i >= 3);
49 ASSERT(i >= -14);
50 ASSERT(i <= 12);
51 ASSERT(i >= 12);
52 ASSERT(i == 12);
53 #endif
54 #endif
56 i = -34;
57 ASSERT(i > -126);
58 ASSERT(i < -3);
59 #if !defined(__SDCC_pdk14) // Lack of memory
60 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
61 ASSERT(i < 47);
62 ASSERT(i >= -126);
63 ASSERT(i <= -3);
64 ASSERT(i <= 47);
65 ASSERT(i <= -34);
66 ASSERT(i >= -34);
67 ASSERT(i == -34);
68 #endif
69 #endif
72 static void
73 testCompareVariables(void)
75 {attr} {storage} signed {type} left, right;
77 left = 12;
78 right = 47;
79 ASSERT(left < right);
80 ASSERT(left <= right);
81 ASSERT(right > left);
82 ASSERT(right >= left);
84 right = -8;
85 ASSERT(left > right);
86 ASSERT(left >= right);
87 ASSERT(right < left);
88 ASSERT(right <= left);
89 #if !defined(__SDCC_pdk14) // Lack of memory
90 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
91 right = 0;
92 ASSERT(left > right);
93 ASSERT(left >= right);
94 ASSERT(right < left);
95 ASSERT(right <= left);
97 right = left;
98 ASSERT(left == right);
99 ASSERT(left <= right);
100 ASSERT(left >= right);
101 #endif
102 #endif
105 static void
106 testUnsignedCompare(void)
108 {attr} {storage} unsigned {type} left, right;
110 left = 0;
111 right = (unsigned {type})-1;
113 ASSERT(left < right);
114 ASSERT(left <= right);
115 ASSERT(right > left);
116 ASSERT(right >= left);
119 void (*fptr)(void);
120 int *volatile iptr;
122 #if !defined(__SDCC_pdk14) // Lack of memory
123 signed {type} s;
124 unsigned {type} u;
126 void set ({type} v)
128 s = v;
129 u = v;
131 #endif
133 /* Test optimization for eliminating redundant loads in range tests. s and u should not be volatile. */
134 void testRange(void)
136 #if !defined(__SDCC_pdk14) // Lack of memory
137 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
138 set (17);
140 ASSERT (s >= 17 && s <= 20);
141 ASSERT (u >= 17 && u <= 20);
143 set (21);
145 ASSERT (!(s >= 17 && s <= 20));
146 ASSERT (!(u >= 17 && u <= 20));
148 set (18);
150 ASSERT (s > 17 && s < 20);
151 ASSERT (u > 17 && u < 20);
153 set (20);
155 ASSERT (!(s > 17 && s < 20));
156 ASSERT (!(u > 17 && u < 20));
157 #endif
158 #endif
161 void testPointerCompare(void)
163 int i;
164 fptr = &testPointerCompare;
165 iptr = &i;
166 ASSERT(iptr == &i);
167 ASSERT(fptr == &testPointerCompare);
173 Common cases:
174 Around zero
175 Constants on either side (reversal)