LCOV - code coverage report
Current view: top level - buildbot/coverage/build/test/unit/util - output_black.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 34 100.0 %
Date: 2026-06-05 10:34:07 Functions: 13 13 100.0 %
Branches: 19 38 50.0 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Black box testing of cvc5 output classes.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include <iostream>
      14                 :            : #include <sstream>
      15                 :            : 
      16                 :            : #include "base/output.h"
      17                 :            : #include "test.h"
      18                 :            : 
      19                 :            : namespace cvc5::internal {
      20                 :            : namespace test {
      21                 :            : 
      22                 :            : class TestUtilBlackOutput : public TestInternal
      23                 :            : {
      24                 :            :  protected:
      25                 :          3 :   void SetUp() override
      26                 :            :   {
      27                 :          3 :     TestInternal::SetUp();
      28                 :          3 :     TraceChannel.setStream(&d_traceStream);
      29                 :          3 :     WarningChannel.setStream(&d_warningStream);
      30                 :            : 
      31                 :          3 :     d_debugStream.str("");
      32                 :          3 :     d_traceStream.str("");
      33                 :          3 :     d_warningStream.str("");
      34                 :          3 :   }
      35                 :            : 
      36                 :            :   int32_t failure()
      37                 :            :   {
      38                 :            :     // this represents an expensive function that should NOT be called
      39                 :            :     // when debugging/tracing is turned off
      40                 :            :     std::cout << "a function was evaluated under an output operation when it "
      41                 :            :                  "should not have been";
      42                 :            :     assert(false);
      43                 :            :     return 0;
      44                 :            :   }
      45                 :            :   std::stringstream d_debugStream;
      46                 :            :   std::stringstream d_traceStream;
      47                 :            :   std::stringstream d_warningStream;
      48                 :            : };
      49                 :            : 
      50                 :          4 : TEST_F(TestUtilBlackOutput, output)
      51                 :            : {
      52         [ -  + ]:          1 :   Warning() << "bad warning!";
      53                 :            : 
      54                 :          1 :   TraceChannel.on("foo");
      55         [ -  + ]:          1 :   Trace("foo") << "tracing1";
      56                 :          1 :   TraceChannel.off("foo");
      57         [ +  - ]:          1 :   Trace("foo") << "tracing2";
      58                 :          1 :   TraceChannel.on("foo");
      59         [ -  + ]:          1 :   Trace("foo") << "tracing3";
      60                 :            : 
      61                 :            : #ifdef CVC5_MUZZLE
      62                 :            : 
      63                 :            :   ASSERT_EQ(d_warningStream.str(), "");
      64                 :            :   ASSERT_EQ(d_traceStream.str(), "");
      65                 :            : 
      66                 :            : #else /* CVC5_MUZZLE */
      67                 :            : 
      68 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(d_warningStream.str(), "bad warning!");
      69                 :            : 
      70                 :            : #ifdef CVC5_TRACING
      71 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(d_traceStream.str(), "tracing1tracing3");
      72                 :            : #else  /* CVC5_TRACING */
      73                 :            :   ASSERT_EQ(d_traceStream.str(), "");
      74                 :            : #endif /* CVC5_TRACING */
      75                 :            : 
      76                 :            : #endif /* CVC5_MUZZLE */
      77                 :            : }
      78                 :            : 
      79                 :          4 : TEST_F(TestUtilBlackOutput, evaluation_off_when_it_is_supposed_to_be)
      80                 :            : {
      81                 :          1 :   TraceChannel.on("foo");
      82                 :            : #ifndef CVC5_TRACING
      83                 :            :   ASSERT_FALSE(TraceIsOn("foo"));
      84                 :            :   Trace("foo") << failure() << std::endl;
      85                 :            : #else
      86 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(TraceIsOn("foo"));
      87                 :            : #endif
      88                 :          1 :   TraceChannel.off("foo");
      89                 :            : 
      90                 :            : #ifdef CVC5_MUZZLE
      91                 :            :   ASSERT_FALSE(TraceIsOn("foo"));
      92                 :            :   ASSERT_FALSE(TraceIsOn("foo"));
      93                 :            :   ASSERT_FALSE(Warning.isOn());
      94                 :            : 
      95                 :            :   cout << "debug" << std::endl;
      96                 :            :   Trace("foo") << failure() << std::endl;
      97                 :            :   cout << "trace" << std::endl;
      98                 :            :   Trace("foo") << failure() << std::endl;
      99                 :            :   cout << "warning" << std::endl;
     100                 :            :   Warning() << failure() << std::endl;
     101                 :            : #endif
     102                 :            : }
     103                 :            : 
     104                 :          4 : TEST_F(TestUtilBlackOutput, simple_print)
     105                 :            : {
     106                 :            : #ifdef CVC5_MUZZLE
     107                 :            : 
     108                 :            :   TraceChannel.off("yo");
     109                 :            :   Trace("yo") << "foobar";
     110                 :            :   ASSERT_EQ(d_traceStream.str(), std::string());
     111                 :            :   d_traceStream.str("");
     112                 :            :   TraceChannel.on("yo");
     113                 :            :   Trace("yo") << "baz foo";
     114                 :            :   ASSERT_EQ(d_traceStream.str(), std::string());
     115                 :            :   d_traceStream.str("");
     116                 :            : 
     117                 :            :   Warning() << "baz foo";
     118                 :            :   ASSERT_EQ(d_warningStream.str(), std::string());
     119                 :            :   d_warningStream.str("");
     120                 :            : 
     121                 :            : #else /* CVC5_MUZZLE */
     122                 :            : 
     123                 :          1 :   TraceChannel.off("yo");
     124         [ +  - ]:          1 :   Trace("yo") << "foobar";
     125 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(d_traceStream.str(), std::string());
     126                 :          1 :   d_traceStream.str("");
     127                 :          1 :   TraceChannel.on("yo");
     128         [ -  + ]:          1 :   Trace("yo") << "baz foo";
     129                 :            : #ifdef CVC5_TRACING
     130 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(d_traceStream.str(), std::string("baz foo"));
     131                 :            : #else  /* CVC5_TRACING */
     132                 :            :   ASSERT_EQ(d_traceStream.str(), std::string());
     133                 :            : #endif /* CVC5_TRACING */
     134                 :          1 :   d_traceStream.str("");
     135                 :            : 
     136         [ -  + ]:          1 :   Warning() << "baz foo";
     137 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(d_warningStream.str(), std::string("baz foo"));
     138                 :          1 :   d_warningStream.str("");
     139                 :            : 
     140                 :            : #endif /* CVC5_MUZZLE */
     141                 :            : }
     142                 :            : }  // namespace test
     143                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14