2 * Copyright (C) 1996-2023 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 "unitTestMain.h"
13 #include <cppunit/extensions/HelperMacros.h>
16 * Test the pre-compiler directives used within Squid code actually work.
19 class TestPreCompiler
: public CPPUNIT_NS::TestFixture
21 CPPUNIT_TEST_SUITE(TestPreCompiler
);
22 CPPUNIT_TEST(testIfDef
);
23 CPPUNIT_TEST(testIfDefAnd
);
24 CPPUNIT_TEST(testIfDefOr
);
25 CPPUNIT_TEST_SUITE_END();
32 CPPUNIT_TEST_SUITE_REGISTRATION(TestPreCompiler
);
35 * Test several ways of defining pre-compiler directives.
36 * Squid-3 uses #if FOO syntax for precompiler directives.
37 * These tests ensure that the inputs will work as expected.
40 TestPreCompiler::testIfDef()
42 /* Defined to explicit value 1 should be true */
52 bool oneFalse
= false;
54 CPPUNIT_ASSERT(oneTrue
);
55 CPPUNIT_ASSERT(!oneFalse
);
57 /* Defined to explicit value 0 should be false */
62 bool zeroTrue
= false;
65 bool zeroFalse
= true;
67 bool zeroFalse
= false;
69 CPPUNIT_ASSERT(zeroFalse
);
70 CPPUNIT_ASSERT(!zeroTrue
);
72 /* Defined to exist without a value generates pre-compiler errors when used in #if . */
74 /* Not Defined to exist at all == false */
77 bool undefinedTrue
= true;
79 bool undefinedTrue
= false;
82 bool undefinedFalse
= true;
84 bool undefinedFalse
= false;
86 CPPUNIT_ASSERT(undefinedFalse
);
87 CPPUNIT_ASSERT(!undefinedTrue
);
91 * Test several ways of defining pre-compiler directives.
92 * Squid-3 uses #if FOO syntax for precompiler directives.
93 * These tests ensure that the inputs will work as expected
94 * when undefined macros are used in && conditions
97 TestPreCompiler::testIfDefAnd()
99 /* Not Defined to exist at all == false - when used in a compound if */
103 #if UNDEFINED_FOO && ONE_FOO
104 bool undefinedAndTrueA
= true;
106 bool undefinedAndTrueA
= false;
108 #if !UNDEFINED_FOO && ONE_FOO
109 bool undefinedAndFalseA
= true;
111 bool undefinedAndFalseA
= false;
113 CPPUNIT_ASSERT(undefinedAndFalseA
);
114 CPPUNIT_ASSERT(!undefinedAndTrueA
);
116 #if ONE_FOO && UNDEFINED_FOO
117 bool undefinedAndTrueB
= true;
119 bool undefinedAndTrueB
= false;
121 #if ONE_FOO && !UNDEFINED_FOO
122 bool undefinedAndFalseB
= true;
124 bool undefinedAndFalseB
= false;
126 CPPUNIT_ASSERT(undefinedAndFalseB
);
127 CPPUNIT_ASSERT(!undefinedAndTrueB
);
129 #if UNDEFINED_FOO && UNDEFINED_FOO
130 bool undefinedAndUndefinedC
= true;
132 bool undefinedAndUndefinedC
= false;
134 #if !UNDEFINED_FOO && !UNDEFINED_FOO
135 bool notUndefinedAndNotUndefinedC
= true;
137 bool notUndefinedAndNotUndefinedC
= false;
139 CPPUNIT_ASSERT(!undefinedAndUndefinedC
);
140 CPPUNIT_ASSERT(notUndefinedAndNotUndefinedC
);
144 * Test several ways of defining pre-compiler directives.
145 * Squid-3 uses #if FOO syntax for precompiler directives.
146 * These tests ensure that the inputs will work as expected
147 * when undefined macros are used in || conditions
150 TestPreCompiler::testIfDefOr()
152 /* Not Defined to exist at all == false - when used in a compound if */
156 #if UNDEFINED_FOO || ZERO_FOO
157 bool undefinedOrTrueA
= true;
159 bool undefinedOrTrueA
= false;
161 #if !UNDEFINED_FOO || ZERO_FOO
162 bool undefinedOrFalseA
= true;
164 bool undefinedOrFalseA
= false;
166 CPPUNIT_ASSERT(undefinedOrFalseA
);
167 CPPUNIT_ASSERT(!undefinedOrTrueA
);
169 #if ZERO_FOO || UNDEFINED_FOO
170 bool undefinedOrTrueB
= true;
172 bool undefinedOrTrueB
= false;
174 #if ZERO_FOO || !UNDEFINED_FOO
175 bool undefinedOrFalseB
= true;
177 bool undefinedOrFalseB
= false;
179 CPPUNIT_ASSERT(undefinedOrFalseB
);
180 CPPUNIT_ASSERT(!undefinedOrTrueB
);
182 #if UNDEFINED_FOO || UNDEFINED_FOO
183 bool undefinedOrUndefinedC
= true;
185 bool undefinedOrUndefinedC
= false;
187 #if !UNDEFINED_FOO || !UNDEFINED_FOO
188 bool notUndefinedOrNotUndefinedC
= true;
190 bool notUndefinedOrNotUndefinedC
= false;
192 CPPUNIT_ASSERT(notUndefinedOrNotUndefinedC
);
193 CPPUNIT_ASSERT(!undefinedOrUndefinedC
);
197 main(int argc
, char *argv
[])
199 return TestProgram().run(argc
, argv
);