Listing 1: Boolean acceptance test suite
#include "booltest.h"
void acceptance_suite(void)
{
#if defined __cplusplus
/*
* boolean default constructor
*/
boolean b;
/*
* boolean copy constructor
*/
boolean b0 = b;
/*
* boolean constructor accepting FALSE/TRUE
*/
boolean b1 = FALSE;
boolean const cb = TRUE;
/*
* boolean aggregate initialized with
* boolean/FALSE/TRUE
*/
boolean ab[] =
{
FALSE,
TRUE,
cb
};
/*
* overload operator on boolean
*/
extern boolean operator !(boolean);
#else
/*
* boolean uninitialized
*/
boolean b;
/*
* boolean initialized with boolean/FALSE/TRUE
*/
boolean b0 = b;
boolean b1 = FALSE;
boolean const cb = TRUE;
/*
* boolean aggregate initialized with
* FALSE/TRUE
*/
boolean ab[] =
{
FALSE,
TRUE
};
#endif
/*
* assign boolean/FALSE/TRUE to boolean
*/
b = b0;
b = TRUE;
b = FALSE;
/*
* assign result of equality operator to boolean
*/
b = (i == 1);
/*
* assign result of logical operator to boolean
*/
b = (i && 1);
/*
* assign result of relational operator to boolean
*/
b = (i < 1);
/*
* boolean/FALSE/TRUE both operands of equality
* operator
*/
b == b;
b == FALSE;
TRUE == FALSE;
/*
* boolean/FALSE/TRUE both operands of logical
* operator
*/
b && b;
FALSE && b;
TRUE && FALSE;
/*
* boolean/FALSE/TRUE conditional expression
*/
b ? 1 : 0;
FALSE ? 1 : 0;
TRUE ? 1 : 0;
/*
* boolean/FALSE/TRUE controlling expression of
* 'if' statement
*/
if (b)
;
if (FALSE)
;
if (TRUE)
;
/*
* FALSE/TRUE case label
*/
switch (i)
{
case FALSE:
case TRUE:
break;
}
}