|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 Muhammad Tayyab Akram |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.mta.tehreer.internal.collections; |
| 18 | + |
| 19 | +import com.mta.tehreer.collections.IntListTestSuite; |
| 20 | +import com.mta.tehreer.internal.Memory; |
| 21 | + |
| 22 | +import org.junit.After; |
| 23 | +import org.junit.Before; |
| 24 | + |
| 25 | +import java.nio.ByteBuffer; |
| 26 | +import java.nio.ByteOrder; |
| 27 | +import java.nio.ShortBuffer; |
| 28 | + |
| 29 | +public class UInt16BufferIntListTest extends IntListTestSuite { |
| 30 | + private long pointer; |
| 31 | + |
| 32 | + @Before |
| 33 | + public void setUp() { |
| 34 | + short[] sample = new short[] { |
| 35 | + (short) 0x0000, (short) 0x1C71, (short) 0x38E2, (short) 0x5553, (short) 0x71C4, |
| 36 | + (short) 0x8E35, (short) 0xAAA6, (short) 0xC717, (short) 0xE388, (short) 0xFFF9 |
| 37 | + }; |
| 38 | + int capacity = sample.length * 2; |
| 39 | + |
| 40 | + this.pointer = Memory.allocate(capacity); |
| 41 | + this.expected = new int[] { 0x0000, 0x1C71, 0x38E2, 0x5553, 0x71C4, |
| 42 | + 0x8E35, 0xAAA6, 0xC717, 0xE388, 0xFFF9 }; |
| 43 | + this.actual = new UInt16BufferIntList(null, pointer, sample.length); |
| 44 | + |
| 45 | + ByteBuffer byteBuffer = Memory.buffer(pointer, capacity); |
| 46 | + ShortBuffer shortBuffer = byteBuffer.order(ByteOrder.nativeOrder()).asShortBuffer(); |
| 47 | + shortBuffer.put(sample); |
| 48 | + } |
| 49 | + |
| 50 | + @After |
| 51 | + public void tearDown() { |
| 52 | + Memory.dispose(pointer); |
| 53 | + } |
| 54 | +} |
0 commit comments