1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Aina Niemetz, Christopher L. Conway, Tim King |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Black box testing of cvc5::parser::ParserBuilder. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include <stdio.h> |
17 |
|
#include <string.h> |
18 |
|
#include <sys/stat.h> |
19 |
|
#include <unistd.h> |
20 |
|
|
21 |
|
#include <fstream> |
22 |
|
#include <iostream> |
23 |
|
|
24 |
|
#include "api/cpp/cvc5.h" |
25 |
|
#include "expr/symbol_manager.h" |
26 |
|
#include "options/language.h" |
27 |
|
#include "parser/parser.h" |
28 |
|
#include "parser/parser_builder.h" |
29 |
|
#include "test_api.h" |
30 |
|
|
31 |
|
namespace cvc5 { |
32 |
|
|
33 |
|
using namespace parser; |
34 |
|
|
35 |
|
namespace test { |
36 |
|
|
37 |
24 |
class TestParseBlackParserBuilder : public TestApi |
38 |
|
{ |
39 |
|
protected: |
40 |
12 |
void SetUp() override { d_symman.reset(new SymbolManager(&d_solver)); } |
41 |
|
|
42 |
6 |
void checkEmptyInput(Parser* parser) |
43 |
|
{ |
44 |
12 |
api::Term e = parser->nextExpression(); |
45 |
6 |
ASSERT_TRUE(e.isNull()); |
46 |
|
} |
47 |
|
|
48 |
6 |
void checkTrueInput(Parser* parser) |
49 |
|
{ |
50 |
12 |
api::Term e = parser->nextExpression(); |
51 |
6 |
ASSERT_EQ(e, d_solver.mkTrue()); |
52 |
|
|
53 |
6 |
e = parser->nextExpression(); |
54 |
6 |
ASSERT_TRUE(e.isNull()); |
55 |
|
} |
56 |
|
|
57 |
4 |
char* mkTemp() |
58 |
|
{ |
59 |
4 |
char* filename = strdup("/tmp/testinput.XXXXXX"); |
60 |
4 |
int32_t fd = mkstemp(filename); |
61 |
4 |
if (fd == -1) return nullptr; |
62 |
4 |
close(fd); |
63 |
4 |
return filename; |
64 |
|
} |
65 |
|
std::unique_ptr<SymbolManager> d_symman; |
66 |
|
}; |
67 |
|
|
68 |
15 |
TEST_F(TestParseBlackParserBuilder, empty_file_input) |
69 |
|
{ |
70 |
2 |
char* filename = mkTemp(); |
71 |
2 |
ASSERT_NE(filename, nullptr); |
72 |
|
|
73 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
74 |
4 |
.withInputLanguage("LANG_CVC") |
75 |
4 |
.build()); |
76 |
2 |
parser->setInput(Input::newFileInput("LANG_CVC", filename, false)); |
77 |
2 |
checkEmptyInput(parser.get()); |
78 |
|
|
79 |
2 |
remove(filename); |
80 |
2 |
free(filename); |
81 |
|
} |
82 |
|
|
83 |
15 |
TEST_F(TestParseBlackParserBuilder, simple_file_input) |
84 |
|
{ |
85 |
2 |
char* filename = mkTemp(); |
86 |
|
|
87 |
4 |
std::fstream fs(filename, std::fstream::out); |
88 |
2 |
fs << "TRUE" << std::endl; |
89 |
2 |
fs.close(); |
90 |
|
|
91 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
92 |
4 |
.withInputLanguage("LANG_CVC") |
93 |
4 |
.build()); |
94 |
2 |
parser->setInput(Input::newFileInput("LANG_CVC", filename, false)); |
95 |
2 |
checkTrueInput(parser.get()); |
96 |
|
|
97 |
2 |
remove(filename); |
98 |
2 |
free(filename); |
99 |
2 |
} |
100 |
|
|
101 |
15 |
TEST_F(TestParseBlackParserBuilder, empty_string_input) |
102 |
|
{ |
103 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
104 |
4 |
.withInputLanguage("LANG_CVC") |
105 |
4 |
.build()); |
106 |
2 |
parser->setInput(Input::newStringInput("LANG_CVC", "", "foo")); |
107 |
2 |
checkEmptyInput(parser.get()); |
108 |
2 |
} |
109 |
|
|
110 |
15 |
TEST_F(TestParseBlackParserBuilder, true_string_input) |
111 |
|
{ |
112 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
113 |
4 |
.withInputLanguage("LANG_CVC") |
114 |
4 |
.build()); |
115 |
2 |
parser->setInput(Input::newStringInput("LANG_CVC", "TRUE", "foo")); |
116 |
2 |
checkTrueInput(parser.get()); |
117 |
2 |
} |
118 |
|
|
119 |
15 |
TEST_F(TestParseBlackParserBuilder, empty_stream_input) |
120 |
|
{ |
121 |
4 |
std::stringstream ss("", std::ios_base::in); |
122 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
123 |
4 |
.withInputLanguage("LANG_CVC") |
124 |
4 |
.build()); |
125 |
2 |
parser->setInput(Input::newStreamInput("LANG_CVC", ss, "foo")); |
126 |
2 |
checkEmptyInput(parser.get()); |
127 |
2 |
} |
128 |
|
|
129 |
15 |
TEST_F(TestParseBlackParserBuilder, true_stream_input) |
130 |
|
{ |
131 |
4 |
std::stringstream ss("TRUE", std::ios_base::in); |
132 |
4 |
std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false) |
133 |
4 |
.withInputLanguage("LANG_CVC") |
134 |
4 |
.build()); |
135 |
2 |
parser->setInput(Input::newStreamInput("LANG_CVC", ss, "foo")); |
136 |
2 |
checkTrueInput(parser.get()); |
137 |
2 |
} |
138 |
|
|
139 |
|
} // namespace test |
140 |
21 |
} // namespace cvc5 |