GlueGen: src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java Source File

GlueGen v2.6.0-rc-20250721 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)
21public class TestStructAccessorEndian extends SingletonJunitCase {
22
23 @Test
24 public void testStructAccessorEndian1 () {
25 final MachineDataInfo machine = Platform.getMachineDataInfo();
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}
com.jogamp.common.nio.Buffers
Utility methods allowing easy java.nio.Buffer manipulations.
Definition: Buffers.java:70
com.jogamp.common.nio.Buffers.newDirectByteBuffer
static ByteBuffer newDirectByteBuffer(final int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.
Definition: Buffers.java:92
com.jogamp.common.nio.Buffers.SIZEOF_LONG
static final int SIZEOF_LONG
Definition: Buffers.java:82
com.jogamp.common.nio.StructAccessor
Definition: StructAccessor.java:47
com.jogamp.common.nio.StructAccessor.setLongAt
final void setLongAt(final int byteOffset, final long v)
Puts a long at the specified byteOffset.
Definition: StructAccessor.java:189
com.jogamp.common.nio.StructAccessor.getLongAt
final long getLongAt(final int byteOffset)
Retrieves the long at the specified byteOffset.
Definition: StructAccessor.java:184
com.jogamp.common.nio.TestStructAccessorEndian
Definition: TestStructAccessorEndian.java:21
com.jogamp.common.nio.TestStructAccessorEndian.main
static void main(final String args[])
Definition: TestStructAccessorEndian.java:49
com.jogamp.common.nio.TestStructAccessorEndian.testStructAccessorEndian1
void testStructAccessorEndian1()
Definition: TestStructAccessorEndian.java:24
com.jogamp.common.os.MachineDataInfo
Machine data description for alignment and size onle, see com.jogamp.gluegen.
Definition: MachineDataInfo.java:57
com.jogamp.common.os.MachineDataInfo.toString
StringBuilder toString(StringBuilder sb)
Definition: MachineDataInfo.java:355
com.jogamp.common.os.Platform
Utility class for querying platform specific properties.
Definition: Platform.java:58
com.jogamp.common.os.Platform.getMachineDataInfo
static MachineDataInfo getMachineDataInfo()
Returns the MachineDataInfo of the running machine.
Definition: Platform.java:510
com.jogamp.common.os.Platform.is32Bit
static boolean is32Bit()
Returns true if this JVM/ARCH is 32bit.
Definition: Platform.java:423
com.jogamp.junit.util.SingletonJunitCase
Definition: SingletonJunitCase.java:39