]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/testPreCompiler.cc
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
);
114 * Test several ways of defining pre-compiler directives.
115 * Squid-3 uses #if FOO syntax for precompiler directives.
116 * These tests ensure that the inputs will work as expected
117 * when undefined macros are used in || conditions
120 testPreCompiler::testIfDefOr()
122 /* Not Defined to exist at all == false - when used in a compound if */
126 #if UNDEFINED_FOO || ZERO_FOO
127 bool undefinedOrTrueA
= true;
129 bool undefinedOrTrueA
= false;
131 #if !UNDEFINED_FOO || ZERO_FOO
132 bool undefinedOrFalseA
= true;
134 bool undefinedOrFalseA
= false;
136 CPPUNIT_ASSERT(undefinedOrFalseA
);
137 CPPUNIT_ASSERT(!undefinedOrTrueA
);
139 #if ZERO_FOO || UNDEFINED_FOO
140 bool undefinedOrTrueB
= true;
142 bool undefinedOrTrueB
= false;
144 #if ZERO_FOO || !UNDEFINED_FOO
145 bool undefinedOrFalseB
= true;
147 bool undefinedOrFalseB
= false;
149 CPPUNIT_ASSERT(undefinedOrFalseB
);
150 CPPUNIT_ASSERT(!undefinedOrTrueB
);