2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "testPreCompiler.h"
11 #include "unitTestMain.h"
15 CPPUNIT_TEST_SUITE_REGISTRATION( testPreCompiler
);
18 * Test several ways of defining pre-compiler directives.
19 * Squid-3 uses #if FOO syntax for precompiler directives.
20 * These tests ensure that the inputs will work as expected.
23 testPreCompiler::testIfDef()
25 /* Defined to explicit value 1 should be true */
35 bool oneFalse
= false;
37 CPPUNIT_ASSERT(oneTrue
);
38 CPPUNIT_ASSERT(!oneFalse
);
40 /* Defined to explicit value 0 should be false */
45 bool zeroTrue
= false;
48 bool zeroFalse
= true;
50 bool zeroFalse
= false;
52 CPPUNIT_ASSERT(zeroFalse
);
53 CPPUNIT_ASSERT(!zeroTrue
);
55 /* Defined to exist without a value generates pre-compiler errors when used in #if . */
57 /* Not Defined to exist at all == false */
60 bool undefinedTrue
= true;
62 bool undefinedTrue
= false;
65 bool undefinedFalse
= true;
67 bool undefinedFalse
= false;
69 CPPUNIT_ASSERT(undefinedFalse
);
70 CPPUNIT_ASSERT(!undefinedTrue
);
74 * Test several ways of defining pre-compiler directives.
75 * Squid-3 uses #if FOO syntax for precompiler directives.
76 * These tests ensure that the inputs will work as expected
77 * when undefined macros are used in && conditions
80 testPreCompiler::testIfDefAnd()
82 /* Not Defined to exist at all == false - when used in a compound if */
86 #if UNDEFINED_FOO && ONE_FOO
87 bool undefinedAndTrueA
= true;
89 bool undefinedAndTrueA
= false;
91 #if !UNDEFINED_FOO && ONE_FOO
92 bool undefinedAndFalseA
= true;
94 bool undefinedAndFalseA
= false;
96 CPPUNIT_ASSERT(undefinedAndFalseA
);
97 CPPUNIT_ASSERT(!undefinedAndTrueA
);
99 #if ONE_FOO && UNDEFINED_FOO
100 bool undefinedAndTrueB
= true;
102 bool undefinedAndTrueB
= false;
104 #if ONE_FOO && !UNDEFINED_FOO
105 bool undefinedAndFalseB
= true;
107 bool undefinedAndFalseB
= false;
109 CPPUNIT_ASSERT(undefinedAndFalseB
);
110 CPPUNIT_ASSERT(!undefinedAndTrueB
);
112 #if UNDEFINED_FOO && UNDEFINED_FOO
113 bool undefinedAndUndefinedC
= true;
115 bool undefinedAndUndefinedC
= false;
117 #if !UNDEFINED_FOO && !UNDEFINED_FOO
118 bool notUndefinedAndNotUndefinedC
= true;
120 bool notUndefinedAndNotUndefinedC
= false;
122 CPPUNIT_ASSERT(!undefinedAndUndefinedC
);
123 CPPUNIT_ASSERT(notUndefinedAndNotUndefinedC
);
127 * Test several ways of defining pre-compiler directives.
128 * Squid-3 uses #if FOO syntax for precompiler directives.
129 * These tests ensure that the inputs will work as expected
130 * when undefined macros are used in || conditions
133 testPreCompiler::testIfDefOr()
135 /* Not Defined to exist at all == false - when used in a compound if */
139 #if UNDEFINED_FOO || ZERO_FOO
140 bool undefinedOrTrueA
= true;
142 bool undefinedOrTrueA
= false;
144 #if !UNDEFINED_FOO || ZERO_FOO
145 bool undefinedOrFalseA
= true;
147 bool undefinedOrFalseA
= false;
149 CPPUNIT_ASSERT(undefinedOrFalseA
);
150 CPPUNIT_ASSERT(!undefinedOrTrueA
);
152 #if ZERO_FOO || UNDEFINED_FOO
153 bool undefinedOrTrueB
= true;
155 bool undefinedOrTrueB
= false;
157 #if ZERO_FOO || !UNDEFINED_FOO
158 bool undefinedOrFalseB
= true;
160 bool undefinedOrFalseB
= false;
162 CPPUNIT_ASSERT(undefinedOrFalseB
);
163 CPPUNIT_ASSERT(!undefinedOrTrueB
);
165 #if UNDEFINED_FOO || UNDEFINED_FOO
166 bool undefinedOrUndefinedC
= true;
168 bool undefinedOrUndefinedC
= false;
170 #if !UNDEFINED_FOO || !UNDEFINED_FOO
171 bool notUndefinedOrNotUndefinedC
= true;
173 bool notUndefinedOrNotUndefinedC
= false;
175 CPPUNIT_ASSERT(notUndefinedOrNotUndefinedC
);
176 CPPUNIT_ASSERT(!undefinedOrUndefinedC
);