View | Details | Raw Unified | Return to bug 1180
Collapse All | Expand All

(-)a/src/junit/com/jogamp/common/nio/BuffersTest.java (+57 lines)
Lines 31-37 Link Here
31
 */
31
 */
32
package com.jogamp.common.nio;
32
package com.jogamp.common.nio;
33
33
34
import java.nio.ByteBuffer;
35
import java.nio.CharBuffer;
36
import java.nio.DoubleBuffer;
37
import java.nio.FloatBuffer;
34
import java.nio.IntBuffer;
38
import java.nio.IntBuffer;
39
import java.nio.LongBuffer;
40
import java.nio.ShortBuffer;
41
35
import org.junit.Test;
42
import org.junit.Test;
36
43
37
import com.jogamp.junit.util.SingletonJunitCase;
44
import com.jogamp.junit.util.SingletonJunitCase;
Lines 48-53 import org.junit.runners.MethodSorters; Link Here
48
public class BuffersTest extends SingletonJunitCase {
55
public class BuffersTest extends SingletonJunitCase {
49
56
50
    @Test
57
    @Test
58
    public void positionLimitCapacityAfterArrayAllocation() {
59
        byte[] byteData = { 1, 2, 3, 4, 5, 6, 7, 8 };
60
        final ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(byteData);
61
        assertEquals(0, byteBuffer.position());
62
        assertEquals(8, byteBuffer.limit());
63
        assertEquals(8, byteBuffer.capacity());
64
        assertEquals(5, byteBuffer.get(4));
65
66
        double[] doubleData = { 1, 2 };
67
        final DoubleBuffer doubleBuffer = Buffers.newDirectDoubleBuffer(doubleData);
68
        assertEquals(0, doubleBuffer.position());
69
        assertEquals(2, doubleBuffer.limit());
70
        assertEquals(2, doubleBuffer.capacity());
71
72
        float[] floatData = { 1.0f, 2.0f, 3.0f };
73
        final FloatBuffer floatBuffer = Buffers.newDirectFloatBuffer(floatData);
74
        assertEquals(0, floatBuffer.position());
75
        assertEquals(3, floatBuffer.limit());
76
        assertEquals(3, floatBuffer.capacity());
77
78
        int[] intData = { 1, 2, 3, 4 };
79
        final IntBuffer intBuffer = Buffers.newDirectIntBuffer(intData);
80
        assertEquals(0, intBuffer.position());
81
        assertEquals(4, intBuffer.limit());
82
        assertEquals(4, intBuffer.capacity());
83
        assertEquals(3, intBuffer.get(2));
84
85
        long[] longData = { 1, 2, 3, 4, 5 };
86
        final LongBuffer longBuffer = Buffers.newDirectLongBuffer(longData);
87
        assertEquals(0, longBuffer.position());
88
        assertEquals(5, longBuffer.limit());
89
        assertEquals(5, longBuffer.capacity());
90
        assertEquals(4, longBuffer.get(3));
91
92
        short[] shortData = { 1, 2, 3, 4, 5, 6 };
93
        final ShortBuffer shortBuffer = Buffers.newDirectShortBuffer(shortData);
94
        assertEquals(0, shortBuffer.position());
95
        assertEquals(6, shortBuffer.limit());
96
        assertEquals(6, shortBuffer.capacity());
97
        assertEquals(4, shortBuffer.get(3));
98
99
        char[] charData = { 1, 2, 3, 4, 5, 6, 7 };
100
        final CharBuffer charBuffer = Buffers.newDirectCharBuffer(charData);
101
        assertEquals(0, charBuffer.position());
102
        assertEquals(7, charBuffer.limit());
103
        assertEquals(7, charBuffer.capacity());
104
        assertEquals(6, charBuffer.get(5));
105
    }
106
107
    @Test
51
    public void slice() {
108
    public void slice() {
52
109
53
        final IntBuffer buffer = Buffers.newDirectIntBuffer(6);
110
        final IntBuffer buffer = Buffers.newDirectIntBuffer(6);

Return to bug 1180