diff options
Diffstat (limited to 'src/junit/com/jogamp/gluegen/test')
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java | 115 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg | 15 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/test1.c | 55 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/test1.h | 19 |
4 files changed, 194 insertions, 10 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java index c53d142..420dc2b 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java +++ b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java @@ -35,6 +35,7 @@ package com.jogamp.gluegen.test.junit; import com.jogamp.gluegen.runtime.Buffers; import com.jogamp.gluegen.runtime.PointerBuffer; import com.jogamp.gluegen.runtime.Int64Buffer; +import com.jogamp.gluegen.runtime.Platform; import java.nio.*; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -89,6 +90,7 @@ public class BaseTest1 { long context = 0; ByteBuffer bb=null; Int64Buffer lb=null; + PointerBuffer pb=null; IntBuffer ib=null; long[] larray = null; int larray_offset = 0; @@ -103,10 +105,16 @@ public class BaseTest1 { result = binding.arrayTestInt64(context, lb); result = binding.arrayTestInt64(context, larray, larray_offset); - result = binding.arrayTestFoo(context, lb); - result = binding.arrayTestFoo(context, larray, larray_offset); + result = binding.arrayTestFoo1(context, lb); + result = binding.arrayTestFoo1(context, larray, larray_offset); result = binding.arrayTestFooNioOnly(context, lb); + lb = binding.arrayTestFoo2(lb); + lb = binding.arrayTestFoo2(larray, larray_offset); + + pb = binding.arrayTestFoo3ArrayToPtrPtr(lb); + pb = binding.arrayTestFoo3PtrPtr(pb); + result = binding.bufferTest(bb); result = binding.bufferTestNioOnly(bb); @@ -128,6 +136,9 @@ public class BaseTest1 { i = binding.intArrayRead(ib, i); i = binding.intArrayRead(iarray, iarray_offset, i); + long cfg=0; + cfg = binding.typeTestAnonSingle(cfg); + pb = binding.typeTestAnonPointer(pb); } /** @@ -192,15 +203,84 @@ public class BaseTest1 { result = binding.arrayTestInt64(context, larray1, larray1_offset); Assert.assertTrue("Wrong result: "+result, 1+8000==result); - result = binding.arrayTestFoo(context, lb1); + result = binding.arrayTestFoo1(context, lb1); Assert.assertTrue("Wrong result: "+result, 1+8000==result); - result = binding.arrayTestFoo(context, larray1, larray1_offset); + result = binding.arrayTestFoo1(context, larray1, larray1_offset); Assert.assertTrue("Wrong result: "+result, 1+8000==result); result = binding.arrayTestFooNioOnly(context, lb1); Assert.assertTrue("Wrong result: "+result, 1+8000==result); + { + lb2.rewind(); + Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE); + lb3.put(lb2); + lb3.rewind(); + lb2.rewind(); + + // System.out.println("lb3: "+lb3); + Assert.assertTrue("Wrong result: "+lb3.capacity(), BindingTest1.ARRAY_SIZE == lb3.capacity()); + Assert.assertTrue("Wrong result: "+lb3.remaining(), BindingTest1.ARRAY_SIZE == lb3.remaining()); + + Int64Buffer lbR = binding.arrayTestFoo2(lb3); + // System.out.println("lbR: "+lbR); + + Assert.assertNotNull(lbR); + Assert.assertTrue("Wrong result: "+lb3.capacity(), BindingTest1.ARRAY_SIZE == lb3.capacity()); + Assert.assertTrue("Wrong result: "+lb3.remaining(), BindingTest1.ARRAY_SIZE == lb3.remaining()); + Assert.assertTrue("Wrong result: "+lbR.capacity(), BindingTest1.ARRAY_SIZE == lbR.capacity()); + Assert.assertTrue("Wrong result: "+lbR.remaining(), BindingTest1.ARRAY_SIZE == lbR.remaining()); + int j=0; + for(j=0; j<BindingTest1.ARRAY_SIZE; j++) { + Assert.assertTrue("Wrong result: s:"+lb3.get(j)+" d: "+lbR.get(j), 1+lb3.get(j)==lbR.get(j)); + } + } + { + long[] larray3 = new long[BindingTest1.ARRAY_SIZE]; + for(i=0; i<BindingTest1.ARRAY_SIZE; i++) { + larray3[i]= larray2[i]; + } + + Int64Buffer lbR = binding.arrayTestFoo2(larray3, 0); + + Assert.assertNotNull(lbR); + Assert.assertTrue("Wrong result: "+lbR.capacity(), BindingTest1.ARRAY_SIZE == lbR.capacity()); + Assert.assertTrue("Wrong result: "+lbR.remaining(), BindingTest1.ARRAY_SIZE == lbR.remaining()); + int j=0; + for(j=0; j<BindingTest1.ARRAY_SIZE; j++) { + Assert.assertTrue("Wrong result: s:"+larray3[j]+" d: "+lbR.get(j), 1+larray3[j]==lbR.get(j)); + } + } + { + lb2.rewind(); + Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE*BindingTest1.ARRAY_SIZE); + int j=0; + for(j=0; j<BindingTest1.ARRAY_SIZE; j++) { + lb3.put(lb2); + lb2.rewind(); + } + lb3.rewind(); + + // System.out.println("lb3: "+lb3); + Assert.assertTrue("Wrong result: "+lb3.capacity(), BindingTest1.ARRAY_SIZE*BindingTest1.ARRAY_SIZE == lb3.capacity()); + Assert.assertTrue("Wrong result: "+lb3.remaining(), BindingTest1.ARRAY_SIZE*BindingTest1.ARRAY_SIZE == lb3.remaining()); + + PointerBuffer pb = binding.arrayTestFoo3ArrayToPtrPtr(lb3); + // System.out.println("pb: "+pb); + Assert.assertTrue("Wrong result: "+pb.capacity(), BindingTest1.ARRAY_SIZE == pb.capacity()); + Assert.assertTrue("Wrong result: "+pb.remaining(), BindingTest1.ARRAY_SIZE == pb.remaining()); + + PointerBuffer pb2 = binding.arrayTestFoo3PtrPtr(pb); + + Assert.assertNotNull(pb2); + Assert.assertTrue("Wrong result: "+pb2.capacity(), BindingTest1.ARRAY_SIZE == pb2.capacity()); + Assert.assertTrue("Wrong result: "+pb2.remaining(), BindingTest1.ARRAY_SIZE == pb2.remaining()); + for(j=0; j<BindingTest1.ARRAY_SIZE; j++) { + Assert.assertTrue("Wrong result: s:"+lb2.get(j)+" d: "+lb3.get(j), 1+lb2.get(j)==lb3.get(j)); + } + } + result = binding.bufferTest(lb.getBuffer()); Assert.assertTrue("Wrong result: "+result, 10==result); @@ -251,6 +331,33 @@ public class BaseTest1 { i = binding.intArrayRead(iarray, 0, 3); Assert.assertTrue("Wrong result: "+i, 6==i); + + { + long cfg_base = 0xAABBCCDD11223344L; + + PointerBuffer pb = PointerBuffer.allocateDirect(BindingTest1.ARRAY_SIZE); + for(i=0; i<BindingTest1.ARRAY_SIZE; i++) { + long cfg_native; + if(Platform.is32Bit()) { + cfg_native = (cfg_base+i) & 0x00000000FFFFFFFFL; // umask 1st 32bit + } else { + cfg_native = (cfg_base+i); + } + long cfg = binding.typeTestAnonSingle(cfg_base + i); + Assert.assertTrue("Wrong result: 0x"+Long.toHexString(cfg_native)+"+1 != 0x"+Long.toHexString(cfg), (cfg_native+1)==cfg); + pb.put(i, cfg_base+i); + + long t = pb.get(i); + Assert.assertTrue("Wrong result: 0x"+Long.toHexString(cfg_native)+" != 0x"+Long.toHexString(t), cfg_native==t); + } + pb.rewind(); + PointerBuffer pb2 = binding.typeTestAnonPointer(pb); + Assert.assertTrue("Wrong result: "+pb2.capacity(), BindingTest1.ARRAY_SIZE == pb2.capacity()); + Assert.assertTrue("Wrong result: "+pb2.remaining(), BindingTest1.ARRAY_SIZE == pb2.remaining()); + for(i=0; i<BindingTest1.ARRAY_SIZE; i++) { + Assert.assertTrue("Wrong result: 0x"+Long.toHexString(pb.get(i))+"+1 != 0x"+Long.toHexString(pb2.get(i)), (pb.get(i)+1)==pb2.get(i)); + } + } } /** diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg index d775424..2709e80 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg @@ -8,6 +8,21 @@ ReturnsString intToStr ArgumentIsString strToInt 0 ArgumentIsString stringArrayRead 0 +ReturnValueCapacity arrayTestFoo2 ARRAY_SIZE * sizeof(foo) +ReturnValueCapacity arrayTestFoo3ArrayToPtrPtr ARRAY_SIZE * sizeof(foo *) +ReturnValueCapacity arrayTestFoo3PtrPtr ARRAY_SIZE * sizeof(foo *) +ReturnValueCapacity typeTestAnonPointer ARRAY_SIZE * sizeof(MYAPIConfig) + +# +# This allows a single element of MYAPIConfig, +# an anonymous struct pointer, to be treated as a long value. +# Arrays of such type (pointer pointer) are still +# treated through a PointerBuffer to achieve architecture +# coherence (32bit/64bit pointer); +# +# typedef struct __MYAPIConfig * MYAPIConfig; +Opaque long MYAPIConfig + CustomCCode #include "test1.h" # Imports needed by all glue code diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.c b/src/junit/com/jogamp/gluegen/test/junit/test1.c index 0fa4abb..f654467 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1.c +++ b/src/junit/com/jogamp/gluegen/test/junit/test1.c @@ -2,6 +2,7 @@ #include <assert.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> foo nopTest() { return 42; @@ -31,7 +32,38 @@ int64_t arrayTestInt64(int64_t context, int64_t * array) { return r+context; } -foo arrayTestFoo(int64_t context, foo * array) { +foo * arrayTestFoo2( foo * array ) { + int i; + foo * result = calloc(ARRAY_SIZE, sizeof(foo)); + assert(NULL!=array); + for(i=0; i<ARRAY_SIZE; i++) { + result[i] = array[i] + 1; + // printf("array[%d]: %d -> %d\n", i, (int)array[i], (int)result[i]); + } + return result; +} + +foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { + int j; + foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); + for(j=0; j<ARRAY_SIZE; j++) { + result[j] = array + ARRAY_SIZE * j ; + } + return result; +} + +foo * * arrayTestFoo3PtrPtr(foo * * array ) { + int i,j; + assert(NULL!=array); + for(j=0; j<ARRAY_SIZE; j++) { + for(i=0; i<ARRAY_SIZE; i++) { + array[j][i] += 1; + } + } + return array; +} + +foo arrayTestFoo1(int64_t context, foo * array) { foo r=0; int i; assert(NULL!=array); @@ -51,7 +83,7 @@ foo bufferTest(void * object) { foo mixedTest(int64_t context, void * object, foo * array){ assert(NULL!=object); assert(NULL!=array); - return arrayTestFoo(context, array) + bufferTest(object); + return arrayTestFoo1(context, array) + bufferTest(object); } foo doubleTest(int64_t context, void * object1, foo * array1, void * object2, foo * array2) { @@ -59,14 +91,14 @@ foo doubleTest(int64_t context, void * object1, foo * array1, void * object2, fo assert(NULL!=array1); assert(NULL!=object2); assert(NULL!=array2); - return arrayTestFoo(context, array1) + - arrayTestFoo( 0, array2) + + return arrayTestFoo1(context, array1) + + arrayTestFoo1( 0, array2) + bufferTest(object1) + bufferTest(object2); } foo arrayTestFooNioOnly(int64_t context, foo * array ) { - return arrayTestFoo(context, array); + return arrayTestFoo1(context, array); } foo bufferTestNioOnly(void * object) { @@ -125,3 +157,16 @@ int intArrayWrite(int * * ints, int num) { return s; } */ +MYAPIConfig typeTestAnonSingle(const MYAPIConfig a) { + return (MYAPIConfig) ( ((void *)a) + 1 ); +} + +MYAPIConfig * MYAPIENTRY typeTestAnonPointer(const MYAPIConfig * a) { + int j; + MYAPIConfig * result = calloc(ARRAY_SIZE, sizeof(MYAPIConfig)); + for(j=0; j<ARRAY_SIZE; j++) { + result[j] = (MYAPIConfig) ( ((void *)a[j]) + 1 ); + } + return result; +} + diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.h b/src/junit/com/jogamp/gluegen/test/junit/test1.h index 2d92607..d0e50e5 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/test1.h @@ -25,7 +25,16 @@ MYAPI int32_t MYAPIENTRY arrayTestInt32(int64_t context, int32_t * array ); MYAPI int64_t MYAPIENTRY arrayTestInt64(int64_t context, int64_t * array ); /** Returns Sum(array) + context */ -MYAPI foo MYAPIENTRY arrayTestFoo(int64_t context, foo * array ); +MYAPI foo MYAPIENTRY arrayTestFoo1(int64_t context, foo * array ); + +/** Returns a copy of the passed array, each element incr by 1 */ +MYAPI foo * MYAPIENTRY arrayTestFoo2(foo * array ); + +/** Returns a array-array of the passed array, split at ARRAY size - IDENTITY! */ +MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array); + +/** Returns a the passed array-array, each element incr by 1 - IDENTITY !*/ +MYAPI foo * * MYAPIENTRY arrayTestFoo3PtrPtr(foo * * array ); /** Returns *((foo *)object) */ MYAPI foo MYAPIENTRY bufferTest(void * object); @@ -63,3 +72,11 @@ MYAPI int MYAPIENTRY intArrayRead(const int * ints, int num); /** Increases the elements by 1, and returns the sum MYAPI int MYAPIENTRY intArrayWrite(int * * ints, int num); */ +typedef struct __MYAPIConfig * MYAPIConfig; + +/** Returns the passed MYAPIConfig incremented by 1 */ +MYAPI MYAPIConfig MYAPIENTRY typeTestAnonSingle(const MYAPIConfig a); + +/** Return a copy of the passed MYAPIConfig*, incremented by 1 */ +MYAPI MYAPIConfig * MYAPIENTRY typeTestAnonPointer(const MYAPIConfig * a); + |