GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/parser/parser_builder_black.cpp Lines: 72 72 100.0 %
Date: 2021-09-29 Branches: 95 230 41.3 %

Line Exec Source
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 "smt/command.h"
30
#include "test_api.h"
31
32
namespace cvc5 {
33
34
using namespace parser;
35
36
namespace test {
37
38
24
class TestParseBlackParserBuilder : public TestApi
39
{
40
 protected:
41
12
  void SetUp() override { d_symman.reset(new SymbolManager(&d_solver)); }
42
43
6
  void checkEmptyInput(Parser* parser)
44
  {
45
12
    api::Term e = parser->nextExpression();
46
6
    ASSERT_TRUE(e.isNull());
47
  }
48
49
6
  void checkInput(Parser* parser, const std::string& expected)
50
  {
51
6
    Command* cmd = parser->nextCommand();
52
6
    ASSERT_NE(cmd, nullptr);
53
6
    ASSERT_EQ(cmd->toString(), expected);
54
6
    delete cmd;
55
56
6
    cmd = parser->nextCommand();
57
6
    ASSERT_EQ(cmd, nullptr);
58
    // e = parser->nextExpression();
59
    // ASSERT_TRUE(e.isNull());
60
  }
61
62
4
  char* mkTemp()
63
  {
64
4
    char* filename = strdup("/tmp/testinput.XXXXXX");
65
4
    int32_t fd = mkstemp(filename);
66
4
    if (fd == -1) return nullptr;
67
4
    close(fd);
68
4
    return filename;
69
  }
70
  std::unique_ptr<SymbolManager> d_symman;
71
};
72
73
15
TEST_F(TestParseBlackParserBuilder, empty_file_input)
74
{
75
2
  char* filename = mkTemp();
76
2
  ASSERT_NE(filename, nullptr);
77
78
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
79
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
80
4
                                     .build());
81
2
  parser->setInput(Input::newFileInput("LANG_SMTLIB_V2_6", filename, false));
82
2
  checkEmptyInput(parser.get());
83
84
2
  remove(filename);
85
2
  free(filename);
86
}
87
88
15
TEST_F(TestParseBlackParserBuilder, simple_file_input)
89
{
90
2
  char* filename = mkTemp();
91
92
4
  std::fstream fs(filename, std::fstream::out);
93
2
  fs << "(set-logic ALL)" << std::endl;
94
2
  fs.close();
95
96
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
97
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
98
4
                                     .build());
99
2
  parser->setInput(Input::newFileInput("LANG_SMTLIB_V2_6", filename, false));
100
2
  checkInput(parser.get(), "(set-logic ALL)\n");
101
102
2
  remove(filename);
103
2
  free(filename);
104
2
}
105
106
15
TEST_F(TestParseBlackParserBuilder, empty_string_input)
107
{
108
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
109
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
110
4
                                     .build());
111
2
  parser->setInput(Input::newStringInput("LANG_SMTLIB_V2_6", "", "foo"));
112
2
  checkEmptyInput(parser.get());
113
2
}
114
115
15
TEST_F(TestParseBlackParserBuilder, true_string_input)
116
{
117
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
118
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
119
4
                                     .build());
120
2
  parser->setInput(
121
      Input::newStringInput("LANG_SMTLIB_V2_6", "(assert true)", "foo"));
122
2
  checkInput(parser.get(), "(assert true)\n");
123
2
}
124
125
15
TEST_F(TestParseBlackParserBuilder, empty_stream_input)
126
{
127
4
  std::stringstream ss("", std::ios_base::in);
128
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
129
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
130
4
                                     .build());
131
2
  parser->setInput(Input::newStreamInput("LANG_SMTLIB_V2_6", ss, "foo"));
132
2
  checkEmptyInput(parser.get());
133
2
}
134
135
15
TEST_F(TestParseBlackParserBuilder, true_stream_input)
136
{
137
4
  std::stringstream ss("(assert false)", std::ios_base::in);
138
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get(), false)
139
4
                                     .withInputLanguage("LANG_SMTLIB_V2_6")
140
4
                                     .build());
141
2
  parser->setInput(Input::newStreamInput("LANG_SMTLIB_V2_6", ss, "foo"));
142
2
  checkInput(parser.get(), "(assert false)\n");
143
2
}
144
145
}  // namespace test
146
21
}  // namespace cvc5