1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Aina Niemetz, Morgan Deters, Mathias Preiner |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Black box testing of cvc5 output classes. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include <iostream> |
17 |
|
#include <sstream> |
18 |
|
|
19 |
|
#include "base/output.h" |
20 |
|
#include "test.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
namespace test { |
24 |
|
|
25 |
12 |
class TestUtilBlackOutput : public TestInternal |
26 |
|
{ |
27 |
|
protected: |
28 |
6 |
void SetUp() override |
29 |
|
{ |
30 |
6 |
TestInternal::SetUp(); |
31 |
6 |
DebugChannel.setStream(&d_debugStream); |
32 |
6 |
TraceChannel.setStream(&d_traceStream); |
33 |
6 |
MessageChannel.setStream(&d_messageStream); |
34 |
6 |
WarningChannel.setStream(&d_warningStream); |
35 |
|
|
36 |
6 |
d_debugStream.str(""); |
37 |
6 |
d_traceStream.str(""); |
38 |
6 |
d_messageStream.str(""); |
39 |
6 |
d_warningStream.str(""); |
40 |
6 |
} |
41 |
|
|
42 |
|
int32_t failure() |
43 |
|
{ |
44 |
|
// this represents an expensive function that should NOT be called |
45 |
|
// when debugging/tracing is turned off |
46 |
|
std::cout << "a function was evaluated under an output operation when it " |
47 |
|
"should not have been"; |
48 |
|
assert(false); |
49 |
|
return 0; |
50 |
|
} |
51 |
|
std::stringstream d_debugStream; |
52 |
|
std::stringstream d_traceStream; |
53 |
|
std::stringstream d_messageStream; |
54 |
|
std::stringstream d_warningStream; |
55 |
|
}; |
56 |
|
|
57 |
12 |
TEST_F(TestUtilBlackOutput, output) |
58 |
|
{ |
59 |
2 |
Debug.on("foo"); |
60 |
2 |
Debug("foo") << "testing1"; |
61 |
2 |
Debug.off("foo"); |
62 |
2 |
Debug("foo") << "testing2"; |
63 |
2 |
Debug.on("foo"); |
64 |
2 |
Debug("foo") << "testing3"; |
65 |
|
|
66 |
2 |
CVC5Message() << "a message"; |
67 |
2 |
Warning() << "bad warning!"; |
68 |
|
|
69 |
2 |
Trace.on("foo"); |
70 |
2 |
Trace("foo") << "tracing1"; |
71 |
2 |
Trace.off("foo"); |
72 |
2 |
Trace("foo") << "tracing2"; |
73 |
2 |
Trace.on("foo"); |
74 |
2 |
Trace("foo") << "tracing3"; |
75 |
|
|
76 |
|
#ifdef CVC5_MUZZLE |
77 |
|
|
78 |
|
ASSERT_EQ(d_debugStream.str(), ""); |
79 |
|
ASSERT_EQ(d_messageStream.str(), ""); |
80 |
|
ASSERT_EQ(d_warningStream.str(), ""); |
81 |
|
ASSERT_EQ(d_traceStream.str(), ""); |
82 |
|
|
83 |
|
#else /* CVC5_MUZZLE */ |
84 |
|
|
85 |
|
#ifdef CVC5_DEBUG |
86 |
2 |
ASSERT_EQ(d_debugStream.str(), "testing1testing3"); |
87 |
|
#else /* CVC5_DEBUG */ |
88 |
|
ASSERT_EQ(d_debugStream.str(), ""); |
89 |
|
#endif /* CVC5_DEBUG */ |
90 |
|
|
91 |
2 |
ASSERT_EQ(d_messageStream.str(), "a message"); |
92 |
2 |
ASSERT_EQ(d_warningStream.str(), "bad warning!"); |
93 |
|
|
94 |
|
#ifdef CVC5_TRACING |
95 |
2 |
ASSERT_EQ(d_traceStream.str(), "tracing1tracing3"); |
96 |
|
#else /* CVC5_TRACING */ |
97 |
|
ASSERT_EQ(d_traceStream.str(), ""); |
98 |
|
#endif /* CVC5_TRACING */ |
99 |
|
|
100 |
|
#endif /* CVC5_MUZZLE */ |
101 |
|
} |
102 |
|
|
103 |
12 |
TEST_F(TestUtilBlackOutput, evaluation_off_when_it_is_supposed_to_be) |
104 |
|
{ |
105 |
2 |
Debug.on("foo"); |
106 |
|
#ifndef CVC5_DEBUG |
107 |
|
ASSERT_FALSE(Debug.isOn("foo")); |
108 |
|
Debug("foo") << failure() << std::endl; |
109 |
|
#else |
110 |
2 |
ASSERT_TRUE(Debug.isOn("foo")); |
111 |
|
#endif |
112 |
2 |
Debug.off("foo"); |
113 |
|
|
114 |
2 |
Trace.on("foo"); |
115 |
|
#ifndef CVC5_TRACING |
116 |
|
ASSERT_FALSE(Trace.isOn("foo")); |
117 |
|
Trace("foo") << failure() << std::endl; |
118 |
|
#else |
119 |
2 |
ASSERT_TRUE(Trace.isOn("foo")); |
120 |
|
#endif |
121 |
2 |
Trace.off("foo"); |
122 |
|
|
123 |
|
#ifdef CVC5_MUZZLE |
124 |
|
ASSERT_FALSE(Debug.isOn("foo")); |
125 |
|
ASSERT_FALSE(Trace.isOn("foo")); |
126 |
|
ASSERT_FALSE(Warning.isOn()); |
127 |
|
ASSERT_FALSE(CVC5Message.isOn()); |
128 |
|
|
129 |
|
cout << "debug" << std::endl; |
130 |
|
Debug("foo") << failure() << std::endl; |
131 |
|
cout << "trace" << std::endl; |
132 |
|
Trace("foo") << failure() << std::endl; |
133 |
|
cout << "warning" << std::endl; |
134 |
|
Warning() << failure() << std::endl; |
135 |
|
cout << "message" << std::endl; |
136 |
|
CVC5Message() << failure() << std::endl; |
137 |
|
#endif |
138 |
|
} |
139 |
|
|
140 |
12 |
TEST_F(TestUtilBlackOutput, simple_print) |
141 |
|
{ |
142 |
|
#ifdef CVC5_MUZZLE |
143 |
|
|
144 |
|
Debug.off("yo"); |
145 |
|
Debug("yo") << "foobar"; |
146 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
147 |
|
d_debugStream.str(""); |
148 |
|
Debug.on("yo"); |
149 |
|
Debug("yo") << "baz foo"; |
150 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
151 |
|
d_debugStream.str(""); |
152 |
|
|
153 |
|
Trace.off("yo"); |
154 |
|
Trace("yo") << "foobar"; |
155 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
156 |
|
d_traceStream.str(""); |
157 |
|
Trace.on("yo"); |
158 |
|
Trace("yo") << "baz foo"; |
159 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
160 |
|
d_traceStream.str(""); |
161 |
|
|
162 |
|
Warning() << "baz foo"; |
163 |
|
ASSERT_EQ(d_warningStream.str(), std::string()); |
164 |
|
d_warningStream.str(""); |
165 |
|
|
166 |
|
CVC5Message() << "baz foo"; |
167 |
|
ASSERT_EQ(d_messageStream.str(), std::string()); |
168 |
|
d_messageStream.str(""); |
169 |
|
|
170 |
|
#else /* CVC5_MUZZLE */ |
171 |
|
|
172 |
2 |
Debug.off("yo"); |
173 |
2 |
Debug("yo") << "foobar"; |
174 |
2 |
ASSERT_EQ(d_debugStream.str(), std::string()); |
175 |
2 |
d_debugStream.str(""); |
176 |
2 |
Debug.on("yo"); |
177 |
2 |
Debug("yo") << "baz foo"; |
178 |
|
#ifdef CVC5_DEBUG |
179 |
2 |
ASSERT_EQ(d_debugStream.str(), std::string("baz foo")); |
180 |
|
#else /* CVC5_DEBUG */ |
181 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
182 |
|
#endif /* CVC5_DEBUG */ |
183 |
2 |
d_debugStream.str(""); |
184 |
|
|
185 |
2 |
Trace.off("yo"); |
186 |
2 |
Trace("yo") << "foobar"; |
187 |
2 |
ASSERT_EQ(d_traceStream.str(), std::string()); |
188 |
2 |
d_traceStream.str(""); |
189 |
2 |
Trace.on("yo"); |
190 |
2 |
Trace("yo") << "baz foo"; |
191 |
|
#ifdef CVC5_TRACING |
192 |
2 |
ASSERT_EQ(d_traceStream.str(), std::string("baz foo")); |
193 |
|
#else /* CVC5_TRACING */ |
194 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
195 |
|
#endif /* CVC5_TRACING */ |
196 |
2 |
d_traceStream.str(""); |
197 |
|
|
198 |
2 |
Warning() << "baz foo"; |
199 |
2 |
ASSERT_EQ(d_warningStream.str(), std::string("baz foo")); |
200 |
2 |
d_warningStream.str(""); |
201 |
|
|
202 |
2 |
CVC5Message() << "baz foo"; |
203 |
2 |
ASSERT_EQ(d_messageStream.str(), std::string("baz foo")); |
204 |
2 |
d_messageStream.str(""); |
205 |
|
|
206 |
|
#endif /* CVC5_MUZZLE */ |
207 |
|
} |
208 |
|
} // namespace test |
209 |
12 |
} // namespace cvc5 |