GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
TestPointerBufferEndian.java
Go to the documentation of this file.
1
2package com.jogamp.common.nio;
3
4import java.io.IOException;
5
6import jogamp.common.os.PlatformPropsImpl;
7
8import com.jogamp.common.os.*;
9import com.jogamp.junit.util.SingletonJunitCase;
10
11import org.junit.Assert;
12import org.junit.Test;
13
14import static java.lang.System.*;
15
16import org.junit.FixMethodOrder;
17import org.junit.runners.MethodSorters;
18
19@FixMethodOrder(MethodSorters.NAME_ASCENDING)
21
22 protected void testImpl (final boolean direct) {
24 final int bitsPtr = machine.pointerSizeInBytes() * 8;
25 final String bitsProp = System.getProperty("sun.arch.data.model");
26 out.println("OS: <"+PlatformPropsImpl.OS+"> CPU: <"+PlatformPropsImpl.ARCH+"> Bits: <"+bitsPtr+"/"+bitsProp+">");
27 out.println(machine.toString());
28
29 final long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL };
30 final long[] values32Bit = { 0x0000000089ABCDEFL, 0x0000000044332211L, 0x00000000BEEFAFFEL };
31
32 final PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(valuesSource.length);
33 ptr.put(valuesSource, 0, valuesSource.length);
34 ptr.rewind();
35
36 int i=0;
37 while(ptr.hasRemaining()) {
38 final long v = ptr.get() ;
39 final long t = Platform.is32Bit() ? values32Bit[i] : valuesSource[i];
40 Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v);
41 i++;
42 }
43 Assert.assertTrue("iterator "+i+" != "+valuesSource.length, i==valuesSource.length);
44 }
45
46 @Test
47 public void testDirect () {
48 testImpl (true);
49 }
50
51 @Test
52 public void testIndirect () {
53 testImpl (false);
54 }
55
56 public static void main(final String args[]) throws IOException {
57 final String tstname = TestPointerBufferEndian.class.getName();
58 org.junit.runner.JUnitCore.main(tstname);
59 }
60}
Hardware independent container holding an array of native pointer, while its getDirectBufferAddress()...
static PointerBuffer allocateDirect(final int size)
Returns a direct PointerBuffer in native order, w/o backup array.
static PointerBuffer allocate(final int size)
Returns a non direct PointerBuffer, having a backup array.
final PointerBuffer put(final PointerBuffer src)
final long get(final int idx)
Absolute get method.
Machine data description for alignment and size onle, see com.jogamp.gluegen.
StringBuilder toString(StringBuilder sb)
Utility class for querying platform specific properties.
Definition: Platform.java:58
static MachineDataInfo getMachineDataInfo()
Returns the MachineDataInfo of the running machine.
Definition: Platform.java:510
static boolean is32Bit()
Returns true if this JVM/ARCH is 32bit.
Definition: Platform.java:423