aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-27 19:47:43 +0200
committerSven Gothel <[email protected]>2011-04-27 19:47:43 +0200
commit8f8aa3f73e3c9804c4a86f5d4fdac257d50d831a (patch)
tree87497a9ffd60f4d3c2be2535312a72f84087a23d /src/junit/com/jogamp
parenta07892f07f15c96ca248fc12133748be7058241f (diff)
NativeBuffer/PointerBuffer API/Impl Change (remove explicit backup array, alloc referenced data map if used only)
This patch doesn't impact GlueGen's code generation, but enhance and fix PointerBuffer usage only. remove explicit backup array As suggested by Michael Bien with a proposed patch, PointerBuffer's backup array is not only redundant in case it's not used, but also erroneous - due to possible sliced buffers. Removes the explicit backup array implementation leaving it up to the user, ie how PointerBuffer is created (alloc/allocDirect) and use the underlying nio's buffer backup array, if available. This also fixes the (never tested) case of indirect w/ backup array usage on 32bit platform size. In this case the array shall be of type int[], holding 32bit pointer - on 64bit long[]. Previous to this patch, it was always long[]. Added more thorough tests of PointerBuffer, notably indirect w/ backup array and native deep copy and filling of a pointer array. alloc referenced data map if used only As suggested by Michael Bien with a proposed patch, the allocation of the dataMap hash map is redundant in case it's not used. The hash map will be initialized lazy, if needed only.
Diffstat (limited to 'src/junit/com/jogamp')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java176
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java35
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java44
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c25
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h6
5 files changed, 235 insertions, 51 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 30ef6fd..c57a288 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -32,6 +32,7 @@ import com.jogamp.common.nio.Buffers;
import com.jogamp.common.nio.PointerBuffer;
import com.jogamp.common.os.Platform;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
@@ -70,7 +71,6 @@ public class BaseClass {
*/
public void chapter__TestCoverageSignature(Bindingtest1 binding) throws Exception {
int i;
- long result;
long context = 0;
ByteBuffer bb=null;
LongBuffer lb=null;
@@ -82,7 +82,8 @@ public class BaseClass {
String[] strings = null;
int[] iarray = null;
int iarray_offset = 0;
- long l = 0;
+ long result = 0;
+ long l = result;
result = binding.arrayTestInt32(context, ib);
result = binding.arrayTestInt32(context, iarray, iarray_offset);
@@ -137,34 +138,90 @@ public class BaseClass {
l = binding.typeTestUIntPtrT(l, l);
}
+ ByteBuffer newByteBuffer(int size, boolean direct) {
+ if(direct) {
+ final ByteBuffer bb = Buffers.newDirectByteBuffer(size);
+ Assert.assertTrue(bb.isDirect());
+ return bb;
+ } else {
+ final ByteBuffer bb = ByteBuffer.wrap(new byte[size]);
+ Assert.assertTrue(bb.hasArray());
+ Assert.assertTrue(!bb.isDirect());
+ bb.order(ByteOrder.nativeOrder());
+ Assert.assertTrue(bb.hasArray());
+ Assert.assertTrue(!bb.isDirect());
+ return bb;
+ }
+ }
+
+ IntBuffer newIntBuffer(int size, boolean direct) {
+ if(direct) {
+ final IntBuffer ib = Buffers.newDirectIntBuffer(size);
+ Assert.assertTrue(ib.isDirect());
+ return ib;
+ } else {
+ final IntBuffer ib = IntBuffer.wrap(new int[size]);
+ Assert.assertTrue(ib.hasArray());
+ Assert.assertTrue(!ib.isDirect());
+ return ib;
+ }
+ }
+
+ LongBuffer newLongBuffer(int size, boolean direct) {
+ if(direct) {
+ final LongBuffer lb = Buffers.newDirectLongBuffer(size);
+ Assert.assertTrue(lb.isDirect());
+ return lb;
+ } else {
+ final LongBuffer lb = LongBuffer.wrap(new long[size]);
+ Assert.assertTrue(!lb.isDirect());
+ Assert.assertTrue(lb.hasArray());
+ return lb;
+ }
+ }
+
+ PointerBuffer newPointerBuffer(int size, boolean direct) {
+ if(direct) {
+ final PointerBuffer pb = PointerBuffer.allocateDirect(size);
+ Assert.assertTrue(pb.isDirect());
+ Assert.assertTrue(pb.getBuffer().isDirect());
+ return pb;
+ } else {
+ final PointerBuffer pb = PointerBuffer.allocate(size);
+ Assert.assertTrue(pb.hasArray());
+ Assert.assertTrue(!pb.isDirect());
+ return pb;
+ }
+ }
+
/**
* Verifies if all methods / signatures are properly generated,
* can be invoked and functions.
* This is a compilation (coverage) and runtime time (semantic) test.
* This covers indirect primitive arrays and direct NIO buffers.
*/
- public void chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray(Bindingtest1 binding) throws Exception {
+ public void chapter03TestCoverageFunctionalityNIOAndPrimitiveArray(Bindingtest1 binding, boolean direct) throws Exception {
int i;
long result;
- long context = 1;
- LongBuffer lb = Buffers.newDirectLongBuffer(1);
+ final long context = 1;
+ LongBuffer lb = newLongBuffer(1, direct);
lb.put(0, 10);
- ByteBuffer bb2 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG);
+ ByteBuffer bb2 = newByteBuffer(Buffers.SIZEOF_LONG, direct);
LongBuffer bb2L = bb2.asLongBuffer();
bb2L.put(0, 100);
- IntBuffer ib1 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT * Bindingtest1.ARRAY_SIZE).asIntBuffer();
+ IntBuffer ib1 = newIntBuffer(Bindingtest1.ARRAY_SIZE, direct);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
ib1.put(i, 1000);
}
- LongBuffer lb1 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE);
+ LongBuffer lb1 = newLongBuffer(Bindingtest1.ARRAY_SIZE, direct);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
lb1.put(i, 1000);
}
- LongBuffer lb2 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE);
+ LongBuffer lb2 = newLongBuffer(Bindingtest1.ARRAY_SIZE, direct);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
lb2.put(i, 10000);
}
@@ -211,7 +268,7 @@ public class BaseClass {
// LongBuffer arrayTestFoo2 ( LongBuffer )
{
lb2.rewind();
- LongBuffer lb3 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE);
+ LongBuffer lb3 = newLongBuffer(Bindingtest1.ARRAY_SIZE, direct);
lb3.put(lb2);
lb3.rewind();
lb2.rewind();
@@ -256,7 +313,7 @@ public class BaseClass {
// PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
{
lb2.rewind();
- LongBuffer lb3 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE*Bindingtest1.ARRAY_SIZE);
+ LongBuffer lb3 = newLongBuffer(Bindingtest1.ARRAY_SIZE*Bindingtest1.ARRAY_SIZE, direct);
int j;
for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
lb3.put(lb2);
@@ -279,18 +336,21 @@ public class BaseClass {
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*Bindingtest1.ARRAY_SIZE; j++) {
- Assert.assertTrue("Wrong result: s:"+lb2.get(j%Bindingtest1.ARRAY_SIZE)+" d: "+lb3.get(j),
- 1+lb2.get(j%Bindingtest1.ARRAY_SIZE)==lb3.get(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));
}
+ Assert.assertEquals(0, binding.arrayTestFoo3PtrPtrValidation(pb2, 10000));
}
+ // PointerBuffer.alloc*(ARRAY_SIZE)
// PointerBuffer.referenceBuffer(LongBuffer.getBuffer)
// " "
// PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
{
- PointerBuffer pb = PointerBuffer.allocateDirect(Bindingtest1.ARRAY_SIZE);
+ PointerBuffer pb = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct);
int j;
for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
+ // the referenced buffer must be direct, non direct is not supported
LongBuffer lb3 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE);
lb3.put(lb2);
lb2.rewind();
@@ -304,27 +364,76 @@ public class BaseClass {
Assert.assertTrue("Wrong result: "+pb.capacity(), Bindingtest1.ARRAY_SIZE == pb.capacity());
Assert.assertTrue("Wrong result: "+pb.remaining(), Bindingtest1.ARRAY_SIZE == pb.remaining());
Assert.assertNotNull(pb.getReferencedBuffer(0));
- Assert.assertTrue("Wrong result: "+pb.getReferencedBuffer(0)+" != "+lb2, pb.getReferencedBuffer(0).equals(lb2));
+ Assert.assertTrue("Wrong result: "+pb.getReferencedBuffer(0)+" != "+lb2, pb.getReferencedBuffer(0).equals(lb2));
- PointerBuffer pb2 = binding.arrayTestFoo3PtrPtr(pb);
+ 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());
for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
- ByteBuffer bb = (ByteBuffer) pb.getReferencedBuffer(j);
- LongBuffer i64b = bb.asLongBuffer();
+ LongBuffer i64b = (LongBuffer) pb.getReferencedBuffer(j);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
- Assert.assertTrue("Wrong result: ["+j+"]["+i+"] s:"+lb2.get(i)+" d: "+i64b.get(i), 1+lb2.get(i)==i64b.get(i));
+ Assert.assertEquals("Wrong result: ["+j+"]["+i+"] s:"+lb2.get(i)+" d: "+i64b.get(i),
+ 1+lb2.get(i), i64b.get(i));
}
}
+ Assert.assertEquals(0, binding.arrayTestFoo3PtrPtrValidation(pb, 10000));
+ }
+
+ // pb = PointerBuffer.alloc*(ARRAY_SIZE)
+ // arrayTestFoo3CopyPtrPtrA(PointerBuffer dst, PointerBuffer src) (Native deep copy w/ alloc)
+ // " "
+ // PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
+ {
+ PointerBuffer pbS = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct);
+ int j;
+ for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
+ // the referenced buffer must be direct, non direct is not supported
+ LongBuffer lb3 = Buffers.newDirectLongBuffer(Bindingtest1.ARRAY_SIZE);
+ lb3.put(lb2);
+ lb2.rewind();
+ lb3.rewind();
+
+ 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());
+ Assert.assertNotNull(pbS.getReferencedBuffer(0));
+ Assert.assertTrue("Wrong result: "+pbS.getReferencedBuffer(0)+" != "+lb2, pbS.getReferencedBuffer(0).equals(lb2));
+
+ PointerBuffer pbD = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct);
+
+ // 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());
+
+
+ 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());
+ Assert.assertEquals(0, binding.arrayTestFoo3PtrPtrValidation(pbD2, 10000));
}
result = binding.bufferTest(lb);
Assert.assertTrue("Wrong result: "+result, 10==result);
- result = binding.bufferTestNioOnly(lb);
- Assert.assertTrue("Wrong result: "+result, 10==result);
+ if(direct) {
+ result = binding.bufferTestNioOnly(lb);
+ Assert.assertTrue("Wrong result: "+result, 10==result);
+ } else {
+ Exception e = null;
+ try {
+ binding.bufferTestNioOnly(lb);
+ } catch (RuntimeException re) {
+ e = re;
+ }
+ Assert.assertNotNull(e);
+ }
result = binding.doubleTest(context, lb, lb1, bb2, lb2);
Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
@@ -332,8 +441,10 @@ public class BaseClass {
result = binding.doubleTest(context, lb, larray1, larray1_offset, bb2, larray2, larray2_offset);
Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
- result = binding.doubleTestNioOnly(context, lb, lb1, bb2, lb2);
- Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
+ if(direct) {
+ result = binding.doubleTestNioOnly(context, lb, lb1, bb2, lb2);
+ Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
+ }
result = binding.mixedTest(context, lb, lb1);
Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
@@ -341,8 +452,10 @@ public class BaseClass {
result = binding.mixedTest(context, lb, larray1, larray1_offset);
Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
- result = binding.mixedTestNioOnly(context, lb, lb1);
- Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
+ if(direct) {
+ result = binding.mixedTestNioOnly(context, lb, lb1);
+ Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
+ }
result = binding.nopTest();
Assert.assertTrue("Wrong result: "+result, 42==result);
@@ -356,14 +469,12 @@ public class BaseClass {
i = binding.stringArrayRead(new String[] { "1234", "5678", "9a" }, 3);
Assert.assertTrue("Wrong result: "+i, 10==i);
- ByteBuffer bb3 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT * 3);
- IntBuffer ib = bb3.asIntBuffer();
+ IntBuffer ib = newIntBuffer(3, direct);
ib.put(0, 1);
ib.put(1, 2);
ib.put(2, 3);
int[] iarray = new int[] { 1, 2, 3 };
- int iarray_offset = 0;
i = binding.intArrayRead(ib, 3);
Assert.assertTrue("Wrong result: "+i, 6==i);
@@ -374,7 +485,7 @@ public class BaseClass {
{
long cfg_base = 0xAABBCCDD11223344L;
- PointerBuffer pb = PointerBuffer.allocateDirect(Bindingtest1.ARRAY_SIZE);
+ PointerBuffer pb = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct);
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
long cfg_native;
if(Platform.is32Bit()) {
@@ -399,12 +510,14 @@ public class BaseClass {
}
}
+ public void chapter04TestPointerBuffer(Bindingtest1 binding) throws Exception {
+ }
+
/**
* This covers indirect primitive arrays and indirect NIO buffers.
*/
- public void chapter04TestSomeFunctionsAllIndirect(Bindingtest1 binding) throws Exception {
+ public void chapter05TestSomeFunctionsAllIndirect(Bindingtest1 binding) throws Exception {
int i;
- long result;
IntBuffer ib = IntBuffer.allocate(3);
ib.put(0, 1);
@@ -412,7 +525,6 @@ public class BaseClass {
ib.put(2, 3);
int[] iarray = new int[] { 1, 2, 3 };
- int iarray_offset = 0;
i = binding.intArrayRead(ib, 3);
Assert.assertTrue("Wrong result: "+i, 6==i);
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java
index 5b6ac01..83faa9b 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java
@@ -28,7 +28,10 @@
package com.jogamp.gluegen.test.junit.generation;
+import java.io.IOException;
+
import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p1Impl;
+import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p2Impl;
import org.junit.Test;
@@ -71,16 +74,40 @@ public class Test1p1JavaEmitter extends BaseClass {
* This covers indirect primitive arrays and direct NIO buffers.
*/
@Test
- public void chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray() throws Exception {
- chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray(new Bindingtest1p1Impl());
+ public void chapter03aTestCoverageFunctionalityDirectNIOAndPrimitiveArray() throws Exception {
+ chapter03TestCoverageFunctionalityNIOAndPrimitiveArray(new Bindingtest1p1Impl(), true);
+ }
+
+ /**
+ * Verifies if all methods / signatures are properly generated,
+ * can be invoked and functions.
+ * This is a compilation (coverage) and runtime time (semantic) test.
+ * This covers indirect primitive arrays and indirect NIO buffers (nio using arrays).
+ */
+ @Test
+ public void chapter03bTestCoverageFunctionalityIndirectNIOAndPrimitiveArray() throws Exception {
+ chapter03TestCoverageFunctionalityNIOAndPrimitiveArray(new Bindingtest1p1Impl(), false);
+ }
+
+ /**
+ * This covers direct / indirect pointer buffers
+ */
+ @Test
+ public void chapter04TestPointerBuffer() throws Exception {
+ chapter04TestPointerBuffer(new Bindingtest1p1Impl());
}
/**
* This covers indirect primitive arrays and indirect NIO buffers.
*/
@Test
- public void chapter04TestSomeFunctionsAllIndirect() throws Exception {
- chapter04TestSomeFunctionsAllIndirect(new Bindingtest1p1Impl());
+ public void chapter05TestSomeFunctionsAllIndirect() throws Exception {
+ chapter05TestSomeFunctionsAllIndirect(new Bindingtest1p1Impl());
}
+ public static void main(String args[]) throws IOException {
+ String tstname = Test1p1JavaEmitter.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java
index 5323013..8fe4f86 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java
@@ -28,6 +28,9 @@
package com.jogamp.gluegen.test.junit.generation;
+import java.io.IOException;
+
+import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p1Impl;
import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p2Impl;
import com.jogamp.common.os.NativeLibrary;
@@ -81,28 +84,39 @@ public class Test1p2ProcAddressEmitter extends BaseClass {
* This covers indirect primitive arrays and direct NIO buffers.
*/
@Test
- public void chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray() throws Exception {
- chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray(new Bindingtest1p2Impl());
+ public void chapter03aTestCoverageFunctionalityDirectNIOAndPrimitiveArray() throws Exception {
+ chapter03TestCoverageFunctionalityNIOAndPrimitiveArray(new Bindingtest1p1Impl(), true);
}
/**
- * This covers indirect primitive arrays and indirect NIO buffers.
+ * Verifies if all methods / signatures are properly generated,
+ * can be invoked and functions.
+ * This is a compilation (coverage) and runtime time (semantic) test.
+ * This covers indirect primitive arrays and indirect NIO buffers (nio using arrays).
+ */
+ @Test
+ public void chapter03bTestCoverageFunctionalityIndirectNIOAndPrimitiveArray() throws Exception {
+ chapter03TestCoverageFunctionalityNIOAndPrimitiveArray(new Bindingtest1p1Impl(), false);
+ }
+
+ /**
+ * This covers direct / indirect pointer buffers
*/
@Test
- public void chapter04TestSomeFunctionsAllIndirect() throws Exception {
- chapter04TestSomeFunctionsAllIndirect(new Bindingtest1p2Impl());
+ public void chapter04TestPointerBuffer() throws Exception {
+ this.chapter04TestPointerBuffer(new Bindingtest1p2Impl());
}
- public static void main(String[] args) {
- Test1p2ProcAddressEmitter test = new Test1p2ProcAddressEmitter();
- try {
- test.chapter01TestLoadLibrary();
- test.chapter02TestClassExist();
- test.chapter03TestCoverageFunctionalityDirectNIOAndPrimitiveArray();
- test.chapter04TestSomeFunctionsAllIndirect();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ /**
+ * This covers indirect primitive arrays and indirect NIO buffers.
+ */
+ @Test
+ public void chapter05TestSomeFunctionsAllIndirect() throws Exception {
+ chapter05TestSomeFunctionsAllIndirect(new Bindingtest1p2Impl());
}
+ public static void main(String args[]) throws IOException {
+ String tstname = Test1p2ProcAddressEmitter.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
}
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 6cf42b5..05a9889 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -54,6 +54,18 @@ MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array) {
return result;
}
+MYAPI void MYAPIENTRY arrayTestFoo3CopyPtrPtrA(foo * * dest, const foo * * src) {
+ int i, j;
+ assert(NULL!=dest);
+ assert(NULL!=src);
+ for(j=0; j<ARRAY_SIZE; j++) {
+ dest[j] = calloc(ARRAY_SIZE, sizeof(foo));
+ for(i=0; i<ARRAY_SIZE; i++) {
+ dest[j][i] = src[j][i];
+ }
+ }
+}
+
MYAPI foo * * MYAPIENTRY arrayTestFoo3PtrPtr(foo * * array ) {
int i,j;
assert(NULL!=array);
@@ -65,6 +77,19 @@ MYAPI foo * * MYAPIENTRY arrayTestFoo3PtrPtr(foo * * array ) {
return array;
}
+MYAPI int MYAPIENTRY arrayTestFoo3PtrPtrValidation(foo * * array, int startval) {
+ int i,j,v,p=0;
+ assert(NULL!=array);
+ for(j=0; j<ARRAY_SIZE; j++) {
+ for(i=0, v=startval; i<ARRAY_SIZE; i++, p++, v++) {
+ if(array[j][i] != v) {
+ return p;
+ }
+ }
+ }
+ return 0;
+}
+
MYAPI foo MYAPIENTRY arrayTestFoo1(int64_t context, foo * array) {
foo 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 6230c51..5b1c241 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -46,9 +46,15 @@ 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);
+/** Fills dest array ptr of ARRAY size with arrays (allocs) and copies content of src to it - COPY! */
+MYAPI void MYAPIENTRY arrayTestFoo3CopyPtrPtrA(foo * * dest, const foo * * src);
+
/** Returns a the passed array-array, each element incr by 1 - IDENTITY !*/
MYAPI foo * * MYAPIENTRY arrayTestFoo3PtrPtr(foo * * array );
+/** Returns 0 if ok, otherwise the linear position */
+MYAPI int MYAPIENTRY arrayTestFoo3PtrPtrValidation(foo * * array, int startval);
+
/** Returns *((foo *)object) */
MYAPI foo MYAPIENTRY bufferTest(void * object);