Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/PostOrderDeserializerTest.java @ 13461:52eb34dd84d7
JS: fix, evaluating jboolean directly gives a warning (and thus error) on Windows
author | Christian Wirth <christian.wirth@oracle.com> |
---|---|
date | Wed, 18 Dec 2013 17:33:00 +0100 |
parents | 96c1d057a5ed |
children | 97321295c974 |
rev | line source |
---|---|
12388
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test.nodes.serial; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.nio.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import java.util.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.nodes.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.nodes.serial.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.test.nodes.serial.TestNodes.EmptyNode; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithArray; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithFields; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithOneChild; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithThreeChilds; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithTwoArray; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithTwoChilds; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 import com.oracle.truffle.api.test.nodes.serial.TestNodes.StringNode; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 public class PostOrderDeserializerTest { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 private PostOrderDeserializer d; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 private TestSerializerConstantPool cp; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 @Before |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 public void setUp() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 cp = new TestSerializerConstantPool(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 d = new PostOrderDeserializer(cp); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 @After |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 public void tearDown() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 d = null; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 cp = null; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 private Node deserialize(byte[] bytes) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 return d.deserialize(bytes, Node.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 public void testNull() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 createCP(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 Node ast = deserialize(createBytes(VariableLengthIntBuffer.NULL)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 Assert.assertNull(ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 public void testSingleNode() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 createCP(EmptyNode.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 Node expectedAst = new EmptyNode(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 Node ast = deserialize(createBytes(0)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 public void testThreeChilds() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 createCP(EmptyNode.class, NodeWithThreeChilds.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 Node expectedAst = new NodeWithThreeChilds(new EmptyNode(), null, new EmptyNode()); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 Node ast = deserialize(createBytes(0, VariableLengthIntBuffer.NULL, 0, 1)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 public void testFields() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 createCP(NodeWithFields.class, "test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE, |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 (int) Character.MIN_VALUE, (int) Character.MAX_VALUE, (int) Short.MIN_VALUE, (int) Short.MAX_VALUE, (int) Byte.MIN_VALUE, (int) Byte.MAX_VALUE, 1); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 NodeWithFields expectedAst = new NodeWithFields("test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE, |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 Double.MAX_VALUE, Character.MIN_VALUE, Character.MAX_VALUE, Short.MIN_VALUE, Short.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE, Boolean.TRUE, Boolean.FALSE); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 Node ast = deserialize(createBytes(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 10)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 public void testFieldsNull() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 createCP(NodeWithFields.class, "test", 0, 0L, 0.0F, 0.0D); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 NodeWithFields expectedAst = new NodeWithFields("test", 0, null, 0L, null, 0f, null, 0d, null, (char) 0, null, (short) 0, null, (byte) 0, null, false, null); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 int nil = VariableLengthIntBuffer.NULL; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 Node ast = deserialize(createBytes(0, 1, 2, nil, 3, nil, 4, nil, 5, nil, 2, nil, 2, nil, 2, nil, 2, nil)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 public void testNullChilds() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 createCP(Node[].class, NodeWithArray.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 Node expectedAst = new NodeWithArray(null); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 Node ast = deserialize(createBytes(0, VariableLengthIntBuffer.NULL, 1)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 public void testNChilds() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 Node expectedAst = new NodeWithArray(new Node[]{new EmptyNode(), new NodeWithArray(new Node[]{new EmptyNode(), new EmptyNode(), new EmptyNode()}), new EmptyNode(), new EmptyNode()}); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 createCP(Node[].class, 4, EmptyNode.class, 3, NodeWithArray.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 Node ast = deserialize(createBytes(0, 1, 2, 0, 3, 2, 2, 2, 4, 2, 2, 4)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 public void test2xNChilds() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 Node expectedAst = new NodeWithTwoArray(new Node[]{new StringNode("a0"), new StringNode("a1")}, new Node[]{new StringNode("b0"), new StringNode("b1"), new StringNode("b2")}); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 createCP(Node[].class, 2, StringNode.class, "a0", "a1", 3, "b0", "b1", "b2", NodeWithTwoArray.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 Node ast = deserialize(createBytes(0, 1, 2, 3, 2, 4, 0, 5, 2, 6, 2, 7, 2, 8, 9)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 public void testBug0() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 Node expectedAst = new NodeWithArray(new Node[]{new NodeWithOneChild(new EmptyNode())}); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 createCP(Node[].class, 1, EmptyNode.class, NodeWithOneChild.class, NodeWithArray.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 Node ast = deserialize(createBytes(0, 1, 2, 3, 4)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 public void testBug1() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 Node expectedAst = new NodeWithArray(new Node[]{new NodeWithTwoChilds(new EmptyNode(), new EmptyNode())}); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 createCP(Node[].class, 1, EmptyNode.class, NodeWithTwoChilds.class, NodeWithArray.class); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 Node ast = deserialize(createBytes(0, 1, 2, 2, 3, 4)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 assertAST(expectedAst, ast); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 private static void assertAST(Node expectedAst, Node actualAst) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 if (expectedAst == null) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 Assert.assertNull(actualAst); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 return; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
154 Assert.assertNotNull(actualAst); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 // fields are asserted using the corresponding equals implementation |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 Assert.assertEquals(expectedAst, actualAst); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 Iterable<Node> expectedChildIterator = expectedAst.getChildren(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 Iterator<Node> actualChildIterator = actualAst.getChildren().iterator(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 for (Node node : expectedChildIterator) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 Assert.assertTrue(actualChildIterator.hasNext()); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
162 assertAST(node, actualChildIterator.next()); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 Assert.assertFalse(actualChildIterator.hasNext()); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 private static byte[] createBytes(int... refs) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 VariableLengthIntBuffer buf = new VariableLengthIntBuffer(ByteBuffer.allocate(512)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 for (int i = 0; i < refs.length; i++) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 buf.put(refs[i]); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
171 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
172 return buf.getBytes(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
173 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
174 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
175 private void createCP(Object... cpData) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
176 for (int i = 0; i < cpData.length; i++) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
177 Object object = cpData[i]; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
178 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 cp.putObject(object.getClass(), object); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
182 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
183 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 } |