Listing 2: Boolean rejection test suite
#include "booltest.h"
void rejection_suite(void)
{
boolean b = TRUE;
boolean const cb = TRUE;
#if defined __cplusplus
/*
* non-boolean aggregate initialized with
* boolean/FALSE/TRUE
*/
int ai[] =
{
FALSE,
TRUE,
cb,
};
#endif
/*
* boolean initialized with non-boolean
*/
boolean b2 = 2;
/*
* FALSE/TRUE enumerator initializer
*/
enum
{
e0 = FALSE,
e1 = TRUE
};
/*
* FALSE/TRUE array dimension
*/
int ia0[FALSE];
int ia1[TRUE];
/*
* assign scalar to boolean
*/
b = c;
b = sc;
b = uc;
b = i;
b = ui;
b = l;
b = ul;
b = f;
b = d;
b = ld;
b = v;
b = cv;
b = r;
b = cr;
b = e;
b = t.t;
b = t.st;
b = t.ut;
/*
* assign boolean to scalar
*/
c = b;
sc = b;
uc = b;
i = b;
ui = b;
l = b;
ul = b;
f = b;
d = b;
ld = b;
v = b;
cv = b;
r = b;
cr = b;
e = b;
t.t = b;
t.st = b;
t.ut = b;
/*
* assign FALSE to scalar
*/
c = FALSE;
sc = FALSE;
uc = FALSE;
i = FALSE;
ui = FALSE;
l = FALSE;
ul = FALSE;
f = FALSE;
d = FALSE;
ld = FALSE;
v = FALSE;
cv = FALSE;
r = FALSE;
cr = FALSE;
e = FALSE;
t.t = FALSE;
t.st = FALSE;
t.ut = FALSE;
/*
* assign TRUE to scalar
*/
c = TRUE;
sc = TRUE;
uc = TRUE;
i = TRUE;
ui = TRUE;
l = TRUE;
ul = TRUE;
f = TRUE;
d = TRUE;
ld = TRUE;
v = TRUE;
cv = TRUE;
r = TRUE;
cr = TRUE;
e = TRUE;
t.t = TRUE;
t.st = TRUE;
t.ut = TRUE;
/*
* assign result of bitwise shift operator to
* boolean
*/
b = (i << 1);
/*
* assign result of bitwise operator to boolean
*/
b = (i & 1);
/*
* assign result of arithmetic operator to boolean
*/
b = (i + 1);
/*
* boolean/FALSE/TRUE operand of equality operator
*/
b == 1;
FALSE == 1;
TRUE == 1;
/*
* boolean/FALSE/TRUE operand of logical operator
*/
b && 1;
FALSE && 1;
TRUE && 1;
/*
* boolean/FALSE/TRUE operand of relational
* operator
*/
b < 1;
FALSE < 1;
TRUE < 1;
/*
* boolean/FALSE/TRUE operand of bitwise shift
* operator
*/
b << b;
FALSE << b;
TRUE << 1;
/*
* boolean/FALSE/TRUE operand of bitwise operator
*/
b & b;
b & FALSE;
TRUE & 1;
/*
* boolean/FALSE/TRUE operand of arithmetic
* operator
*/
b + b;
b + FALSE;
TRUE + 1;
/*
* FALSE/TRUE as modifiable lvalues
*/
FALSE = FALSE;
TRUE = TRUE;
/*
* FALSE/TRUE as lvalues
*/
&FALSE;
&TRUE;
}