struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bool.c
blob862f9408f47d596428895493e8c8f79ddc9e1ef3
1 /* bool.c
2 */
4 #include <testfwk.h>
6 #ifdef __SDCC
7 #pragma std_c99
8 #endif
10 #include <stdbool.h>
11 #include <stdint.h>
13 bool ret_true(void)
15 return(true);
18 bool ret_false(void)
20 return(false);
23 volatile bool E;
25 bool (* const pa[])(void) = {&ret_true, &ret_false};
27 struct s
29 bool b;
32 struct
34 bool b : 1;
35 bool b1 : 1;
36 } s2;
38 void fieldassign(void)
40 s2.b1 = s2.b;
43 void
44 testBug2233(void)
46 #ifndef __SDCC_pic16
47 bool result;
48 volatile char test = 0;
50 result = ret_true();
52 if (result == 1)
53 test = 1;
54 ASSERT(test);
55 #endif
59 void
60 testBool(void)
62 #ifndef __SDCC_pic16
63 volatile unsigned char z = 2;
65 const char *BOOL = "George Boole";
67 ASSERT(true);
68 ASSERT((*(pa[0]))() == true);
69 ASSERT((*(pa[1]))() == false);
71 s2.b = (z & 2);
72 ASSERT(s2.b);
73 s2.b = (bool)(z & 2);
74 ASSERT(s2.b);
76 E = true;
77 ASSERT((E ? 1 : 0) == (!(!E)));
78 ASSERT((E += 2) == 1);
79 ASSERT((--E, --E, E) == E);
81 E = false;
82 ASSERT((E ? 1 : 0) == (!(!E)));
83 ASSERT((E += 2) == 1);
84 ASSERT((--E, --E, E) == E);
86 E = 0; ASSERT(!E); // sets E to 0
87 E = 1; ASSERT(E); // sets E to 1
88 E = 4; ASSERT(E); // sets E to 1
89 E = 0.5; ASSERT(E); // sets E to 1
90 E = false;
91 E++; ASSERT(E); // sets E to 1
92 E = true;
93 E++; ASSERT(E); // sets E to 1
94 E = false;
95 E--; ASSERT(E); // sets E to 1-E
96 E = true;
97 E--; ASSERT(!E); // sets E to 1-E
99 ASSERT(!s2.b1);
100 s2.b = true;
101 fieldassign();
102 ASSERT(s2.b1);
103 #endif