summaryrefslogtreecommitdiff
path: root/test/unit/parser/parser_builder_black.h
blob: 78e1be7482480086230df43834c734e710bddc79 (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
/*********************                                                        */
/*! \file parser_builder_black.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Christopher L. Conway, Aina Niemetz, Tim King
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2019 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.\endverbatim
 **
 ** \brief Black box testing of CVC4::parser::ParserBuilder.
 **
 ** Black box testing of CVC4::parser::ParserBuilder.
 **/

#include <cxxtest/TestSuite.h>

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

#include <fstream>
#include <iostream>

#include "api/cvc4cpp.h"
#include "options/language.h"
#include "parser/parser.h"
#include "parser/parser_builder.h"
#include "smt/command.h"

using namespace CVC4;
using namespace CVC4::parser;
using namespace CVC4::language::input;
using namespace std;

class ParserBuilderBlack : public CxxTest::TestSuite
{
 public:
  void setUp() override { d_solver.reset(new api::Solver()); }

  void tearDown() override {}

  void testEmptyFileInput()
  {
    char *filename = mkTemp();

    checkEmptyInput(
        ParserBuilder(d_solver.get(), filename).withInputLanguage(LANG_CVC4));

    remove(filename);
    free(filename);
  }

  void testSimpleFileInput() {
    char *filename = mkTemp();

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

    checkTrueInput(
        ParserBuilder(d_solver.get(), filename).withInputLanguage(LANG_CVC4));

    remove(filename);
    free(filename);
  }

  void testEmptyStringInput() {
    checkEmptyInput(ParserBuilder(d_solver.get(), "foo")
                        .withInputLanguage(LANG_CVC4)
                        .withStringInput(""));
  }

  void testTrueStringInput() {
    checkTrueInput(ParserBuilder(d_solver.get(), "foo")
                       .withInputLanguage(LANG_CVC4)
                       .withStringInput("TRUE"));
  }

  void testEmptyStreamInput() {
    stringstream ss( "", ios_base::in );
    checkEmptyInput(ParserBuilder(d_solver.get(), "foo")
                        .withInputLanguage(LANG_CVC4)
                        .withStreamInput(ss));
  }

  void testTrueStreamInput() {
    stringstream ss( "TRUE", ios_base::in );
    checkTrueInput(ParserBuilder(d_solver.get(), "foo")
                       .withInputLanguage(LANG_CVC4)
                       .withStreamInput(ss));
  }

 private:
  void checkEmptyInput(ParserBuilder &builder)
  {
    Parser *parser = builder.build();
    TS_ASSERT(parser != NULL);

    Expr e = parser->nextExpression();
    TS_ASSERT(e.isNull());

    delete parser;
  }

  void checkTrueInput(ParserBuilder &builder)
  {
    Parser *parser = builder.build();
    TS_ASSERT(parser != NULL);

    Expr e = parser->nextExpression();
    TS_ASSERT_EQUALS(e, d_solver->getExprManager()->mkConst(true));

    e = parser->nextExpression();
    TS_ASSERT(e.isNull());
    delete parser;
  }

  char *mkTemp()
  {
    char *filename = strdup("/tmp/testinput.XXXXXX");
    int fd = mkstemp(filename);
    TS_ASSERT(fd != -1);
    close(fd);
    return filename;
  }

  std::unique_ptr<api::Solver> d_solver;

}; // class ParserBuilderBlack
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback