Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/VariableLengthIntBufferTest.java @ 15462:05d3f069cff2
fixed pylint warning
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 02 May 2014 00:17:40 +0200 |
parents | 96c1d057a5ed |
children |
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 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import org.junit.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.nodes.serial.*; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 public class VariableLengthIntBufferTest { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 private VariableLengthIntBuffer buf; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 @Before |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public void setUp() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 buf = new VariableLengthIntBuffer(ByteBuffer.allocate(512)); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 @After |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 public void tearDown() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 buf = null; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 public void testPutNull() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 buf.put(VariableLengthIntBuffer.NULL); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 assertBytes(0xFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 } |
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 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 public void testPutByteCornerCase0() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 buf.put(0x00); // 0 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 assertBytes(0x00); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
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 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 public void testPutByteCornerCase1() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 buf.put(0x7F); // 127 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 assertBytes(0x7F); |
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 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 public void testPutByteCornerCase2() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 buf.put(0x3FFF_FFFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 assertBytes(0xBF, 0xFF, 0xFF, 0xFF); |
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(expected = IllegalArgumentException.class) |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 public void testPutByteCornerCase3() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 buf.put(0x4000_0000); // out of encodeable |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 public void testGetNull() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 create(0xFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 assertGet(VariableLengthIntBuffer.NULL); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 public void testGetCornerCase0() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 create(0x00); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 assertGet(0x00); |
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 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 public void testGetCornerCase1() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 create(0x7F); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 assertGet(0x7F); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 @Test |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 public void testGetCornerCase2() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 create(0xBF, 0xFF, 0xFF, 0xFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 assertGet(0x3FFF_FFFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 @Test(expected = AssertionError.class) |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 public void testGetCornerCase3() { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 create(0xFF, 0xFF, 0xFF, 0xFF); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 assertGet(0x0); |
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 private void create(int... bytes) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 byte[] convBytes = new byte[bytes.length]; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 for (int i = 0; i < bytes.length; i++) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 convBytes[i] = (byte) bytes[i]; |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 buf = new VariableLengthIntBuffer(convBytes); |
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 private void assertGet(int expected) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 Assert.assertEquals(expected, buf.get()); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 private void assertBytes(int... expectedBytes) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 byte[] actualBytes = buf.getBytes(); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 Assert.assertEquals(expectedBytes.length, actualBytes.length); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 for (int i = 0; i < expectedBytes.length; i++) { |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 Assert.assertTrue(actualBytes[i] == (byte) expectedBytes[i]); |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 } |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 |
96c1d057a5ed
Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 } |