Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/node.h" | 5 #include "src/compiler/node.h" |
| 6 #include "src/compiler/operator.h" | 6 #include "src/compiler/operator.h" |
| 7 #include "test/unittests/test-utils.h" | 7 #include "test/unittests/test-utils.h" |
| 8 #include "testing/gmock-support.h" | 8 #include "testing/gmock-support.h" |
| 9 | 9 |
| 10 using testing::ElementsAre; | 10 using testing::ElementsAre; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 EXPECT_EQ(1, node->id()); | 35 EXPECT_EQ(1, node->id()); |
| 36 EXPECT_EQ(0, node->UseCount()); | 36 EXPECT_EQ(0, node->UseCount()); |
| 37 EXPECT_TRUE(node->uses().empty()); | 37 EXPECT_TRUE(node->uses().empty()); |
| 38 EXPECT_EQ(0, node->InputCount()); | 38 EXPECT_EQ(0, node->InputCount()); |
| 39 EXPECT_TRUE(node->inputs().empty()); | 39 EXPECT_TRUE(node->inputs().empty()); |
| 40 EXPECT_EQ(&kOp0, node->op()); | 40 EXPECT_EQ(&kOp0, node->op()); |
| 41 EXPECT_EQ(kOpcode0, node->opcode()); | 41 EXPECT_EQ(kOpcode0, node->opcode()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 // TODO(titzer): stupid test is stupid. | |
| 46 static Node* UseAt(Node* node, int index) { | |
|
Benedikt Meurer
2015/03/19 09:46:23
There should be no need for this helper method.
titzer
2015/03/19 10:10:31
Done.
| |
| 47 for (Node* use : node->uses()) { | |
| 48 if (index-- <= 0) return use; | |
| 49 } | |
| 50 return nullptr; | |
| 51 } | |
| 52 | |
| 53 | |
| 45 TEST_F(NodeTest, NewWithInputs) { | 54 TEST_F(NodeTest, NewWithInputs) { |
| 46 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false); | 55 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false); |
| 47 EXPECT_EQ(0, n0->UseCount()); | 56 EXPECT_EQ(0, n0->UseCount()); |
| 48 EXPECT_EQ(0, n0->InputCount()); | 57 EXPECT_EQ(0, n0->InputCount()); |
| 49 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false); | 58 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false); |
| 50 EXPECT_EQ(1, n0->UseCount()); | 59 EXPECT_EQ(1, n0->UseCount()); |
| 51 EXPECT_EQ(n1, n0->UseAt(0)); | 60 EXPECT_EQ(n1, UseAt(n0, 0)); |
|
Michael Starzinger
2015/03/19 09:40:09
Can we use EXPECT_THAT(n1->uses(), ElementsAre(n0)
titzer
2015/03/19 10:10:31
Done.
| |
| 52 EXPECT_EQ(0, n1->UseCount()); | 61 EXPECT_EQ(0, n1->UseCount()); |
| 53 EXPECT_EQ(1, n1->InputCount()); | 62 EXPECT_EQ(1, n1->InputCount()); |
| 54 EXPECT_EQ(n0, n1->InputAt(0)); | 63 EXPECT_EQ(n0, n1->InputAt(0)); |
| 55 Node* n0_n1[] = {n0, n1}; | 64 Node* n0_n1[] = {n0, n1}; |
| 56 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false); | 65 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false); |
| 57 EXPECT_EQ(2, n0->UseCount()); | 66 EXPECT_EQ(2, n0->UseCount()); |
| 58 EXPECT_EQ(n1, n0->UseAt(0)); | 67 EXPECT_EQ(n1, UseAt(n0, 1)); |
|
Michael Starzinger
2015/03/19 09:40:08
Can we use EXPECT_THAT(n0->uses(), ElementsAre(n0,
titzer
2015/03/19 10:10:31
Done.
| |
| 59 EXPECT_EQ(n2, n0->UseAt(1)); | 68 EXPECT_EQ(n2, UseAt(n1, 0)); |
| 60 EXPECT_EQ(2, n2->InputCount()); | 69 EXPECT_EQ(2, n2->InputCount()); |
| 61 EXPECT_EQ(n0, n2->InputAt(0)); | 70 EXPECT_EQ(n0, n2->InputAt(0)); |
| 62 EXPECT_EQ(n1, n2->InputAt(1)); | 71 EXPECT_EQ(n1, n2->InputAt(1)); |
| 63 } | 72 } |
| 64 | 73 |
| 65 | 74 |
| 66 TEST_F(NodeTest, InputIteratorEmpty) { | 75 TEST_F(NodeTest, InputIteratorEmpty) { |
| 67 Node* node = Node::New(zone(), 0, &kOp0, 0, nullptr, false); | 76 Node* node = Node::New(zone(), 0, &kOp0, 0, nullptr, false); |
| 68 EXPECT_EQ(node->inputs().begin(), node->inputs().end()); | 77 EXPECT_EQ(node->inputs().begin(), node->inputs().end()); |
| 69 } | 78 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0)); | 170 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0)); |
| 162 node->AppendInput(zone(), n0); | 171 node->AppendInput(zone(), n0); |
| 163 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0)); | 172 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0)); |
| 164 node->AppendInput(zone(), n1); | 173 node->AppendInput(zone(), n1); |
| 165 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0, n1)); | 174 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0, n1)); |
| 166 } | 175 } |
| 167 | 176 |
| 168 } // namespace compiler | 177 } // namespace compiler |
| 169 } // namespace internal | 178 } // namespace internal |
| 170 } // namespace v8 | 179 } // namespace v8 |
| OLD | NEW |