GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/parser/parser_builder_black.cpp Lines: 56 56 100.0 %
Date: 2021-03-23 Branches: 74 196 37.8 %

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