summaryrefslogtreecommitdiff
path: root/test/unit/parser/parser_black.cpp
blob: 6a3cc03a5c39cd68660b97b8f851e86b16d28d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/******************************************************************************
 * Top contributors (to current version):
 *   Aina Niemetz, Christopher L. Conway, Tim King
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 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.
 * ****************************************************************************
 *
 * Black box testing of cvc5::parser::ParserBuilder.
 */

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <fstream>
#include <iostream>

#include "api/cpp/cvc5.h"
#include "expr/symbol_manager.h"
#include "options/language.h"
#include "parser/input_parser.h"
#include "parser/parser.h"
#include "test_api.h"

namespace cvc5 {

using namespace parser;
using namespace language::input;

namespace test {

class TestParserBlackParser : public TestApi
{
 protected:
  void SetUp() override { d_symman.reset(new SymbolManager(&d_solver)); }

  void checkEmptyInput(InputParser* inputParser)
  {
    api::Term e = inputParser->nextExpression();
    ASSERT_TRUE(e.isNull());
  }

  void checkTrueInput(InputParser* inputParser)
  {
    api::Term e = inputParser->nextExpression();
    ASSERT_EQ(e, d_solver.mkTrue());

    e = inputParser->nextExpression();
    ASSERT_TRUE(e.isNull());
  }

  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<SymbolManager> d_symman;
};

TEST_F(TestParserBlackParser, empty_file_input)
{
  char* filename = mkTemp();
  ASSERT_NE(filename, nullptr);

  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseFile(filename, false);
  checkEmptyInput(inputParser.get());

  remove(filename);
  free(filename);
}

TEST_F(TestParserBlackParser, simple_file_input)
{
  char* filename = mkTemp();

  std::fstream fs(filename, std::fstream::out);
  fs << "TRUE" << std::endl;
  fs.close();

  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseFile(filename, false);
  checkTrueInput(inputParser.get());

  remove(filename);
  free(filename);
}

TEST_F(TestParserBlackParser, empty_string_input)
{
  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseString("foo", "");
  checkEmptyInput(inputParser.get());
}

TEST_F(TestParserBlackParser, true_string_input)
{
  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseString("foo", "TRUE");
  checkTrueInput(inputParser.get());
}

TEST_F(TestParserBlackParser, empty_stream_input)
{
  std::stringstream ss("", std::ios_base::in);
  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseStream("foo", ss);
  checkEmptyInput(inputParser.get());
}

TEST_F(TestParserBlackParser, true_stream_input)
{
  std::stringstream ss("TRUE", std::ios_base::in);
  Options options;
  options.setInputLanguage(LANG_CVC);
  Parser parser(&d_solver, d_symman.get(), options);
  std::unique_ptr<InputParser> inputParser = parser.parseStream("foo", ss);
  checkTrueInput(inputParser.get());
}

}  // namespace test
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback