File: testPreCompiler.cc

package info (click to toggle)
squid3 3.4.8-6
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 31,084 kB
  • sloc: cpp: 165,325; ansic: 21,998; sh: 12,166; makefile: 5,964; perl: 2,153; sql: 322; awk: 118
file content (148 lines) | stat: -rw-r--r-- 3,427 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#define SQUID_UNIT_TEST 1
#include "squid.h"

#if HAVE_ASSERT_H
#include <assert.h>
#endif

#include "testPreCompiler.h"

CPPUNIT_TEST_SUITE_REGISTRATION( testPreCompiler );

/**
 * Test several ways of defining pre-compiler directives.
 * Squid-3 uses #if FOO syntax for precompiler directives.
 * These tests ensure that the inputs will work as expected.
 */
void
testPreCompiler::testIfDef()
{
    /* Defined to explicit value 1 should be true */
#define ONE_FOO 1
#if ONE_FOO
    bool oneTrue = true;
#else
    bool oneTrue = false;
#endif
#if !ONE_FOO
    bool oneFalse = true;
#else
    bool oneFalse = false;
#endif
    CPPUNIT_ASSERT(oneTrue);
    CPPUNIT_ASSERT(!oneFalse);

    /* Defined to explicit value 0 should be false */
#define ZERO_FOO 0
#if ZERO_FOO
    bool zeroTrue = true;
#else
    bool zeroTrue = false;
#endif
#if !ZERO_FOO
    bool zeroFalse = true;
#else
    bool zeroFalse = false;
#endif
    CPPUNIT_ASSERT(zeroFalse);
    CPPUNIT_ASSERT(!zeroTrue);

    /* Defined to exist without a value generates pre-compiler errors when used in #if . */

    /* Not Defined to exist at all == false */
#undef UNDEFINED_FOO
#if UNDEFINED_FOO
    bool undefinedTrue = true;
#else
    bool undefinedTrue = false;
#endif
#if !UNDEFINED_FOO
    bool undefinedFalse = true;
#else
    bool undefinedFalse = false;
#endif
    CPPUNIT_ASSERT(undefinedFalse);
    CPPUNIT_ASSERT(!undefinedTrue);
}

/**
 * Test several ways of defining pre-compiler directives.
 * Squid-3 uses #if FOO syntax for precompiler directives.
 * These tests ensure that the inputs will work as expected
 * when undefined macros are used in && conditions
 */
void
testPreCompiler::testIfDefAnd()
{
    /* Not Defined to exist at all == false - when used in a compound if */
#undef UNDEFINED_FOO
#define ONE_FOO 1

#if UNDEFINED_FOO && ONE_FOO
    bool undefinedAndTrueA = true;
#else
    bool undefinedAndTrueA = false;
#endif
#if !UNDEFINED_FOO && ONE_FOO
    bool undefinedAndFalseA = true;
#else
    bool undefinedAndFalseA = false;
#endif
    CPPUNIT_ASSERT(undefinedAndFalseA);
    CPPUNIT_ASSERT(!undefinedAndTrueA);

#if ONE_FOO && UNDEFINED_FOO
    bool undefinedAndTrueB = true;
#else
    bool undefinedAndTrueB = false;
#endif
#if ONE_FOO && !UNDEFINED_FOO
    bool undefinedAndFalseB = true;
#else
    bool undefinedAndFalseB = false;
#endif
    CPPUNIT_ASSERT(undefinedAndFalseB);
    CPPUNIT_ASSERT(!undefinedAndTrueB);
}

/**
 * Test several ways of defining pre-compiler directives.
 * Squid-3 uses #if FOO syntax for precompiler directives.
 * These tests ensure that the inputs will work as expected
 * when undefined macros are used in || conditions
 */
void
testPreCompiler::testIfDefOr()
{
    /* Not Defined to exist at all == false - when used in a compound if */
#undef UNDEFINED_FOO
#define ZERO_FOO 0

#if UNDEFINED_FOO || ZERO_FOO
    bool undefinedOrTrueA = true;
#else
    bool undefinedOrTrueA = false;
#endif
#if !UNDEFINED_FOO || ZERO_FOO
    bool undefinedOrFalseA = true;
#else
    bool undefinedOrFalseA = false;
#endif
    CPPUNIT_ASSERT(undefinedOrFalseA);
    CPPUNIT_ASSERT(!undefinedOrTrueA);

#if ZERO_FOO || UNDEFINED_FOO
    bool undefinedOrTrueB = true;
#else
    bool undefinedOrTrueB = false;
#endif
#if ZERO_FOO || !UNDEFINED_FOO
    bool undefinedOrFalseB = true;
#else
    bool undefinedOrFalseB = false;
#endif
    CPPUNIT_ASSERT(undefinedOrFalseB);
    CPPUNIT_ASSERT(!undefinedOrTrueB);

}