summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun/gluegen/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/sun/gluegen/test')
-rw-r--r--src/java/com/sun/gluegen/test/TestPointerBufferEndian.java35
-rw-r--r--src/java/com/sun/gluegen/test/TestStructAccessorEndian.java35
2 files changed, 70 insertions, 0 deletions
diff --git a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java
new file mode 100644
index 0000000..973c89d
--- /dev/null
+++ b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java
@@ -0,0 +1,35 @@
+
+package com.sun.gluegen.test;
+
+import com.sun.gluegen.runtime.*;
+import java.nio.*;
+
+public class TestPointerBufferEndian {
+ public static void main (String[] args) {
+ boolean direct = args.length>0 && args[0].equals("-direct");
+ boolean ok = true;
+ System.out.println("Buffer is in: "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian");
+ PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(3);
+ ptr.put(0, 0x0123456789ABCDEFL);
+ ptr.put(1, 0x8877665544332211L);
+ ptr.put(2, 0xAFFEDEADBEEFAFFEL);
+ long v = ptr.get(0);
+ if( 0x0123456789ABCDEFL != v ) {
+ System.out.println("Err[0] shall 0x0123456789ABCDEF, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ v = ptr.get(1);
+ if( 0x8877665544332211L != v ) {
+ System.out.println("Err[1] shall 0x8877665544332211, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ v = ptr.get(2);
+ if( 0xAFFEDEADBEEFAFFEL != v ) {
+ System.out.println("Err[2] shall 0xAFFEDEADBEEFAFFE, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ if(!ok) {
+ throw new RuntimeException("Long conversion failure");
+ }
+ }
+}
diff --git a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java
new file mode 100644
index 0000000..13d7afb
--- /dev/null
+++ b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java
@@ -0,0 +1,35 @@
+
+package com.sun.gluegen.test;
+
+import com.sun.gluegen.runtime.*;
+import java.nio.*;
+
+public class TestStructAccessorEndian {
+ public static void main (String args[]) {
+ boolean ok = true;
+ System.out.println("CPU is : "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian");
+ ByteBuffer tst = BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_LONG * 3);
+ StructAccessor acc = new StructAccessor(tst);
+ acc.setLongAt(0, 0x0123456789ABCDEFL);
+ acc.setLongAt(1, 0x8877665544332211L);
+ acc.setLongAt(2, 0xAFFEDEADBEEFAFFEL);
+ long v = acc.getLongAt(0);
+ if( 0x0123456789ABCDEFL != v ) {
+ System.out.println("Err[0] shall 0x0123456789ABCDEF, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ v = acc.getLongAt(1);
+ if( 0x8877665544332211L != v ) {
+ System.out.println("Err[1] shall 0x8877665544332211, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ v = acc.getLongAt(2);
+ if( 0xAFFEDEADBEEFAFFEL != v ) {
+ System.out.println("Err[2] shall 0xAFFEDEADBEEFAFFE, is: "+Long.toHexString(v));
+ ok=false;
+ }
+ if(!ok) {
+ throw new RuntimeException("Long conversion failure");
+ }
+ }
+}