Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / bitvars.c
1 /** Bit vars test.
2
3     type: bool, char, unsigned char, unsigned short, unsigned long
4 */
5
6 #include <testfwk.h>
7 #include <stdbool.h>
8
9 #ifndef PORT_HOST
10 #pragma disable_warning 180 //no warning about using complement on bit/unsigned char
11 #endif
12
13 #ifdef __bool_true_false_are_defined
14
15 #define TYPE_{type}
16
17 char foo(bool a, bool b, char c)
18 {
19   return a + b + c;
20 }
21
22 char complement(bool a, bool b)
23 {
24   return (a == b);
25 }
26
27 {type} _0 = 0, _1 = 1, _ff = 0xFF, _ffff = -1;
28
29 #endif //__bool_true_false_are_defined
30
31 void
32 testBits(void)
33 {
34 #ifdef __bool_true_false_are_defined
35   bool x = 2;
36   ASSERT (foo(x,3,4) == 6);
37
38   ASSERT (complement (~_0, 1));
39   ASSERT (complement (~_1, 1));
40
41 #if defined TYPE_char
42   ASSERT (complement (~_ff, 0));
43 #else
44   ASSERT (complement (~_ff, 1));
45 #endif
46
47 #if defined TYPE_bool
48   ASSERT (complement (~_ffff, 1));
49 #elif defined TYPE_char
50   ASSERT (complement (~_ffff, 0));
51 #else
52   if (sizeof({type}) < sizeof(int))
53     ASSERT (complement (~_ffff, 1));
54   else
55     ASSERT (complement (~_ffff, 0));
56 #endif
57
58 #endif //__bool_true_false_are_defined
59 }