LCOV - code coverage report
Current view: top level - buildbot/coverage/build/test/unit/api/cpp - api_command_black.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 38 38 100.0 %
Date: 2026-07-29 10:35:49 Functions: 15 16 93.8 %
Branches: 20 40 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::parser::Command.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include <cvc5/cvc5.h>
      14                 :            : #include <cvc5/cvc5_parser.h>
      15                 :            : 
      16                 :            : #include <sstream>
      17                 :            : 
      18                 :            : #include "base/output.h"
      19                 :            : #include "options/base_options.h"
      20                 :            : #include "options/language.h"
      21                 :            : #include "options/options.h"
      22                 :            : #include "test_parser.h"
      23                 :            : 
      24                 :            : using namespace cvc5::parser;
      25                 :            : 
      26                 :            : namespace cvc5::internal {
      27                 :            : namespace test {
      28                 :            : 
      29                 :            : class TestApiBlackCommand : public TestParser
      30                 :            : {
      31                 :            :  protected:
      32                 :          3 :   TestApiBlackCommand() {}
      33                 :          3 :   virtual ~TestApiBlackCommand() {}
      34                 :            : 
      35                 :          5 :   Command parseCommand(const std::string& cmdStr)
      36                 :            :   {
      37                 :          5 :     std::stringstream ss;
      38                 :          5 :     ss << cmdStr << std::endl;
      39                 :          5 :     InputParser parser(d_solver.get(), d_symman.get());
      40                 :          5 :     parser.setStreamInput(
      41                 :            :         modes::InputLanguage::SMT_LIB_2_6, ss, "command_black");
      42                 :          9 :     return parser.nextCommand();
      43                 :          6 :   }
      44                 :            : };
      45                 :            : 
      46                 :          4 : TEST_F(TestApiBlackCommand, invoke)
      47                 :            : {
      48                 :          1 :   std::stringstream out;
      49                 :          1 :   Command cmd;
      50                 :            :   // set logic command can be executed
      51                 :          1 :   cmd = parseCommand("(set-logic QF_LIA)");
      52 [ -  + ][ +  - ]:          1 :   ASSERT_FALSE(cmd.isNull());
      53                 :          1 :   cmd.invoke(d_solver.get(), d_symman.get(), out);
      54                 :            :   // get model not available
      55                 :          1 :   cmd = parseCommand("(get-model)");
      56 [ -  + ][ +  - ]:          1 :   ASSERT_FALSE(cmd.isNull());
      57                 :          1 :   cmd.invoke(d_solver.get(), d_symman.get(), out);
      58                 :          1 :   std::string result = out.str();
      59         [ -  + ]:          1 :   ASSERT_EQ(
      60                 :            :       "(error \"cannot get model unless model generation is enabled (try "
      61                 :            :       "--produce-models)\")\n",
      62         [ +  - ]:          1 :       result);
      63                 :            :   // logic already set
      64                 :          3 :   ASSERT_THROW(parseCommand("(set-logic QF_LRA)"), ParserException);
      65 [ +  - ][ +  - ]:          1 : }
      66                 :            : 
      67                 :          4 : TEST_F(TestApiBlackCommand, toString)
      68                 :            : {
      69                 :          1 :   Command cmd;
      70                 :          1 :   cmd = parseCommand("(set-logic QF_LIA )");
      71 [ -  + ][ +  - ]:          1 :   ASSERT_FALSE(cmd.isNull());
      72                 :            :   // note normalizes wrt whitespace
      73 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(cmd.toString(), "(set-logic QF_LIA)");
      74                 :          1 :   std::stringstream ss;
      75                 :          1 :   ss << cmd;
      76 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(cmd.toString(), ss.str());
      77         [ +  - ]:          1 : }
      78                 :            : 
      79                 :          4 : TEST_F(TestApiBlackCommand, getCommandName)
      80                 :            : {
      81                 :          1 :   Command cmd;
      82                 :          1 :   cmd = parseCommand("(get-model)");
      83 [ -  + ][ +  - ]:          1 :   ASSERT_FALSE(cmd.isNull());
      84 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(cmd.getCommandName(), "get-model");
      85         [ +  - ]:          1 : }
      86                 :            : 
      87                 :            : }  // namespace test
      88                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14