diff options
Diffstat (limited to 'src/junit/com/jogamp/common/nio/BuffersTest.java')
-rw-r--r-- | src/junit/com/jogamp/common/nio/BuffersTest.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/junit/com/jogamp/common/nio/BuffersTest.java b/src/junit/com/jogamp/common/nio/BuffersTest.java index 0b72cd4..836e46d 100644 --- a/src/junit/com/jogamp/common/nio/BuffersTest.java +++ b/src/junit/com/jogamp/common/nio/BuffersTest.java @@ -43,14 +43,45 @@ public class BuffersTest { @Test public void slice() { + IntBuffer buffer = Buffers.newDirectIntBuffer(6); buffer.put(new int[]{1,2,3,4,5,6}).rewind(); - IntBuffer threefour = (IntBuffer)Buffers.slice(buffer, 2, 2); + IntBuffer threefour = Buffers.slice(buffer, 2, 2); assertEquals(3, threefour.get(0)); assertEquals(4, threefour.get(1)); assertEquals(2, threefour.capacity()); + + assertEquals(0, buffer.position()); + assertEquals(6, buffer.limit()); + + IntBuffer fourfivesix = Buffers.slice(buffer, 3, 3); + + assertEquals(4, fourfivesix.get(0)); + assertEquals(5, fourfivesix.get(1)); + assertEquals(6, fourfivesix.get(2)); + assertEquals(3, fourfivesix.capacity()); + + assertEquals(0, buffer.position()); + assertEquals(6, buffer.limit()); + + IntBuffer onetwothree = Buffers.slice(buffer, 0, 3); + + assertEquals(1, onetwothree.get(0)); + assertEquals(2, onetwothree.get(1)); + assertEquals(3, onetwothree.get(2)); + assertEquals(3, onetwothree.capacity()); + + assertEquals(0, buffer.position()); + assertEquals(6, buffer.limit()); + + // is it really sliced? + buffer.put(2, 42); + + assertEquals(42, buffer.get(2)); + assertEquals(42, onetwothree.get(2)); + } |