From 0bd00a9a25ff2358cb613a964186c1a13c5f351d Mon Sep 17 00:00:00 2001 From: Aina Niemetz Date: Tue, 16 Feb 2021 08:08:55 -0800 Subject: [PATCH] google test: parser: Migrate parser_builder_black. (#5896) --- test/unit/parser/CMakeLists.txt | 2 +- test/unit/parser/parser_builder_black.cpp | 137 +++++++++++++++++++++ test/unit/parser/parser_builder_black.h | 139 ---------------------- 3 files changed, 138 insertions(+), 140 deletions(-) create mode 100644 test/unit/parser/parser_builder_black.cpp delete mode 100644 test/unit/parser/parser_builder_black.h diff --git a/test/unit/parser/CMakeLists.txt b/test/unit/parser/CMakeLists.txt index 7e413e707..b4938c26c 100644 --- a/test/unit/parser/CMakeLists.txt +++ b/test/unit/parser/CMakeLists.txt @@ -12,4 +12,4 @@ # Add unit tests cvc4_add_unit_test_black(parser_black parser) -cvc4_add_cxx_unit_test_black(parser_builder_black parser) +cvc4_add_unit_test_black(parser_builder_black parser) \ No newline at end of file diff --git a/test/unit/parser/parser_builder_black.cpp b/test/unit/parser/parser_builder_black.cpp new file mode 100644 index 000000000..11395fdcb --- /dev/null +++ b/test/unit/parser/parser_builder_black.cpp @@ -0,0 +1,137 @@ +/********************* */ +/*! \file parser_builder_black.cpp + ** \verbatim + ** Top contributors (to current version): + ** Aina Niemetz, Christopher L. Conway, Tim King + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS + ** in the top-level source directory and their institutional affiliations. + ** All rights reserved. See the file COPYING in the top-level source + ** directory for licensing information.\endverbatim + ** + ** \brief Black box testing of CVC4::parser::ParserBuilder. + ** + ** Black box testing of CVC4::parser::ParserBuilder. + **/ + +#include +#include +#include +#include + +#include +#include + +#include "api/cvc4cpp.h" +#include "expr/symbol_manager.h" +#include "options/language.h" +#include "parser/parser.h" +#include "parser/parser_builder.h" +#include "test_api.h" + +namespace CVC4 { + +using namespace parser; +using namespace language::input; + +namespace test { + +class TestParseBlackParserBuilder : public TestApi +{ + protected: + void SetUp() override { d_symman.reset(new SymbolManager(&d_solver)); } + + void checkEmptyInput(ParserBuilder& builder) + { + Parser* parser = builder.build(); + ASSERT_NE(parser, nullptr); + + api::Term e = parser->nextExpression(); + ASSERT_TRUE(e.isNull()); + + delete parser; + } + + void checkTrueInput(ParserBuilder& builder) + { + Parser* parser = builder.build(); + ASSERT_NE(parser, nullptr); + + api::Term e = parser->nextExpression(); + ASSERT_EQ(e, d_solver.mkTrue()); + + e = parser->nextExpression(); + ASSERT_TRUE(e.isNull()); + delete parser; + } + + char* mkTemp() + { + char* filename = strdup("/tmp/testinput.XXXXXX"); + int32_t fd = mkstemp(filename); + if (fd == -1) return nullptr; + close(fd); + return filename; + } + std::unique_ptr d_symman; +}; + +TEST_F(TestParseBlackParserBuilder, empty_file_input) +{ + char* filename = mkTemp(); + ASSERT_NE(filename, nullptr); + + checkEmptyInput(ParserBuilder(&d_solver, d_symman.get(), filename) + .withInputLanguage(LANG_CVC4)); + + remove(filename); + free(filename); +} + +TEST_F(TestParseBlackParserBuilder, simple_file_input) +{ + char* filename = mkTemp(); + + std::fstream fs(filename, std::fstream::out); + fs << "TRUE" << std::endl; + fs.close(); + + checkTrueInput(ParserBuilder(&d_solver, d_symman.get(), filename) + .withInputLanguage(LANG_CVC4)); + + remove(filename); + free(filename); +} + +TEST_F(TestParseBlackParserBuilder, empty_string_input) +{ + checkEmptyInput(ParserBuilder(&d_solver, d_symman.get(), "foo") + .withInputLanguage(LANG_CVC4) + .withStringInput("")); +} + +TEST_F(TestParseBlackParserBuilder, true_string_input) +{ + checkTrueInput(ParserBuilder(&d_solver, d_symman.get(), "foo") + .withInputLanguage(LANG_CVC4) + .withStringInput("TRUE")); +} + +TEST_F(TestParseBlackParserBuilder, empty_stream_input) +{ + std::stringstream ss("", std::ios_base::in); + checkEmptyInput(ParserBuilder(&d_solver, d_symman.get(), "foo") + .withInputLanguage(LANG_CVC4) + .withStreamInput(ss)); +} + +TEST_F(TestParseBlackParserBuilder, true_stream_input) +{ + std::stringstream ss("TRUE", std::ios_base::in); + checkTrueInput(ParserBuilder(&d_solver, d_symman.get(), "foo") + .withInputLanguage(LANG_CVC4) + .withStreamInput(ss)); +} + +} // namespace test +} // namespace CVC4 diff --git a/test/unit/parser/parser_builder_black.h b/test/unit/parser/parser_builder_black.h deleted file mode 100644 index 686fc7400..000000000 --- a/test/unit/parser/parser_builder_black.h +++ /dev/null @@ -1,139 +0,0 @@ -/********************* */ -/*! \file parser_builder_black.h - ** \verbatim - ** Top contributors (to current version): - ** Christopher L. Conway, Andrew Reynolds, Aina Niemetz - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS - ** in the top-level source directory and their institutional affiliations. - ** All rights reserved. See the file COPYING in the top-level source - ** directory for licensing information.\endverbatim - ** - ** \brief Black box testing of CVC4::parser::ParserBuilder. - ** - ** Black box testing of CVC4::parser::ParserBuilder. - **/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "api/cvc4cpp.h" -#include "expr/symbol_manager.h" -#include "options/language.h" -#include "parser/parser.h" -#include "parser/parser_builder.h" - -using namespace CVC4; -using namespace CVC4::parser; -using namespace CVC4::language::input; -using namespace std; - -class ParserBuilderBlack : public CxxTest::TestSuite -{ - public: - void setUp() override - { - // ensure the old symbol manager is deleted - d_symman.reset(nullptr); - d_solver.reset(new api::Solver()); - d_symman.reset(new SymbolManager(d_solver.get())); - } - - void tearDown() override {} - - void testEmptyFileInput() - { - char *filename = mkTemp(); - - checkEmptyInput(ParserBuilder(d_solver.get(), d_symman.get(), filename) - .withInputLanguage(LANG_CVC4)); - - remove(filename); - free(filename); - } - - void testSimpleFileInput() { - char *filename = mkTemp(); - - std::fstream fs( filename, fstream::out ); - fs << "TRUE" << std::endl; - fs.close(); - - checkTrueInput(ParserBuilder(d_solver.get(), d_symman.get(), filename) - .withInputLanguage(LANG_CVC4)); - - remove(filename); - free(filename); - } - - void testEmptyStringInput() { - checkEmptyInput(ParserBuilder(d_solver.get(), d_symman.get(), "foo") - .withInputLanguage(LANG_CVC4) - .withStringInput("")); - } - - void testTrueStringInput() { - checkTrueInput(ParserBuilder(d_solver.get(), d_symman.get(), "foo") - .withInputLanguage(LANG_CVC4) - .withStringInput("TRUE")); - } - - void testEmptyStreamInput() { - stringstream ss( "", ios_base::in ); - checkEmptyInput(ParserBuilder(d_solver.get(), d_symman.get(), "foo") - .withInputLanguage(LANG_CVC4) - .withStreamInput(ss)); - } - - void testTrueStreamInput() { - stringstream ss( "TRUE", ios_base::in ); - checkTrueInput(ParserBuilder(d_solver.get(), d_symman.get(), "foo") - .withInputLanguage(LANG_CVC4) - .withStreamInput(ss)); - } - - private: - void checkEmptyInput(ParserBuilder &builder) - { - Parser *parser = builder.build(); - TS_ASSERT(parser != NULL); - - api::Term e = parser->nextExpression(); - TS_ASSERT(e.isNull()); - - delete parser; - } - - void checkTrueInput(ParserBuilder &builder) - { - Parser *parser = builder.build(); - TS_ASSERT(parser != NULL); - - api::Term e = parser->nextExpression(); - TS_ASSERT_EQUALS(e, d_solver->mkTrue()); - - e = parser->nextExpression(); - TS_ASSERT(e.isNull()); - delete parser; - } - - char *mkTemp() - { - char *filename = strdup("/tmp/testinput.XXXXXX"); - int fd = mkstemp(filename); - TS_ASSERT(fd != -1); - close(fd); - return filename; - } - - std::unique_ptr d_solver; - std::unique_ptr d_symman; - -}; // class ParserBuilderBlack -- 2.30.2