summaryrefslogtreecommitdiffstats
path: root/src/junit
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-03-20 02:15:53 +0100
committerSven Gothel <[email protected]>2013-03-20 02:15:53 +0100
commit1610dbb4e4d1a1ecf31eb837a47e0f5be04afdac (patch)
tree89808f30f1f3937a46d872a161be7673ad516821 /src/junit
parent4becdfa125b07ff969d6540e1112735b53cd15eb (diff)
Fix intptr_t*, uintptr_t*, ptrdiff_t* and size_t* mapping, map them to PointerBuffer, since referenced memory-size is arch dependent
Added extensive PointerBuffer unit tests w/ new mapping in generated test class.
Diffstat (limited to 'src/junit')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java188
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg7
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c58
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h27
4 files changed, 257 insertions, 23 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
index 8dff4be..1ce97b5 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -77,9 +77,7 @@ public class BaseClass extends JunitTracer {
public void chapter__TestCoverageSignature(Bindingtest1 binding) throws Exception {
int i;
long context = 0;
- ByteBuffer bb=null;
LongBuffer lb=null;
- PointerBuffer pb=null;
IntBuffer ib=null;
long[] larray = null;
int larray_offset = 0;
@@ -90,6 +88,38 @@ public class BaseClass extends JunitTracer {
long result = 0;
long l = result;
+ {
+ ByteBuffer bb = binding.createAPtrBlob();
+ PointerBuffer pb = safeByteBuffer2PointerBuffer(bb, 1);
+ long bb2A = binding.getAPtrAddress(bb);
+ bb2A = bb2A - 0; // avoid warning
+
+ binding.arrayTestAVoidPtrTypeDim1Mutable(pb);
+ pb = PointerBuffer.wrap( binding.arrayTestAVoidPtrTypeDim1Immutable(pb) );
+ pb = PointerBuffer.wrap( binding.arrayTestAVoidPtrTypeDim0(pb.getBuffer()) );
+ binding.releaseAPtrBlob( binding.getAPtrMemory( pb.get(0) ) );
+
+ binding.arrayTestAIntPtrTypeDim1Mutable(pb);
+ result = binding.arrayTestAIntPtrTypeDim1Immutable(pb);
+ result = binding.arrayTestAIntPtrTypeDim0(pb.get(0));
+ binding.releaseAPtrBlob( binding.getAPtrMemory( pb.get(0) ) );
+
+ binding.arrayTestAPtr1TypeDim1Mutable(pb);
+ pb = PointerBuffer.wrap( binding.arrayTestAPtr1TypeDim1Immutable(pb) );
+ pb = PointerBuffer.wrap( binding.arrayTestAPtr1TypeDim0(pb.getBuffer()) );
+ binding.releaseAPtrBlob( binding.getAPtrMemory( pb.get(0) ) );
+
+ binding.arrayTestAPtr2TypeDim1Mutable(pb);
+ result = binding.arrayTestAPtr2TypeDim1Immutable(pb);
+ result = binding.arrayTestAPtr2TypeDim0(pb.get(0));
+ binding.releaseAPtrBlob( binding.getAPtrMemory( pb.get(0) ) );
+
+ binding.releaseAPtrBlob(bb);
+ }
+
+ ByteBuffer bb=null;
+ PointerBuffer pb=null;
+
result = binding.arrayTestInt32(context, ib);
result = binding.arrayTestInt32(context, iarray, iarray_offset);
@@ -199,6 +229,31 @@ public class BaseClass extends JunitTracer {
}
}
+ long cleanAddress(long a) {
+ if (Platform.is32Bit()) {
+ return a & 0x00000000FFFFFFFFL;
+ } else {
+ return a;
+ }
+ }
+
+ PointerBuffer validatePointerBuffer(PointerBuffer pb, int elements) {
+ Assert.assertNotNull(pb);
+ Assert.assertEquals("PointerBuffer capacity not "+elements, elements, pb.capacity());
+ Assert.assertEquals("PointerBuffer remaining not "+elements, elements, pb.remaining());
+ System.err.println("Testing accessing PointerBuffer values [0.."+(elements-1)+"]");
+ for(int i=0; i<elements; i++) {
+ final long v = pb.get(i);
+ System.err.println(" "+i+"/"+elements+": 0x"+Long.toHexString(v));
+ }
+ return pb;
+ }
+ PointerBuffer safeByteBuffer2PointerBuffer(ByteBuffer bb, int elements) {
+ Assert.assertEquals("ByteBuffer capacity not PointerBuffer ELEMENT_SIZE * "+elements, elements * PointerBuffer.ELEMENT_SIZE, bb.capacity());
+ Assert.assertEquals("ByteBuffer remaining not PointerBuffer ELEMENT_SIZE * "+elements, elements * PointerBuffer.ELEMENT_SIZE, bb.remaining());
+ return validatePointerBuffer(PointerBuffer.wrap(bb), elements);
+ }
+
/**
* Verifies if all methods / signatures are properly generated,
* can be invoked and functions.
@@ -370,15 +425,10 @@ public class BaseClass extends JunitTracer {
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());
+ validatePointerBuffer(pb, Bindingtest1.ARRAY_SIZE);
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());
+ validatePointerBuffer(pb2, Bindingtest1.ARRAY_SIZE);
for(j=0; j<Bindingtest1.ARRAY_SIZE*Bindingtest1.ARRAY_SIZE; j++) {
Assert.assertEquals("Wrong result: s:"+lb2.get(j%Bindingtest1.ARRAY_SIZE)+" d: "+lb3.get(j),
1+lb2.get(j%Bindingtest1.ARRAY_SIZE), lb3.get(j));
@@ -405,16 +455,12 @@ public class BaseClass extends JunitTracer {
pb.rewind();
// System.out.println("lb3: "+lb3);
- Assert.assertTrue("Wrong result: "+pb.capacity(), Bindingtest1.ARRAY_SIZE == pb.capacity());
- Assert.assertTrue("Wrong result: "+pb.remaining(), Bindingtest1.ARRAY_SIZE == pb.remaining());
+ validatePointerBuffer(pb, Bindingtest1.ARRAY_SIZE);
Assert.assertNotNull(pb.getReferencedBuffer(0));
Assert.assertTrue("Wrong result: "+pb.getReferencedBuffer(0)+" != "+lb2, pb.getReferencedBuffer(0).equals(lb2));
PointerBuffer pb2 = binding.arrayTestFoo3PtrPtr(pb); // pb2 is shallow
-
- 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());
+ validatePointerBuffer(pb2, Bindingtest1.ARRAY_SIZE);
for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
LongBuffer i64b = (LongBuffer) pb.getReferencedBuffer(j);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
@@ -442,8 +488,7 @@ public class BaseClass extends JunitTracer {
pbS.referenceBuffer(lb3);
}
pbS.rewind();
- Assert.assertTrue("Wrong result: "+pbS.capacity(), Bindingtest1.ARRAY_SIZE == pbS.capacity());
- Assert.assertTrue("Wrong result: "+pbS.remaining(), Bindingtest1.ARRAY_SIZE == pbS.remaining());
+ validatePointerBuffer(pbS, Bindingtest1.ARRAY_SIZE);
Assert.assertNotNull(pbS.getReferencedBuffer(0));
Assert.assertTrue("Wrong result: "+pbS.getReferencedBuffer(0)+" != "+lb2, pbS.getReferencedBuffer(0).equals(lb2));
@@ -451,15 +496,11 @@ public class BaseClass extends JunitTracer {
// System.err.println("\n***pbS "+pbS); System.err.println("***pbD "+pbD);
binding.arrayTestFoo3CopyPtrPtrA(pbD, pbS); // pbD is shallow
- Assert.assertTrue("Wrong result: "+pbD.capacity(), Bindingtest1.ARRAY_SIZE == pbD.capacity());
- Assert.assertTrue("Wrong result: "+pbD.remaining(), Bindingtest1.ARRAY_SIZE == pbD.remaining());
-
+ validatePointerBuffer(pbD, Bindingtest1.ARRAY_SIZE);
PointerBuffer pbD2 = binding.arrayTestFoo3PtrPtr(pbD); // pbD2 is shallow
Assert.assertEquals(0, binding.arrayTestFoo3PtrPtrValidation(pbD, 10000));
- Assert.assertNotNull(pbD2);
- Assert.assertTrue("Wrong result: "+pbD2.capacity(), Bindingtest1.ARRAY_SIZE == pbD2.capacity());
- Assert.assertTrue("Wrong result: "+pbD2.remaining(), Bindingtest1.ARRAY_SIZE == pbD2.remaining());
+ validatePointerBuffer(pbD2, Bindingtest1.ARRAY_SIZE);
Assert.assertEquals(0, binding.arrayTestFoo3PtrPtrValidation(pbD2, 10000));
}
@@ -563,6 +604,107 @@ public class BaseClass extends JunitTracer {
}
public void chapter04TestPointerBuffer(Bindingtest1 binding) throws Exception {
+ final long DEADBEEF = 0x00000000DEADBEEFL;
+
+ {
+ long bbA, bbA2;
+ ByteBuffer bb, bb2;
+ PointerBuffer bbPb;
+
+ final ByteBuffer blob = binding.createAPtrBlob();
+ final PointerBuffer blobPb = safeByteBuffer2PointerBuffer(blob, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & blobPb.get(0));
+
+ binding.arrayTestAVoidPtrTypeDim1Mutable(blobPb); // new memory in [0]
+ Assert.assertTrue(DEADBEEF != ( 0xFFFFFFFF & blobPb.get(0) ) );
+ bb = binding.arrayTestAVoidPtrTypeDim1Immutable(blobPb); // returns memory address of [0], returned as bb (blob)
+ bbA = cleanAddress( binding.getAPtrAddress(bb) ); // address of new memory in [0]
+ Assert.assertEquals(blobPb.get(0), bbA);
+
+ bbPb = safeByteBuffer2PointerBuffer(bb, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & bbPb.get(0));
+ Assert.assertEquals(blobPb.get(0), binding.getAPtrAddress(bbPb.getBuffer()));
+
+ bb2 = binding.arrayTestAVoidPtrTypeDim0(bb);
+ bbA2 = cleanAddress( binding.getAPtrAddress(bb2) );
+ Assert.assertEquals(bbA, bbA2);
+ binding.releaseAPtrBlob(bb);
+ binding.releaseAPtrBlob(blob);
+ }
+
+ {
+ long bbA, bbA2;
+ ByteBuffer bb;
+ PointerBuffer bbPb;
+
+ final ByteBuffer blob = binding.createAPtrBlob();
+ final PointerBuffer blobPb = safeByteBuffer2PointerBuffer(blob, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & blobPb.get(0));
+
+ binding.arrayTestAIntPtrTypeDim1Mutable(blobPb); // new memory in [0]
+ Assert.assertTrue(DEADBEEF != ( 0xFFFFFFFF & blobPb.get(0) ) );
+ bbA = cleanAddress( binding.arrayTestAIntPtrTypeDim1Immutable(blobPb) ); // returns memory address of [0], returned as intptr_t
+ Assert.assertEquals(blobPb.get(0), bbA);
+ bb = binding.getAPtrMemory(bbA);
+ bbPb = safeByteBuffer2PointerBuffer(bb, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & bbPb.get(0));
+
+ bbA2 = cleanAddress( binding.arrayTestAIntPtrTypeDim0(bbA) );
+ Assert.assertEquals(bbA, bbA2);
+ binding.releaseAPtrBlob(bb);
+ binding.releaseAPtrBlob(blob);
+ }
+
+ {
+ long bbA, bbA2;
+ ByteBuffer bb, bb2;
+ PointerBuffer bbPb;
+
+ final ByteBuffer blob = binding.createAPtrBlob();
+ final PointerBuffer blobPb = safeByteBuffer2PointerBuffer(blob, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & blobPb.get(0));
+
+ binding.arrayTestAPtr1TypeDim1Mutable(blobPb); // new memory in [0]
+ Assert.assertTrue(DEADBEEF != ( 0xFFFFFFFF & blobPb.get(0) ) );
+ bb = binding.arrayTestAPtr1TypeDim1Immutable(blobPb); // returns memory address of [0], returned as bb (blob)
+ bbA = cleanAddress( binding.getAPtrAddress(bb) ); // address of new memory in [0]
+ Assert.assertEquals(blobPb.get(0), bbA);
+
+ bbPb = safeByteBuffer2PointerBuffer(bb, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & bbPb.get(0));
+ Assert.assertEquals(blobPb.get(0), binding.getAPtrAddress(bbPb.getBuffer()));
+
+ bb2 = binding.arrayTestAPtr1TypeDim0(bb);
+ bbA2 = cleanAddress( binding.getAPtrAddress(bb2) );
+ Assert.assertEquals(bbA, bbA2);
+ binding.releaseAPtrBlob(bb);
+ binding.releaseAPtrBlob(blob);
+
+ }
+
+ {
+ long bbA, bbA2;
+ ByteBuffer bb;
+ PointerBuffer bbPb;
+
+ final ByteBuffer blob = binding.createAPtrBlob();
+ final PointerBuffer blobPb = safeByteBuffer2PointerBuffer(blob, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & blobPb.get(0));
+
+ binding.arrayTestAPtr2TypeDim1Mutable(blobPb); // new memory in [0]
+ Assert.assertTrue(DEADBEEF != ( 0xFFFFFFFF & blobPb.get(0) ) );
+ bbA = cleanAddress( binding.arrayTestAPtr2TypeDim1Immutable(blobPb) ); // returns memory address of [0], returned as intptr_t
+ Assert.assertEquals(blobPb.get(0), bbA);
+ bb = binding.getAPtrMemory(bbA);
+ bbPb = safeByteBuffer2PointerBuffer(bb, 1);
+ Assert.assertEquals(DEADBEEF, 0xFFFFFFFF & bbPb.get(0));
+
+ bbA2 = cleanAddress( binding.arrayTestAPtr2TypeDim0(bbA) );
+ Assert.assertEquals(bbA, bbA2);
+ binding.releaseAPtrBlob(bb);
+ binding.releaseAPtrBlob(blob);
+ }
+
}
/**
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
index 490bf2d..89689cb 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
@@ -9,6 +9,13 @@ ReturnsString intToStr
ArgumentIsString strToInt 0
ArgumentIsString stringArrayRead 0
+ReturnValueCapacity createAPtrBlob 1 * sizeof(void *)
+ReturnValueCapacity getAPtrMemory 1 * sizeof(void *)
+ReturnValueCapacity arrayTestAVoidPtrTypeDim0 1 * sizeof(void *)
+ReturnValueCapacity arrayTestAVoidPtrTypeDim1Immutable 1 * sizeof(void *)
+ReturnValueCapacity arrayTestAPtr1TypeDim0 1 * sizeof(APtr1Type)
+ReturnValueCapacity arrayTestAPtr1TypeDim1Immutable 1 * sizeof(APtr1Type)
+
ReturnValueCapacity arrayTestFoo2 ARRAY_SIZE * sizeof(foo)
ReturnValueCapacity arrayTestFoo3ArrayToPtrPtr ARRAY_SIZE * sizeof(foo *)
ReturnValueCapacity arrayTestFoo3PtrPtr ARRAY_SIZE * sizeof(foo *)
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
index 1adf824..c32b54b 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -12,6 +12,64 @@ MYAPI foo MYAPIENTRY nopTest() {
return 42;
}
+/**
+ * new blob sizeof(void*) filled w/ 0xDEADBEEF
+ */
+MYAPI void * MYAPIENTRY createAPtrBlob () {
+ uint32_t * mem = (uint32_t *) calloc(1, sizeof(void *));
+ *mem = 0xDEADBEEF;
+ return (void *)mem;
+}
+MYAPI void MYAPIENTRY releaseAPtrBlob (void * blob) {
+ free(blob);
+}
+MYAPI intptr_t MYAPIENTRY getAPtrAddress (const void * immutable ) {
+ return (intptr_t)immutable;
+}
+MYAPI void * MYAPIENTRY getAPtrMemory (const intptr_t address ) {
+ return (void *)address;
+}
+
+MYAPI void * MYAPIENTRY arrayTestAVoidPtrTypeDim0 (const void * immutable ) {
+ return immutable;
+}
+MYAPI void MYAPIENTRY arrayTestAVoidPtrTypeDim1Mutable (void ** mutable ) {
+ *mutable = createAPtrBlob ();
+}
+MYAPI void * MYAPIENTRY arrayTestAVoidPtrTypeDim1Immutable (const void ** immutable ) {
+ return *immutable;
+}
+
+MYAPI intptr_t MYAPIENTRY arrayTestAIntPtrTypeDim0 (intptr_t immutable) {
+ return immutable;
+}
+MYAPI void MYAPIENTRY arrayTestAIntPtrTypeDim1Mutable (intptr_t * mutable ) {
+ *mutable = (intptr_t) createAPtrBlob ();
+}
+MYAPI intptr_t MYAPIENTRY arrayTestAIntPtrTypeDim1Immutable(const intptr_t * immutable ) {
+ return *immutable;
+}
+
+MYAPI APtr1Type MYAPIENTRY arrayTestAPtr1TypeDim0 (APtr1Type immutable ) {
+ return immutable;
+}
+MYAPI void MYAPIENTRY arrayTestAPtr1TypeDim1Mutable (APtr1Type * mutable ) {
+ *mutable = (APtr1Type) createAPtrBlob ();
+}
+MYAPI APtr1Type MYAPIENTRY arrayTestAPtr1TypeDim1Immutable(const APtr1Type * immutable ) {
+ return *immutable;
+}
+
+MYAPI APtr2Type MYAPIENTRY arrayTestAPtr2TypeDim0 (APtr2Type immutable ) {
+ return immutable;
+}
+MYAPI void MYAPIENTRY arrayTestAPtr2TypeDim1Mutable (APtr2Type * mutable ) {
+ *mutable = (APtr2Type) createAPtrBlob ();
+}
+MYAPI APtr2Type MYAPIENTRY arrayTestAPtr2TypeDim1Immutable(const APtr2Type * immutable ) {
+ return *immutable;
+}
+
MYAPI int32_t MYAPIENTRY arrayTestInt32(int64_t context, int32_t * array) {
int32_t r=0;
int i;
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
index de57b66..49510b4 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -28,10 +28,37 @@
typedef int Bool;
typedef uint64_t foo;
+typedef void * APtr1Type;
+typedef intptr_t APtr2Type;
/** Returns 42 */
MYAPI foo MYAPIENTRY nopTest();
+//
+// Different pointer type tests ..
+//
+
+MYAPI void * MYAPIENTRY createAPtrBlob ();
+MYAPI void MYAPIENTRY releaseAPtrBlob (void * blob);
+MYAPI intptr_t MYAPIENTRY getAPtrAddress (const void * immutable );
+MYAPI void * MYAPIENTRY getAPtrMemory (const intptr_t address );
+
+MYAPI void * MYAPIENTRY arrayTestAVoidPtrTypeDim0 (const void * immutable );
+MYAPI void MYAPIENTRY arrayTestAVoidPtrTypeDim1Mutable (void ** mutable );
+MYAPI void * MYAPIENTRY arrayTestAVoidPtrTypeDim1Immutable (const void ** immutable );
+
+MYAPI intptr_t MYAPIENTRY arrayTestAIntPtrTypeDim0 (intptr_t immutable);
+MYAPI void MYAPIENTRY arrayTestAIntPtrTypeDim1Mutable (intptr_t * mutable );
+MYAPI intptr_t MYAPIENTRY arrayTestAIntPtrTypeDim1Immutable(const intptr_t * immutable );
+
+MYAPI APtr1Type MYAPIENTRY arrayTestAPtr1TypeDim0 (APtr1Type immutable );
+MYAPI void MYAPIENTRY arrayTestAPtr1TypeDim1Mutable (APtr1Type * mutable );
+MYAPI APtr1Type MYAPIENTRY arrayTestAPtr1TypeDim1Immutable(const APtr1Type * immutable );
+
+MYAPI APtr2Type MYAPIENTRY arrayTestAPtr2TypeDim0 (APtr2Type immutable );
+MYAPI void MYAPIENTRY arrayTestAPtr2TypeDim1Mutable (APtr2Type * mutable );
+MYAPI APtr2Type MYAPIENTRY arrayTestAPtr2TypeDim1Immutable(const APtr2Type * immutable );
+
/** Returns Sum(array) + context */
MYAPI int32_t MYAPIENTRY arrayTestInt32(int64_t context, int32_t * array );