]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/testPreCompiler.cc
Merge from trunk
[thirdparty/squid.git] / compat / testPreCompiler.cc
1 #define SQUID_UNIT_TEST 1
2 #include "config.h"
3
4 #if HAVE_ASSERT_H
5 #include <assert.h>
6 #endif
7
8 #include "testPreCompiler.h"
9
10 CPPUNIT_TEST_SUITE_REGISTRATION( testPreCompiler );
11
12 /**
13 * Test several ways of defining pre-compiler directives.
14 * Squid-3 uses #if FOO syntax for precompiler directives.
15 * These tests ensure that the inputs will work as expected.
16 */
17 void
18 testPreCompiler::testIfDef()
19 {
20 /* Defined to explicit value 1 should be true */
21 #define ONE_FOO 1
22 #if ONE_FOO
23 bool oneTrue = true;
24 #else
25 bool oneTrue = false;
26 #endif
27 #if !ONE_FOO
28 bool oneFalse = true;
29 #else
30 bool oneFalse = false;
31 #endif
32 CPPUNIT_ASSERT(oneTrue);
33 CPPUNIT_ASSERT(!oneFalse);
34
35 /* Defined to explicit value 0 should be false */
36 #define ZERO_FOO 0
37 #if ZERO_FOO
38 bool zeroTrue = true;
39 #else
40 bool zeroTrue = false;
41 #endif
42 #if !ZERO_FOO
43 bool zeroFalse = true;
44 #else
45 bool zeroFalse = false;
46 #endif
47 CPPUNIT_ASSERT(zeroFalse);
48 CPPUNIT_ASSERT(!zeroTrue);
49
50 /* Defined to exist without a value generates pre-compiler errors when used in #if . */
51
52 /* Not Defined to exist at all == false */
53 #undef UNDEFINED_FOO
54 #if UNDEFINED_FOO
55 bool undefinedTrue = true;
56 #else
57 bool undefinedTrue = false;
58 #endif
59 #if !UNDEFINED_FOO
60 bool undefinedFalse = true;
61 #else
62 bool undefinedFalse = false;
63 #endif
64 CPPUNIT_ASSERT(undefinedFalse);
65 CPPUNIT_ASSERT(!undefinedTrue);
66 }