]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/testPreCompiler.cc
Merged from trunk
[thirdparty/squid.git] / compat / testPreCompiler.cc
1 #define SQUID_UNIT_TEST 1
2 #include "squid.h"
3
4 #include <cassert>
5
6 #include "testPreCompiler.h"
7
8 CPPUNIT_TEST_SUITE_REGISTRATION( testPreCompiler );
9
10 /**
11 * Test several ways of defining pre-compiler directives.
12 * Squid-3 uses #if FOO syntax for precompiler directives.
13 * These tests ensure that the inputs will work as expected.
14 */
15 void
16 testPreCompiler::testIfDef()
17 {
18 /* Defined to explicit value 1 should be true */
19 #define ONE_FOO 1
20 #if ONE_FOO
21 bool oneTrue = true;
22 #else
23 bool oneTrue = false;
24 #endif
25 #if !ONE_FOO
26 bool oneFalse = true;
27 #else
28 bool oneFalse = false;
29 #endif
30 CPPUNIT_ASSERT(oneTrue);
31 CPPUNIT_ASSERT(!oneFalse);
32
33 /* Defined to explicit value 0 should be false */
34 #define ZERO_FOO 0
35 #if ZERO_FOO
36 bool zeroTrue = true;
37 #else
38 bool zeroTrue = false;
39 #endif
40 #if !ZERO_FOO
41 bool zeroFalse = true;
42 #else
43 bool zeroFalse = false;
44 #endif
45 CPPUNIT_ASSERT(zeroFalse);
46 CPPUNIT_ASSERT(!zeroTrue);
47
48 /* Defined to exist without a value generates pre-compiler errors when used in #if . */
49
50 /* Not Defined to exist at all == false */
51 #undef UNDEFINED_FOO
52 #if UNDEFINED_FOO
53 bool undefinedTrue = true;
54 #else
55 bool undefinedTrue = false;
56 #endif
57 #if !UNDEFINED_FOO
58 bool undefinedFalse = true;
59 #else
60 bool undefinedFalse = false;
61 #endif
62 CPPUNIT_ASSERT(undefinedFalse);
63 CPPUNIT_ASSERT(!undefinedTrue);
64 }
65
66 /**
67 * Test several ways of defining pre-compiler directives.
68 * Squid-3 uses #if FOO syntax for precompiler directives.
69 * These tests ensure that the inputs will work as expected
70 * when undefined macros are used in && conditions
71 */
72 void
73 testPreCompiler::testIfDefAnd()
74 {
75 /* Not Defined to exist at all == false - when used in a compound if */
76 #undef UNDEFINED_FOO
77 #define ONE_FOO 1
78
79 #if UNDEFINED_FOO && ONE_FOO
80 bool undefinedAndTrueA = true;
81 #else
82 bool undefinedAndTrueA = false;
83 #endif
84 #if !UNDEFINED_FOO && ONE_FOO
85 bool undefinedAndFalseA = true;
86 #else
87 bool undefinedAndFalseA = false;
88 #endif
89 CPPUNIT_ASSERT(undefinedAndFalseA);
90 CPPUNIT_ASSERT(!undefinedAndTrueA);
91
92 #if ONE_FOO && UNDEFINED_FOO
93 bool undefinedAndTrueB = true;
94 #else
95 bool undefinedAndTrueB = false;
96 #endif
97 #if ONE_FOO && !UNDEFINED_FOO
98 bool undefinedAndFalseB = true;
99 #else
100 bool undefinedAndFalseB = false;
101 #endif
102 CPPUNIT_ASSERT(undefinedAndFalseB);
103 CPPUNIT_ASSERT(!undefinedAndTrueB);
104 }
105
106 /**
107 * Test several ways of defining pre-compiler directives.
108 * Squid-3 uses #if FOO syntax for precompiler directives.
109 * These tests ensure that the inputs will work as expected
110 * when undefined macros are used in || conditions
111 */
112 void
113 testPreCompiler::testIfDefOr()
114 {
115 /* Not Defined to exist at all == false - when used in a compound if */
116 #undef UNDEFINED_FOO
117 #define ZERO_FOO 0
118
119 #if UNDEFINED_FOO || ZERO_FOO
120 bool undefinedOrTrueA = true;
121 #else
122 bool undefinedOrTrueA = false;
123 #endif
124 #if !UNDEFINED_FOO || ZERO_FOO
125 bool undefinedOrFalseA = true;
126 #else
127 bool undefinedOrFalseA = false;
128 #endif
129 CPPUNIT_ASSERT(undefinedOrFalseA);
130 CPPUNIT_ASSERT(!undefinedOrTrueA);
131
132 #if ZERO_FOO || UNDEFINED_FOO
133 bool undefinedOrTrueB = true;
134 #else
135 bool undefinedOrTrueB = false;
136 #endif
137 #if ZERO_FOO || !UNDEFINED_FOO
138 bool undefinedOrFalseB = true;
139 #else
140 bool undefinedOrFalseB = false;
141 #endif
142 CPPUNIT_ASSERT(undefinedOrFalseB);
143 CPPUNIT_ASSERT(!undefinedOrTrueB);
144
145 }
146