Debian Codegraph @

src/test/java/io/airlift/slice/TestSliceOutput.java

raw
1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14 package io.airlift.slice;
15
16 import org.testng.annotations.Test;
17
18 import static org.testng.Assert.assertEquals;
19
20 public class TestSliceOutput
21 {
22 @Test
23 public void testAppendByte()
24 throws Exception
25 {
26 for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
27 Slice actual = new DynamicSliceOutput(1)
28 .appendByte(i)
29 .slice();
30
31 Slice expected = Slices.wrappedBuffer(new byte[] {(byte) i});
32
33 assertEquals(actual, expected);
34 }
35 }
36
37 @Test
38 public void testAppendUnsignedByte()
39 throws Exception
40 {
41 for (int i = 0; i < 256; i++) {
42 Slice actual = new DynamicSliceOutput(1)
43 .appendByte(i)
44 .slice();
45
46 Slice expected = Slices.wrappedBuffer(new byte[] {(byte) i});
47
48 assertEquals(actual, expected);
49 }
50 }
51
52 @Test
53 public void testAppendByteTruncation()
54 throws Exception
55 {
56 for (int i = 256; i < 512; i++) {
57 Slice actual = new DynamicSliceOutput(1)
58 .appendByte(i)
59 .slice();
60
61 Slice expected = Slices.wrappedBuffer(new byte[] {(byte) i});
62
63 assertEquals(actual, expected);
64 }
65 }
66
67 @Test
68 public void testAppendMultiple()
69 throws Exception
70 {
71 Slice actual = new DynamicSliceOutput(1)
72 .appendByte(0)
73 .appendByte(1)
74 .appendByte(2)
75 .appendByte(3)
76 .appendByte(4)
77 .slice();
78
79 Slice expected = Slices.wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 });
80 assertEquals(actual, expected);
81 }
82 }