]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/testPreCompiler.cc
Renamed squid.h to squid-old.h and config.h to squid.h.
[thirdparty/squid.git] / compat / testPreCompiler.cc
1 #define SQUID_UNIT_TEST 1
2 #include "squid.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 }
67
68 /**
69 * Test several ways of defining pre-compiler directives.
70 * Squid-3 uses #if FOO syntax for precompiler directives.
71 * These tests ensure that the inputs will work as expected
72 * when undefined macros are used in && conditions
73 */
74 void
75 testPreCompiler::testIfDefAnd()
76 {
77 /* Not Defined to exist at all == false - when used in a compound if */
78 #undef UNDEFINED_FOO
79 #define ONE_FOO 1
80
81 #if UNDEFINED_FOO && ONE_FOO
82 bool undefinedAndTrueA = true;
83 #else
84 bool undefinedAndTrueA = false;
85 #endif
86 #if !UNDEFINED_FOO && ONE_FOO
87 bool undefinedAndFalseA = true;
88 #else
89 bool undefinedAndFalseA = false;
90 #endif
91 CPPUNIT_ASSERT(undefinedAndFalseA);
92 CPPUNIT_ASSERT(!undefinedAndTrueA);
93
94 #if ONE_FOO && UNDEFINED_FOO
95 bool undefinedAndTrueB = true;
96 #else
97 bool undefinedAndTrueB = false;
98 #endif
99 #if ONE_FOO && !UNDEFINED_FOO
100 bool undefinedAndFalseB = true;
101 #else
102 bool undefinedAndFalseB = false;
103 #endif
104 CPPUNIT_ASSERT(undefinedAndFalseB);
105 CPPUNIT_ASSERT(!undefinedAndTrueB);
106 }
107
108 /**
109 * Test several ways of defining pre-compiler directives.
110 * Squid-3 uses #if FOO syntax for precompiler directives.
111 * These tests ensure that the inputs will work as expected
112 * when undefined macros are used in || conditions
113 */
114 void
115 testPreCompiler::testIfDefOr()
116 {
117 /* Not Defined to exist at all == false - when used in a compound if */
118 #undef UNDEFINED_FOO
119 #define ZERO_FOO 0
120
121 #if UNDEFINED_FOO || ZERO_FOO
122 bool undefinedOrTrueA = true;
123 #else
124 bool undefinedOrTrueA = false;
125 #endif
126 #if !UNDEFINED_FOO || ZERO_FOO
127 bool undefinedOrFalseA = true;
128 #else
129 bool undefinedOrFalseA = false;
130 #endif
131 CPPUNIT_ASSERT(undefinedOrFalseA);
132 CPPUNIT_ASSERT(!undefinedOrTrueA);
133
134 #if ZERO_FOO || UNDEFINED_FOO
135 bool undefinedOrTrueB = true;
136 #else
137 bool undefinedOrTrueB = false;
138 #endif
139 #if ZERO_FOO || !UNDEFINED_FOO
140 bool undefinedOrFalseB = true;
141 #else
142 bool undefinedOrFalseB = false;
143 #endif
144 CPPUNIT_ASSERT(undefinedOrFalseB);
145 CPPUNIT_ASSERT(!undefinedOrTrueB);
146
147 }
148