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