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 |
NoticeChannel.setStream(&d_noticeStream); |
34 |
6 |
ChatChannel.setStream(&d_chatStream); |
35 |
6 |
MessageChannel.setStream(&d_messageStream); |
36 |
6 |
WarningChannel.setStream(&d_warningStream); |
37 |
|
|
38 |
6 |
d_debugStream.str(""); |
39 |
6 |
d_traceStream.str(""); |
40 |
6 |
d_noticeStream.str(""); |
41 |
6 |
d_chatStream.str(""); |
42 |
6 |
d_messageStream.str(""); |
43 |
6 |
d_warningStream.str(""); |
44 |
6 |
} |
45 |
|
|
46 |
|
int32_t failure() |
47 |
|
{ |
48 |
|
// this represents an expensive function that should NOT be called |
49 |
|
// when debugging/tracing is turned off |
50 |
|
std::cout << "a function was evaluated under an output operation when it " |
51 |
|
"should not have been"; |
52 |
|
assert(false); |
53 |
|
return 0; |
54 |
|
} |
55 |
|
std::stringstream d_debugStream; |
56 |
|
std::stringstream d_traceStream; |
57 |
|
std::stringstream d_noticeStream; |
58 |
|
std::stringstream d_chatStream; |
59 |
|
std::stringstream d_messageStream; |
60 |
|
std::stringstream d_warningStream; |
61 |
|
}; |
62 |
|
|
63 |
12 |
TEST_F(TestUtilBlackOutput, output) |
64 |
|
{ |
65 |
2 |
Debug.on("foo"); |
66 |
2 |
Debug("foo") << "testing1"; |
67 |
2 |
Debug.off("foo"); |
68 |
2 |
Debug("foo") << "testing2"; |
69 |
2 |
Debug.on("foo"); |
70 |
2 |
Debug("foo") << "testing3"; |
71 |
|
|
72 |
2 |
CVC5Message() << "a message"; |
73 |
2 |
Warning() << "bad warning!"; |
74 |
2 |
Chat() << "chatty"; |
75 |
2 |
Notice() << "note"; |
76 |
|
|
77 |
2 |
Trace.on("foo"); |
78 |
2 |
Trace("foo") << "tracing1"; |
79 |
2 |
Trace.off("foo"); |
80 |
2 |
Trace("foo") << "tracing2"; |
81 |
2 |
Trace.on("foo"); |
82 |
2 |
Trace("foo") << "tracing3"; |
83 |
|
|
84 |
|
#ifdef CVC5_MUZZLE |
85 |
|
|
86 |
|
ASSERT_EQ(d_debugStream.str(), ""); |
87 |
|
ASSERT_EQ(d_messageStream.str(), ""); |
88 |
|
ASSERT_EQ(d_warningStream.str(), ""); |
89 |
|
ASSERT_EQ(d_chatStream.str(), ""); |
90 |
|
ASSERT_EQ(d_noticeStream.str(), ""); |
91 |
|
ASSERT_EQ(d_traceStream.str(), ""); |
92 |
|
|
93 |
|
#else /* CVC5_MUZZLE */ |
94 |
|
|
95 |
|
#ifdef CVC5_DEBUG |
96 |
2 |
ASSERT_EQ(d_debugStream.str(), "testing1testing3"); |
97 |
|
#else /* CVC5_DEBUG */ |
98 |
|
ASSERT_EQ(d_debugStream.str(), ""); |
99 |
|
#endif /* CVC5_DEBUG */ |
100 |
|
|
101 |
2 |
ASSERT_EQ(d_messageStream.str(), "a message"); |
102 |
2 |
ASSERT_EQ(d_warningStream.str(), "bad warning!"); |
103 |
2 |
ASSERT_EQ(d_chatStream.str(), "chatty"); |
104 |
2 |
ASSERT_EQ(d_noticeStream.str(), "note"); |
105 |
|
|
106 |
|
#ifdef CVC5_TRACING |
107 |
2 |
ASSERT_EQ(d_traceStream.str(), "tracing1tracing3"); |
108 |
|
#else /* CVC5_TRACING */ |
109 |
|
ASSERT_EQ(d_traceStream.str(), ""); |
110 |
|
#endif /* CVC5_TRACING */ |
111 |
|
|
112 |
|
#endif /* CVC5_MUZZLE */ |
113 |
|
} |
114 |
|
|
115 |
12 |
TEST_F(TestUtilBlackOutput, evaluation_off_when_it_is_supposed_to_be) |
116 |
|
{ |
117 |
2 |
Debug.on("foo"); |
118 |
|
#ifndef CVC5_DEBUG |
119 |
|
ASSERT_FALSE(Debug.isOn("foo")); |
120 |
|
Debug("foo") << failure() << std::endl; |
121 |
|
#else |
122 |
2 |
ASSERT_TRUE(Debug.isOn("foo")); |
123 |
|
#endif |
124 |
2 |
Debug.off("foo"); |
125 |
|
|
126 |
2 |
Trace.on("foo"); |
127 |
|
#ifndef CVC5_TRACING |
128 |
|
ASSERT_FALSE(Trace.isOn("foo")); |
129 |
|
Trace("foo") << failure() << std::endl; |
130 |
|
#else |
131 |
2 |
ASSERT_TRUE(Trace.isOn("foo")); |
132 |
|
#endif |
133 |
2 |
Trace.off("foo"); |
134 |
|
|
135 |
|
#ifdef CVC5_MUZZLE |
136 |
|
ASSERT_FALSE(Debug.isOn("foo")); |
137 |
|
ASSERT_FALSE(Trace.isOn("foo")); |
138 |
|
ASSERT_FALSE(Warning.isOn()); |
139 |
|
ASSERT_FALSE(CVC5Message.isOn()); |
140 |
|
ASSERT_FALSE(Notice.isOn()); |
141 |
|
ASSERT_FALSE(Chat.isOn()); |
142 |
|
|
143 |
|
cout << "debug" << std::endl; |
144 |
|
Debug("foo") << failure() << std::endl; |
145 |
|
cout << "trace" << std::endl; |
146 |
|
Trace("foo") << failure() << std::endl; |
147 |
|
cout << "warning" << std::endl; |
148 |
|
Warning() << failure() << std::endl; |
149 |
|
cout << "message" << std::endl; |
150 |
|
CVC5Message() << failure() << std::endl; |
151 |
|
cout << "notice" << std::endl; |
152 |
|
Notice() << failure() << std::endl; |
153 |
|
cout << "chat" << std::endl; |
154 |
|
Chat() << failure() << std::endl; |
155 |
|
#endif |
156 |
|
} |
157 |
|
|
158 |
12 |
TEST_F(TestUtilBlackOutput, simple_print) |
159 |
|
{ |
160 |
|
#ifdef CVC5_MUZZLE |
161 |
|
|
162 |
|
Debug.off("yo"); |
163 |
|
Debug("yo") << "foobar"; |
164 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
165 |
|
d_debugStream.str(""); |
166 |
|
Debug.on("yo"); |
167 |
|
Debug("yo") << "baz foo"; |
168 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
169 |
|
d_debugStream.str(""); |
170 |
|
|
171 |
|
Trace.off("yo"); |
172 |
|
Trace("yo") << "foobar"; |
173 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
174 |
|
d_traceStream.str(""); |
175 |
|
Trace.on("yo"); |
176 |
|
Trace("yo") << "baz foo"; |
177 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
178 |
|
d_traceStream.str(""); |
179 |
|
|
180 |
|
Warning() << "baz foo"; |
181 |
|
ASSERT_EQ(d_warningStream.str(), std::string()); |
182 |
|
d_warningStream.str(""); |
183 |
|
|
184 |
|
Chat() << "baz foo"; |
185 |
|
ASSERT_EQ(d_chatStream.str(), std::string()); |
186 |
|
d_chatStream.str(""); |
187 |
|
|
188 |
|
CVC5Message() << "baz foo"; |
189 |
|
ASSERT_EQ(d_messageStream.str(), std::string()); |
190 |
|
d_messageStream.str(""); |
191 |
|
|
192 |
|
Notice() << "baz foo"; |
193 |
|
ASSERT_EQ(d_noticeStream.str(), std::string()); |
194 |
|
d_noticeStream.str(""); |
195 |
|
|
196 |
|
#else /* CVC5_MUZZLE */ |
197 |
|
|
198 |
2 |
Debug.off("yo"); |
199 |
2 |
Debug("yo") << "foobar"; |
200 |
2 |
ASSERT_EQ(d_debugStream.str(), std::string()); |
201 |
2 |
d_debugStream.str(""); |
202 |
2 |
Debug.on("yo"); |
203 |
2 |
Debug("yo") << "baz foo"; |
204 |
|
#ifdef CVC5_DEBUG |
205 |
2 |
ASSERT_EQ(d_debugStream.str(), std::string("baz foo")); |
206 |
|
#else /* CVC5_DEBUG */ |
207 |
|
ASSERT_EQ(d_debugStream.str(), std::string()); |
208 |
|
#endif /* CVC5_DEBUG */ |
209 |
2 |
d_debugStream.str(""); |
210 |
|
|
211 |
2 |
Trace.off("yo"); |
212 |
2 |
Trace("yo") << "foobar"; |
213 |
2 |
ASSERT_EQ(d_traceStream.str(), std::string()); |
214 |
2 |
d_traceStream.str(""); |
215 |
2 |
Trace.on("yo"); |
216 |
2 |
Trace("yo") << "baz foo"; |
217 |
|
#ifdef CVC5_TRACING |
218 |
2 |
ASSERT_EQ(d_traceStream.str(), std::string("baz foo")); |
219 |
|
#else /* CVC5_TRACING */ |
220 |
|
ASSERT_EQ(d_traceStream.str(), std::string()); |
221 |
|
#endif /* CVC5_TRACING */ |
222 |
2 |
d_traceStream.str(""); |
223 |
|
|
224 |
2 |
Warning() << "baz foo"; |
225 |
2 |
ASSERT_EQ(d_warningStream.str(), std::string("baz foo")); |
226 |
2 |
d_warningStream.str(""); |
227 |
|
|
228 |
2 |
Chat() << "baz foo"; |
229 |
2 |
ASSERT_EQ(d_chatStream.str(), std::string("baz foo")); |
230 |
2 |
d_chatStream.str(""); |
231 |
|
|
232 |
2 |
CVC5Message() << "baz foo"; |
233 |
2 |
ASSERT_EQ(d_messageStream.str(), std::string("baz foo")); |
234 |
2 |
d_messageStream.str(""); |
235 |
|
|
236 |
2 |
Notice() << "baz foo"; |
237 |
2 |
ASSERT_EQ(d_noticeStream.str(), std::string("baz foo")); |
238 |
2 |
d_noticeStream.str(""); |
239 |
|
|
240 |
|
#endif /* CVC5_MUZZLE */ |
241 |
|
} |
242 |
|
} // namespace test |
243 |
12 |
} // namespace cvc5 |