GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
BaseClass3PtrStorage.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.gluegen.test.junit.generation;
30
31import java.nio.IntBuffer;
32
33import com.jogamp.common.nio.Buffers;
34import com.jogamp.common.nio.ElementBuffer;
35
36import org.junit.Assert;
37
38/**
39 * Test {@link Bindingtest2} with {@link T2_PointerStorage} instance and pointer pointer..
40 */
41public class BaseClass3PtrStorage extends BaseClass {
42
43 /**
44 * Test {@link Bindingtest2} with {@link T2_PointerStorage} instance and pointer pointer
45 */
46 public void chapter01(final Bindingtest2 bt2) throws Exception {
47 Assert.assertEquals(false, T2_PointerStorage.usesNativeCode());
48
49 final T2_PointerStorage store = bt2.createT2PointerStorage();
50 // final T2_PointerStorage store = T2_PointerStorage.create();
51 final long[] int32PtrArray = store.getInt32PtrArray(0, new long[10], 0, 10); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
52 {
53 Assert.assertEquals(10, int32PtrArray.length);
54 System.err.print("int32PtrArray[10] = { ");
55 for(int i=0; i<int32PtrArray.length; ++i) {
56 Assert.assertNotEquals(0, int32PtrArray[i]);
57 final ElementBuffer eb = ElementBuffer.derefPointer(Buffers.SIZEOF_INT, int32PtrArray[i], 1);
58 final IntBuffer ib = eb.getByteBuffer().asIntBuffer();
59 Assert.assertEquals(1, ib.limit());
60 final int value = ib.get(0);
61 Assert.assertEquals(i, value);
62 System.err.print(value+", ");
63 }
64 System.err.println("}");
65 }
66 Assert.assertEquals(0, store.getInt32PtrPtrElemCount());
67 store.setInt32PtrPtr(false, int32PtrArray, 3, 0, 7); // -> 3, 4, 5, 6, 7, 8, 9
68 store.setInt32PtrPtr(true, int32PtrArray, 8, 3, 2); // -> 3, 4, 5, 8, 9, 8, 9
69 store.setInt32PtrPtr(true, int32PtrArray, 0, 5, 2); // -> 3, 4, 5, 8, 9, 0, 1
70 final long[] int32PtrPtr = store.getInt32PtrPtr(0, new long[7], 0, 7); // 3, 4, 5, 8, 9, 0, 1
71 {
72 System.err.print("int32PtrPtr[7] = { ");
73 for(int i=0; i<int32PtrPtr.length; ++i) {
74 Assert.assertNotEquals(0, int32PtrPtr[i]);
75 final ElementBuffer eb = ElementBuffer.derefPointer(Buffers.SIZEOF_INT, int32PtrPtr[i], 1);
76 final IntBuffer ib = eb.getByteBuffer().asIntBuffer();
77 Assert.assertEquals(1, ib.limit());
78 final int value = ib.get(0);
79 final int exp;
80 switch( i ) {
81 case 0: exp = 3; break;
82 case 1: exp = 4; break;
83 case 2: exp = 5; break;
84 case 3: exp = 8; break;
85 case 4: exp = 9; break;
86 case 5: exp = 0; break;
87 case 6: exp = 1; break;
88 default: exp = 99;
89 }
90 Assert.assertEquals(exp, value);
91 System.err.print(value+", ");
92 }
93 System.err.println("}");
94 }
95 bt2.destroyT2PointerStorage(store);
96 }
97
98}
Utility methods allowing easy java.nio.Buffer manipulations.
Definition: Buffers.java:70
static final int SIZEOF_INT
Definition: Buffers.java:80
Hardware independent container holding an array of linearly aligned elements, while its getDirectBuff...
final ByteBuffer getByteBuffer()
Returns the ByteBuffer, i.e.
static ElementBuffer derefPointer(final int elementSize, final long aptr, final int elemCount)
Test Bindingtest2 with T2_PointerStorage instance and pointer pointer.
void chapter01(final Bindingtest2 bt2)
Test Bindingtest2 with T2_PointerStorage instance and pointer pointer.