GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
TestStructAccessorEndian.java
Go to the documentation of this file.
1package com.jogamp.common.nio;
2
3import static java.lang.System.out;
4
5import java.io.IOException;
6import java.nio.ByteBuffer;
7
8import jogamp.common.os.PlatformPropsImpl;
9
10import org.junit.Assert;
11import org.junit.Test;
12
13import com.jogamp.common.os.MachineDataInfo;
14import com.jogamp.common.os.Platform;
15import com.jogamp.junit.util.SingletonJunitCase;
16
17import org.junit.FixMethodOrder;
18import org.junit.runners.MethodSorters;
19
20@FixMethodOrder(MethodSorters.NAME_ASCENDING)
22
23 @Test
26 final int bitsPtr = machine.pointerSizeInBytes() * 8;
27 final String bitsProp = System.getProperty("sun.arch.data.model");
28 out.println("OS: <"+PlatformPropsImpl.OS+"> CPU: <"+PlatformPropsImpl.ARCH+"> Bits: <"+bitsPtr+"/"+bitsProp+">");
29 out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit");
30 out.println(machine.toString());
31
32 final long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL };
33 final ByteBuffer tst = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG * valuesSource.length);
34 final StructAccessor acc = new StructAccessor(tst);
35
36 int i;
37
38 for(i=0; i<valuesSource.length; i++) {
39 acc.setLongAt(i*8, valuesSource[i]);
40 }
41
42 for(i=0; i<valuesSource.length; i++) {
43 final long v = acc.getLongAt(i*8);
44 final long t = valuesSource[i];
45 Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v);
46 }
47 }
48
49 public static void main(final String args[]) throws IOException {
50 final String tstname = TestStructAccessorEndian.class.getName();
51 org.junit.runner.JUnitCore.main(tstname);
52 }
53
54}
Utility methods allowing easy java.nio.Buffer manipulations.
Definition: Buffers.java:70
static ByteBuffer newDirectByteBuffer(final int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.
Definition: Buffers.java:92
static final int SIZEOF_LONG
Definition: Buffers.java:82
final void setLongAt(final int byteOffset, final long v)
Puts a long at the specified byteOffset.
final long getLongAt(final int byteOffset)
Retrieves the long at the specified byteOffset.
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