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

GlueGen v2.6.0 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)
20public class TestPointerBufferEndian extends SingletonJunitCase {
21
22 protected void testImpl (final boolean direct) {
23 final MachineDataInfo machine = Platform.getMachineDataInfo();
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}
com.jogamp.common.nio.AbstractBuffer.hasRemaining
final boolean hasRemaining()
Definition: AbstractBuffer.java:123
com.jogamp.common.nio.AbstractBuffer.rewind
final B rewind()
Definition: AbstractBuffer.java:145
com.jogamp.common.nio.PointerBuffer
Hardware independent container holding an array of native pointer, while its getDirectBufferAddress()...
Definition: PointerBuffer.java:55
com.jogamp.common.nio.PointerBuffer.allocateDirect
static PointerBuffer allocateDirect(final int size)
Returns a direct PointerBuffer in native order, w/o backup array.
Definition: PointerBuffer.java:90
com.jogamp.common.nio.PointerBuffer.allocate
static PointerBuffer allocate(final int size)
Returns a non direct PointerBuffer, having a backup array.
Definition: PointerBuffer.java:81
com.jogamp.common.nio.PointerBuffer.put
final PointerBuffer put(final PointerBuffer src)
Definition: PointerBuffer.java:149
com.jogamp.common.nio.PointerBuffer.get
final long get(final int idx)
Absolute get method.
Definition: PointerBuffer.java:179
com.jogamp.common.nio.TestPointerBufferEndian
Definition: TestPointerBufferEndian.java:20
com.jogamp.common.nio.TestPointerBufferEndian.testImpl
void testImpl(final boolean direct)
Definition: TestPointerBufferEndian.java:22
com.jogamp.common.nio.TestPointerBufferEndian.testIndirect
void testIndirect()
Definition: TestPointerBufferEndian.java:52
com.jogamp.common.nio.TestPointerBufferEndian.testDirect
void testDirect()
Definition: TestPointerBufferEndian.java:47
com.jogamp.common.nio.TestPointerBufferEndian.main
static void main(final String args[])
Definition: TestPointerBufferEndian.java:56
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