Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Aina Niemetz, Gereon Kremer, Morgan Deters 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 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::internal { 23 : : namespace test { 24 : : 25 : : class TestUtilBlackOutput : public TestInternal 26 : : { 27 : : protected: 28 : 3 : void SetUp() override 29 : : { 30 : 3 : TestInternal::SetUp(); 31 : 3 : TraceChannel.setStream(&d_traceStream); 32 : 3 : WarningChannel.setStream(&d_warningStream); 33 : : 34 : 3 : d_debugStream.str(""); 35 : 3 : d_traceStream.str(""); 36 : 3 : d_warningStream.str(""); 37 : 3 : } 38 : : 39 : : int32_t failure() 40 : : { 41 : : // this represents an expensive function that should NOT be called 42 : : // when debugging/tracing is turned off 43 : : std::cout << "a function was evaluated under an output operation when it " 44 : : "should not have been"; 45 : : assert(false); 46 : : return 0; 47 : : } 48 : : std::stringstream d_debugStream; 49 : : std::stringstream d_traceStream; 50 : : std::stringstream d_warningStream; 51 : : }; 52 : : 53 : 2 : TEST_F(TestUtilBlackOutput, output) 54 : : { 55 [ - + ]: 1 : Warning() << "bad warning!"; 56 : : 57 : 1 : TraceChannel.on("foo"); 58 [ - + ]: 1 : Trace("foo") << "tracing1"; 59 : 1 : TraceChannel.off("foo"); 60 [ + - ]: 1 : Trace("foo") << "tracing2"; 61 : 1 : TraceChannel.on("foo"); 62 [ - + ]: 1 : Trace("foo") << "tracing3"; 63 : : 64 : : #ifdef CVC5_MUZZLE 65 : : 66 : : ASSERT_EQ(d_warningStream.str(), ""); 67 : : ASSERT_EQ(d_traceStream.str(), ""); 68 : : 69 : : #else /* CVC5_MUZZLE */ 70 : : 71 [ - + ]: 2 : ASSERT_EQ(d_warningStream.str(), "bad warning!"); 72 : : 73 : : #ifdef CVC5_TRACING 74 [ - + ]: 2 : ASSERT_EQ(d_traceStream.str(), "tracing1tracing3"); 75 : : #else /* CVC5_TRACING */ 76 : : ASSERT_EQ(d_traceStream.str(), ""); 77 : : #endif /* CVC5_TRACING */ 78 : : 79 : : #endif /* CVC5_MUZZLE */ 80 : : } 81 : : 82 : 2 : TEST_F(TestUtilBlackOutput, evaluation_off_when_it_is_supposed_to_be) 83 : : { 84 : 1 : TraceChannel.on("foo"); 85 : : #ifndef CVC5_TRACING 86 : : ASSERT_FALSE(TraceIsOn("foo")); 87 : : Trace("foo") << failure() << std::endl; 88 : : #else 89 [ - + ]: 1 : ASSERT_TRUE(TraceIsOn("foo")); 90 : : #endif 91 : 1 : TraceChannel.off("foo"); 92 : : 93 : : #ifdef CVC5_MUZZLE 94 : : ASSERT_FALSE(TraceIsOn("foo")); 95 : : ASSERT_FALSE(TraceIsOn("foo")); 96 : : ASSERT_FALSE(Warning.isOn()); 97 : : 98 : : cout << "debug" << std::endl; 99 : : Trace("foo") << failure() << std::endl; 100 : : cout << "trace" << std::endl; 101 : : Trace("foo") << failure() << std::endl; 102 : : cout << "warning" << std::endl; 103 : : Warning() << failure() << std::endl; 104 : : #endif 105 : : } 106 : : 107 : 2 : TEST_F(TestUtilBlackOutput, simple_print) 108 : : { 109 : : #ifdef CVC5_MUZZLE 110 : : 111 : : TraceChannel.off("yo"); 112 : : Trace("yo") << "foobar"; 113 : : ASSERT_EQ(d_traceStream.str(), std::string()); 114 : : d_traceStream.str(""); 115 : : TraceChannel.on("yo"); 116 : : Trace("yo") << "baz foo"; 117 : : ASSERT_EQ(d_traceStream.str(), std::string()); 118 : : d_traceStream.str(""); 119 : : 120 : : Warning() << "baz foo"; 121 : : ASSERT_EQ(d_warningStream.str(), std::string()); 122 : : d_warningStream.str(""); 123 : : 124 : : #else /* CVC5_MUZZLE */ 125 : : 126 : 1 : TraceChannel.off("yo"); 127 [ + - ]: 1 : Trace("yo") << "foobar"; 128 [ - + ]: 2 : ASSERT_EQ(d_traceStream.str(), std::string()); 129 : 1 : d_traceStream.str(""); 130 : 1 : TraceChannel.on("yo"); 131 [ - + ]: 1 : Trace("yo") << "baz foo"; 132 : : #ifdef CVC5_TRACING 133 [ - + ]: 2 : ASSERT_EQ(d_traceStream.str(), std::string("baz foo")); 134 : : #else /* CVC5_TRACING */ 135 : : ASSERT_EQ(d_traceStream.str(), std::string()); 136 : : #endif /* CVC5_TRACING */ 137 : 1 : d_traceStream.str(""); 138 : : 139 [ - + ]: 1 : Warning() << "baz foo"; 140 [ - + ]: 2 : ASSERT_EQ(d_warningStream.str(), std::string("baz foo")); 141 : 1 : d_warningStream.str(""); 142 : : 143 : : #endif /* CVC5_MUZZLE */ 144 : : } 145 : : } // namespace test 146 : : } // namespace cvc5::internal