summaryrefslogtreecommitdiff
path: root/test/unit/node/attribute_black.cpp
blob: 487798e49f556eba3e104221eceea4f19244a4c2 (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
/*********************                                                        */
/*! \file attribute_black.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Aina Niemetz, Tim King, Morgan Deters
 ** This file is part of the CVC4 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.\endverbatim
 **
 ** \brief Black box testing of CVC4::Attribute.
 **
 ** Black box testing of CVC4::Attribute.
 **/

#include <sstream>
#include <vector>

#include "expr/attribute.h"
#include "expr/node.h"
#include "expr/node_builder.h"
#include "expr/node_value.h"
#include "test_node.h"

namespace CVC4 {

using namespace kind;
using namespace smt;

namespace test {

class TestNodeBlackAttribute : public TestNode
{
 protected:
  struct PrimitiveIntAttributeId
  {
  };
  using PrimitiveIntAttribute =
      expr::Attribute<PrimitiveIntAttributeId, uint64_t>;
  struct TNodeAttributeId
  {
  };
  using TNodeAttribute = expr::Attribute<TNodeAttributeId, TNode>;
  struct StringAttributeId
  {
  };
  using StringAttribute = expr::Attribute<StringAttributeId, std::string>;
  struct BoolAttributeId
  {
  };
  using BoolAttribute = expr::Attribute<BoolAttributeId, bool>;
};

TEST_F(TestNodeBlackAttribute, ints)
{
  TypeNode booleanType = d_nodeManager->booleanType();
  Node* node = new Node(d_nodeManager->mkSkolem("b", booleanType));
  const uint64_t val = 63489;
  uint64_t data0 = 0;
  uint64_t data1 = 0;

  PrimitiveIntAttribute attr;
  ASSERT_FALSE(node->getAttribute(attr, data0));
  node->setAttribute(attr, val);
  ASSERT_TRUE(node->getAttribute(attr, data1));
  ASSERT_EQ(data1, val);

  delete node;
}

TEST_F(TestNodeBlackAttribute, tnodes)
{
  TypeNode booleanType = d_nodeManager->booleanType();
  Node* node = new Node(d_nodeManager->mkSkolem("b", booleanType));

  Node val(d_nodeManager->mkSkolem("b", booleanType));
  TNode data0;
  TNode data1;

  TNodeAttribute attr;
  ASSERT_FALSE(node->getAttribute(attr, data0));
  node->setAttribute(attr, val);
  ASSERT_TRUE(node->getAttribute(attr, data1));
  ASSERT_EQ(data1, val);

  delete node;
}

TEST_F(TestNodeBlackAttribute, strings)
{
  TypeNode booleanType = d_nodeManager->booleanType();
  Node* node = new Node(d_nodeManager->mkSkolem("b", booleanType));

  std::string val("63489");
  std::string data0;
  std::string data1;

  StringAttribute attr;
  ASSERT_FALSE(node->getAttribute(attr, data0));
  node->setAttribute(attr, val);
  ASSERT_TRUE(node->getAttribute(attr, data1));
  ASSERT_EQ(data1, val);

  delete node;
}

TEST_F(TestNodeBlackAttribute, bools)
{
  TypeNode booleanType = d_nodeManager->booleanType();
  Node* node = new Node(d_nodeManager->mkSkolem("b", booleanType));

  bool val = true;
  bool data0 = false;
  bool data1 = false;

  BoolAttribute attr;
  ASSERT_TRUE(node->getAttribute(attr, data0));
  ASSERT_EQ(false, data0);
  node->setAttribute(attr, val);
  ASSERT_TRUE(node->getAttribute(attr, data1));
  ASSERT_EQ(data1, val);

  delete node;
}

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