GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/parser/parser_builder_black.cpp Lines: 70 70 100.0 %
Date: 2021-08-17 Branches: 78 188 41.5 %

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 "test_api.h"
30
31
namespace cvc5 {
32
33
using namespace parser;
34
using namespace language::input;
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 checkTrueInput(Parser* parser)
50
  {
51
12
    api::Term e = parser->nextExpression();
52
6
    ASSERT_EQ(e, d_solver.mkTrue());
53
54
6
    e = parser->nextExpression();
55
6
    ASSERT_TRUE(e.isNull());
56
  }
57
58
4
  char* mkTemp()
59
  {
60
4
    char* filename = strdup("/tmp/testinput.XXXXXX");
61
4
    int32_t fd = mkstemp(filename);
62
4
    if (fd == -1) return nullptr;
63
4
    close(fd);
64
4
    return filename;
65
  }
66
  std::unique_ptr<SymbolManager> d_symman;
67
};
68
69
15
TEST_F(TestParseBlackParserBuilder, empty_file_input)
70
{
71
2
  char* filename = mkTemp();
72
2
  ASSERT_NE(filename, nullptr);
73
74
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
75
2
                                     .withInputLanguage(LANG_CVC)
76
4
                                     .build());
77
2
  parser->setInput(Input::newFileInput(LANG_CVC, filename, false));
78
2
  checkEmptyInput(parser.get());
79
80
2
  remove(filename);
81
2
  free(filename);
82
}
83
84
15
TEST_F(TestParseBlackParserBuilder, simple_file_input)
85
{
86
2
  char* filename = mkTemp();
87
88
4
  std::fstream fs(filename, std::fstream::out);
89
2
  fs << "TRUE" << std::endl;
90
2
  fs.close();
91
92
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
93
2
                                     .withInputLanguage(LANG_CVC)
94
4
                                     .build());
95
2
  parser->setInput(Input::newFileInput(LANG_CVC, filename, false));
96
2
  checkTrueInput(parser.get());
97
98
2
  remove(filename);
99
2
  free(filename);
100
2
}
101
102
15
TEST_F(TestParseBlackParserBuilder, empty_string_input)
103
{
104
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
105
2
                                     .withInputLanguage(LANG_CVC)
106
4
                                     .build());
107
2
  parser->setInput(Input::newStringInput(LANG_CVC, "", "foo"));
108
2
  checkEmptyInput(parser.get());
109
2
}
110
111
15
TEST_F(TestParseBlackParserBuilder, true_string_input)
112
{
113
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
114
2
                                     .withInputLanguage(LANG_CVC)
115
4
                                     .build());
116
2
  parser->setInput(Input::newStringInput(LANG_CVC, "TRUE", "foo"));
117
2
  checkTrueInput(parser.get());
118
2
}
119
120
15
TEST_F(TestParseBlackParserBuilder, empty_stream_input)
121
{
122
4
  std::stringstream ss("", std::ios_base::in);
123
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
124
2
                                     .withInputLanguage(LANG_CVC)
125
4
                                     .build());
126
2
  parser->setInput(Input::newStreamInput(LANG_CVC, ss, "foo"));
127
2
  checkEmptyInput(parser.get());
128
2
}
129
130
15
TEST_F(TestParseBlackParserBuilder, true_stream_input)
131
{
132
4
  std::stringstream ss("TRUE", std::ios_base::in);
133
4
  std::unique_ptr<Parser> parser(ParserBuilder(&d_solver, d_symman.get())
134
2
                                     .withInputLanguage(LANG_CVC)
135
4
                                     .build());
136
2
  parser->setInput(Input::newStreamInput(LANG_CVC, ss, "foo"));
137
2
  checkTrueInput(parser.get());
138
2
}
139
140
}  // namespace test
141
21
}  // namespace cvc5