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 : : * Common header for tests that have access to an SMT-LIB parser 11 : : * (for easily issuing commands and parsing terms). 12 : : */ 13 : : 14 : : #ifndef CVC5__TEST__UNIT__TEST_API_H 15 : : #define CVC5__TEST__UNIT__TEST_API_H 16 : : 17 : : #include <cvc5/cvc5.h> 18 : : #include <cvc5/cvc5_parser.h> 19 : : 20 : : #include "expr/node.h" 21 : : #include "gtest/gtest.h" 22 : : #include "test.h" 23 : : 24 : : namespace cvc5::internal { 25 : : namespace test { 26 : : 27 : : /** 28 : : * For writing tests that accesss an SMT-LIB parser. 29 : : * 30 : : * The parser is set to logic ALL. 31 : : */ 32 : : class TestWithSmtParser : public TestInternal 33 : : { 34 : : protected: 35 : 4 : void SetUp() override 36 : : { 37 : 4 : d_solver.reset(new cvc5::Solver(d_tm)); 38 : 4 : d_solver->setLogic("ALL"); 39 : 4 : d_symman.reset(new parser::SymbolManager(d_tm)); 40 : 4 : d_ip.reset(new parser::InputParser(d_solver.get(), d_symman.get())); 41 : 4 : } 42 : : 43 : 4 : void TearDown() override 44 : : { 45 : 4 : d_symman.reset(nullptr); 46 : 4 : d_ip.reset(nullptr); 47 : 4 : } 48 : : 49 : : cvc5::TermManager d_tm; 50 : : std::unique_ptr<cvc5::Solver> d_solver; 51 : : std::unique_ptr<parser::SymbolManager> d_symman; 52 : : std::unique_ptr<cvc5::parser::InputParser> d_ip; 53 : : 54 : : public: 55 : : /** 56 : : * Run this SMT-LIB command. 57 : : */ 58 : 19 : void doCommand(const std::string& s) 59 : : { 60 : 19 : d_ip->setStringInput(modes::InputLanguage::SMT_LIB_2_6, s, "temp"); 61 : 19 : auto command = d_ip->nextCommand(); 62 : 19 : command.invoke(d_solver.get(), d_symman.get(), std::cout); 63 : 19 : } 64 : : 65 : : /** 66 : : * Parse a node from SMT-LIB. 67 : : */ 68 : 34 : Node parseNode(const std::string& s) 69 : : { 70 : 34 : d_ip->setStringInput(modes::InputLanguage::SMT_LIB_2_6, s, "temp"); 71 : 68 : return *d_ip->nextTerm().d_node; 72 : : } 73 : : }; 74 : : 75 : : } // namespace test 76 : : } // namespace cvc5::internal 77 : : #endif