summaryrefslogtreecommitdiff
path: root/test/unit/util/output_black.h
blob: 9fee218a27d91fc7e12d48cc4597fe487fd8f687 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*********************                                                        */
/*! \file output_black.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Morgan Deters, Tim King, Andres Noetzli
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Black box testing of CVC4 output classes.
 **
 ** Black box testing of CVC4 output classes.
 **/

#include <cxxtest/TestSuite.h>

#include <iostream>
#include <sstream>

#include "base/output.h"

using namespace CVC4;
using namespace std;

class OutputBlack : public CxxTest::TestSuite {

  stringstream d_debugStream;
  stringstream d_traceStream;
  stringstream d_noticeStream;
  stringstream d_chatStream;
  stringstream d_messageStream;
  stringstream d_warningStream;

 public:
  void setUp() override
  {
    DebugChannel.setStream(&d_debugStream);
    TraceChannel.setStream(&d_traceStream);
    NoticeChannel.setStream(&d_noticeStream);
    ChatChannel.setStream(&d_chatStream);
    MessageChannel.setStream(&d_messageStream);
    WarningChannel.setStream(&d_warningStream);

    d_debugStream.str("");
    d_traceStream.str("");
    d_noticeStream.str("");
    d_chatStream.str("");
    d_messageStream.str("");
    d_warningStream.str("");
  }

  void tearDown() override {}

  void testOutput() {
    Debug.on("foo");
    Debug("foo") << "testing1";
    Debug.off("foo");
    Debug("foo") << "testing2";
    Debug.on("foo");
    Debug("foo") << "testing3";

    Message() << "a message";
    Warning() << "bad warning!";
    Chat() << "chatty";
    Notice() << "note";

    Trace.on("foo");
    Trace("foo") << "tracing1";
    Trace.off("foo");
    Trace("foo") << "tracing2";
    Trace.on("foo");
    Trace("foo") << "tracing3";

#ifdef CVC4_MUZZLE

    TS_ASSERT( d_debugStream.str() == "" );
    TS_ASSERT( d_messageStream.str() == "" );
    TS_ASSERT( d_warningStream.str() == "" );
    TS_ASSERT( d_chatStream.str() == "" );
    TS_ASSERT( d_noticeStream.str() == "" );
    TS_ASSERT( d_traceStream.str() == "" );

#else /* CVC4_MUZZLE */

#  ifdef CVC4_DEBUG
    TS_ASSERT( d_debugStream.str() == "testing1testing3" );
#  else /* CVC4_DEBUG */
    TS_ASSERT( d_debugStream.str() == "" );
#  endif /* CVC4_DEBUG */

    TS_ASSERT( d_messageStream.str() == "a message" );
    TS_ASSERT( d_warningStream.str() == "bad warning!" );
    TS_ASSERT( d_chatStream.str() == "chatty" );
    TS_ASSERT( d_noticeStream.str() == "note" );

#  ifdef CVC4_TRACING
    TS_ASSERT( d_traceStream.str() == "tracing1tracing3" );
#  else /* CVC4_TRACING */
    TS_ASSERT( d_traceStream.str() == "" );
#  endif /* CVC4_TRACING */

#endif /* CVC4_MUZZLE */
  }

  static int failure() {
    // this represents an expensive function that should NOT be called
    // when debugging/tracing is turned off
    TS_FAIL("a function was evaluated under an output operation when it should not have been");
    return 0;
  }

  void testEvaluationOffWhenItIsSupposedToBe() {
    Debug.on("foo");
#ifndef CVC4_DEBUG
    TS_ASSERT( !( Debug.isOn("foo") ) );
    Debug("foo") << failure() << endl;
#else /* ! CVC4_DEBUG */
    TS_ASSERT( Debug.isOn("foo") );
#endif /* ! CVC4_DEBUG */
    Debug.off("foo");
    //Debug("foo") << failure() << endl;

    Trace.on("foo");
#ifndef CVC4_TRACING
    TS_ASSERT( !( Trace.isOn("foo") ) );
    Trace("foo") << failure() << endl;
#else /* ! CVC4_TRACING */
    TS_ASSERT( Trace.isOn("foo") );
#endif /* ! CVC4_TRACING */
    Trace.off("foo");
    //Trace("foo") << failure() << endl;

#ifdef CVC4_MUZZLE
    TS_ASSERT( !( Debug.isOn("foo") ) );
    TS_ASSERT( !( Trace.isOn("foo") ) );
    TS_ASSERT( !( Warning.isOn() ) );
    TS_ASSERT( !( Message.isOn() ) );
    TS_ASSERT( !( Notice.isOn() ) );
    TS_ASSERT( !( Chat.isOn() ) );

    cout << "debug" << std::endl;
    Debug("foo") << failure() << endl;
    cout << "trace" << std::endl;
    Trace("foo") << failure() << endl;
    cout << "warning" << std::endl;
    Warning() << failure() << endl;
    cout << "message" << std::endl;
    Message() << failure() << endl;
    cout << "notice" << std::endl;
    Notice() << failure() << endl;
    cout << "chat" << std::endl;
    Chat() << failure() << endl;
#endif /* CVC4_MUZZLE */
  }

  void testSimplePrint() {

#ifdef CVC4_MUZZLE

    Debug.off("yo");
    Debug("yo") << "foobar";
    TS_ASSERT_EQUALS(d_debugStream.str(), string());
    d_debugStream.str("");
    Debug.on("yo");
    Debug("yo") << "baz foo";
    TS_ASSERT_EQUALS(d_debugStream.str(), string());
    d_debugStream.str("");

    Trace.off("yo");
    Trace("yo") << "foobar";
    TS_ASSERT_EQUALS(d_traceStream.str(), string());
    d_traceStream.str("");
    Trace.on("yo");
    Trace("yo") << "baz foo";
    TS_ASSERT_EQUALS(d_traceStream.str(), string());
    d_traceStream.str("");

    Warning() << "baz foo";
    TS_ASSERT_EQUALS(d_warningStream.str(), string());
    d_warningStream.str("");

    Chat() << "baz foo";
    TS_ASSERT_EQUALS(d_chatStream.str(), string());
    d_chatStream.str("");

    Message() << "baz foo";
    TS_ASSERT_EQUALS(d_messageStream.str(), string());
    d_messageStream.str("");

    Notice() << "baz foo";
    TS_ASSERT_EQUALS(d_noticeStream.str(), string());
    d_noticeStream.str("");

#else /* CVC4_MUZZLE */

    Debug.off("yo");
    Debug("yo") << "foobar";
    TS_ASSERT_EQUALS(d_debugStream.str(), string());
    d_debugStream.str("");
    Debug.on("yo");
    Debug("yo") << "baz foo";
#  ifdef CVC4_DEBUG
    TS_ASSERT_EQUALS(d_debugStream.str(), string("baz foo"));
#  else /* CVC4_DEBUG */
    TS_ASSERT_EQUALS(d_debugStream.str(), string());
#  endif /* CVC4_DEBUG */
    d_debugStream.str("");

    Trace.off("yo");
    Trace("yo") << "foobar";
    TS_ASSERT_EQUALS(d_traceStream.str(), string());
    d_traceStream.str("");
    Trace.on("yo");
    Trace("yo") << "baz foo";
#  ifdef CVC4_TRACING
    TS_ASSERT_EQUALS(d_traceStream.str(), string("baz foo"));
#  else /* CVC4_TRACING */
    TS_ASSERT_EQUALS(d_traceStream.str(), string());
#  endif /* CVC4_TRACING */
    d_traceStream.str("");

    Warning() << "baz foo";
    TS_ASSERT_EQUALS(d_warningStream.str(), string("baz foo"));
    d_warningStream.str("");

    Chat() << "baz foo";
    TS_ASSERT_EQUALS(d_chatStream.str(), string("baz foo"));
    d_chatStream.str("");

    Message() << "baz foo";
    TS_ASSERT_EQUALS(d_messageStream.str(), string("baz foo"));
    d_messageStream.str("");

    Notice() << "baz foo";
    TS_ASSERT_EQUALS(d_noticeStream.str(), string("baz foo"));
    d_noticeStream.str("");

#endif /* CVC4_MUZZLE */

  }
};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback