1 /** constant range tests.
18 #if defined (__GNUC__) && defined (__alpha__) && (__GNUC__ < 3)
19 /* bool should be casted to int in order to pass the test. Is this a gcc bug? */
20 #define INT_CAST (int)
35 testConstantRange (void)
37 ASSERT (! (INT8_MIN
- 1 == s8
));
38 ASSERT (! (INT8_MAX
+ 1 == s8
));
39 ASSERT ( (INT8_MIN
- 1 != s8
));
40 ASSERT ( (INT8_MAX
+ 1 != s8
));
41 ASSERT ( (INT8_MIN
- 1 < s8
));
42 ASSERT (! (INT8_MAX
< s8
));
43 ASSERT ( (INT8_MIN
<= s8
));
44 ASSERT (! (INT8_MAX
<= s8
));
45 ASSERT (! (INT8_MIN
> s8
));
46 ASSERT ( (INT8_MAX
+ 1 > s8
));
47 ASSERT (! (INT8_MIN
- 1 >= s8
));
48 ASSERT ( (INT8_MAX
>= s8
));
49 #if !defined(__SDCC_pdk14) // Lack of memory
50 ASSERT (! ( 0 - 1 == u8
));
51 ASSERT (! (UINT8_MAX
+ 1 == u8
));
52 ASSERT ( ( 0 - 1 != u8
));
53 ASSERT ( (UINT8_MAX
+ 1 != u8
));
54 ASSERT ( ( 0 - 1 < u8
));
55 ASSERT (! (UINT8_MAX
< u8
));
57 ASSERT (! (UINT8_MAX
+ 1 <= u8
));
59 ASSERT ( (UINT8_MAX
+ 1 > u8
));
60 ASSERT (! ( 0 - 1 >= u8
));
61 ASSERT ( (UINT8_MAX
>= u8
));
63 /* force extension to long to avoid int (16 bit) overflow */
64 ASSERT (! (INT16_MIN
- 1L == s16
));
65 ASSERT (! (INT16_MAX
+ 1L == s16
));
66 ASSERT ( (INT16_MIN
- 1L != s16
));
67 ASSERT ( (INT16_MAX
+ 1L != s16
));
68 ASSERT ( (INT16_MIN
- 1L < s16
));
69 ASSERT (! (INT16_MAX
< s16
));
70 ASSERT ( (INT16_MIN
<= s16
));
71 ASSERT (! (INT16_MAX
<= s16
));
72 ASSERT (! (INT16_MIN
> s16
));
73 ASSERT ( (INT16_MAX
+ 1L > s16
));
74 ASSERT (! (INT16_MIN
- 1L >= s16
));
75 ASSERT ( (INT16_MAX
>= s16
));
77 ASSERT (! ( 0 - 1 == u16
));
78 ASSERT (! (UINT16_MAX
+ 1L == u16
));
79 ASSERT ( ( 0 - 1 != u16
));
80 ASSERT ( (UINT16_MAX
+ 1L != u16
));
81 ASSERT (! (UINT16_MAX
< u16
));
82 ASSERT ( ( 0 <= u16
));
83 ASSERT (! (UINT16_MAX
+ 1L <= u16
));
84 ASSERT (! ( 0 > u16
));
85 ASSERT ( (UINT16_MAX
+ 1L > u16
));
86 ASSERT ( (UINT16_MAX
>= u16
));
88 ASSERT (UINTMAX_C(4294967295) <= UINTMAX_MAX
);
90 #if defined(PORT_HOST)
91 /* on 32bit host: -1 is presented as 32 bit int, 16 bit unsigned short is promoted to 32 bit int */
92 ASSERT ( ( 0 - 1 < u16
)); /* -1 > 0 */
93 ASSERT (! ( 0 - 1 >= u16
)); /* !(-1 <= 0) */
95 /* on 16bit sdcc: int (-1) is promoted to unsigned int (0xffff) */
96 ASSERT ( ( 0 - 1 > u16
)); /* 0xffff > 0 */
97 ASSERT (! ( 0 - 1 <= u16
)); /* !(0xffff <= 0) */
100 /* sdcc can't hold a number (INT32_MIN - 1) or (INT32_MAX + 1),
101 there's no 'double' or 'long long' */
102 /* ASSERT (! (INT32_MIN - 1 == s32)); */
103 /* ASSERT (! (INT32_MAX + 1 == s32)); */
104 /* ASSERT ( (INT32_MIN - 1 != s32)); */
105 /* ASSERT ( (INT32_MAX + 1 != s32)); */
106 /* ASSERT ( (INT32_MIN - 1 < s32)); */
107 ASSERT (! (INT32_MAX
< s32
));
108 ASSERT ( (INT32_MIN
<= s32
));
109 ASSERT (! (INT32_MAX
<= s32
));
110 ASSERT (! (INT32_MIN
> s32
));
111 /* ASSERT ( (INT32_MAX + 1 > s32)); */
112 /* ASSERT (! (INT32_MIN - 1 >= s32)); */
113 ASSERT ( (INT32_MAX
>= s32
));
115 ASSERT (! ( 0 - 1 == u32
));
116 /* ASSERT (! (UINT32_MAX + 1 == u32)); */
117 ASSERT ( ( 0 - 1 != u32
));
118 /* ASSERT ( (UINT32_MAX + 1 != u32)); */
119 ASSERT ( ( 0 - 1 > u32
)); /* 0xffffffff > 0 */
120 ASSERT (! (UINT32_MAX
< u32
));
121 ASSERT ( ( 0 <= u32
));
122 /* ASSERT (! (UINT32_MAX + 1 <= u32)); */
123 ASSERT (! ( 0 > u32
));
124 /* ASSERT ( (UINT32_MAX + 1 > u32)); */
125 ASSERT (! ( 0 - 1 <= u32
)); /* !(0xffffffff <= 0) */
126 ASSERT ( (UINT32_MAX
>= u32
));
133 #if !defined(__SDCC_pdk14) // Lack of memory
134 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
135 #ifdef __bool_true_false_are_defined
136 volatile bool sb
, ub
;
141 ASSERT (! (-1 == sb
));
142 ASSERT ( ( 0 == sb
));
143 ASSERT (! ( 1 == sb
));
145 ASSERT ( (-1 != sb
));
146 ASSERT (! ( 0 != sb
));
147 ASSERT ( ( 1 != sb
));
149 ASSERT ( (-1 < INT_CAST sb
));
150 ASSERT (! ( 0 < sb
));
152 ASSERT ( ( 0 <= sb
));
153 ASSERT (! ( 1 <= sb
));
155 ASSERT (! ( 0 > sb
));
158 ASSERT (! (-1 >= INT_CAST sb
));
159 ASSERT ( ( 0 >= sb
));
162 ASSERT (! (-1 == ub
));
163 ASSERT ( ( 0 == ub
));
164 ASSERT (! ( 1 == ub
));
166 ASSERT ( (-1 != ub
));
167 ASSERT (! ( 0 != ub
));
168 ASSERT ( ( 1 != ub
));
170 ASSERT ( (-1 < INT_CAST ub
));
171 ASSERT (! ( 0 < ub
));
173 ASSERT ( ( 0 <= ub
));
174 ASSERT (! ( 1 <= ub
));
176 ASSERT (! ( 0 > ub
));
179 ASSERT (! (-1 >= INT_CAST ub
));
180 ASSERT ( ( 0 >= ub
));
181 #endif //__bool_true_false_are_defined
189 #if !defined(__SDCC_pdk14) // Lack of memory
190 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
203 ASSERT (! (-2 == str
.sb1
));
204 ASSERT (! (-1 == str
.sb1
));
205 ASSERT ( ( 0 == str
.sb1
));
206 ASSERT (! ( 1 == str
.sb1
));
208 ASSERT (! (-1 == str
.ub1
));
209 ASSERT ( ( 0 == str
.ub1
));
210 ASSERT (! ( 1 == str
.ub1
));
211 ASSERT (! ( 2 == str
.ub1
));
213 ASSERT (! (-5 == str
.sb3
));
214 ASSERT (! (-4 == str
.sb3
));
215 ASSERT ( ( 0 == str
.sb3
));
216 ASSERT (! ( 3 == str
.sb3
));
217 ASSERT (! ( 4 == str
.sb3
));
219 ASSERT (! (-1 == str
.ub3
));
220 ASSERT ( ( 0 == str
.ub3
));
221 ASSERT (! ( 7 == str
.ub3
));
222 ASSERT (! ( 8 == str
.ub3
));