aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-06 02:05:22 +0200
committerSven Gothel <[email protected]>2011-10-06 02:05:22 +0200
commite388426759e02e15ccc93b9df2e5c0400590d057 (patch)
tree2b37cc94003ecc76e3a1cc250d6745b746cf6a28 /src/junit/com
parent2fdff368a5e77c31fff242f286c61edabae2669e (diff)
Enhance ReleasePrimitiveArrayCritical: Use mode-flag JNI_ABORT if array is const, ie no write-back
We shall consider the C header declaration as being correct and no modification shall happen on const arrays. Tested w/ unit tests and JOGL +++ Cleanup JavaType: final immutable fields, proper CVoidPointer name
Diffstat (limited to 'src/junit/com')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java43
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c15
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h7
3 files changed, 58 insertions, 7 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 e73aca6..f2a85fe 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -268,7 +268,7 @@ public class BaseClass {
result = binding.arrayTestFooNioOnly(context, lb1);
Assert.assertTrue("Wrong result: "+result, 1+8000==result);
- // LongBuffer arrayTestFoo2 ( LongBuffer )
+ // LongBuffer arrayTestFoo2 ( LongBuffer ) - don't write-back array-arg
{
lb2.rewind();
LongBuffer lb3 = newLongBuffer(Bindingtest1.ARRAY_SIZE, direct);
@@ -290,11 +290,12 @@ public class BaseClass {
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:"+lb2.get(j)+" c: "+lb3.get(j), lb2.get(j)==lb3.get(j));
Assert.assertTrue("Wrong result: s:"+lb3.get(j)+" d: "+lbR.get(j), 1+lb3.get(j)==lbR.get(j));
}
}
- // LongBuffer arrayTestFoo2 ( long[], int )
+ // LongBuffer arrayTestFoo2 ( long[], int ) - don't write-back array-arg
{
long[] larray3 = new long[Bindingtest1.ARRAY_SIZE];
for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
@@ -308,10 +309,48 @@ public class BaseClass {
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:"+larray2[j]+" c: "+larray3[j], larray2[j]==larray3[j]);
Assert.assertTrue("Wrong result: s:"+larray3[j]+" d: "+lbR.get(j), 1+larray3[j]==lbR.get(j));
}
}
+ // void arrayTestFoo3 ( LongBuffer ) - write-back array-arg
+ {
+ lb2.rewind();
+ LongBuffer lb3 = newLongBuffer(Bindingtest1.ARRAY_SIZE, direct);
+ 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());
+
+ binding.arrayTestFoo3(lb3);
+
+ Assert.assertTrue("Wrong result: "+lb3.capacity(), Bindingtest1.ARRAY_SIZE == lb3.capacity());
+ Assert.assertTrue("Wrong result: "+lb3.remaining(), Bindingtest1.ARRAY_SIZE == lb3.remaining());
+ int j=0;
+ 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));
+ }
+ }
+
+ // void arrayTestFoo3 ( long[], int ) - write-back array-arg
+ {
+ long[] larray3 = new long[Bindingtest1.ARRAY_SIZE];
+ for(i=0; i<Bindingtest1.ARRAY_SIZE; i++) {
+ larray3[i]= larray2[i];
+ }
+
+ binding.arrayTestFoo3(larray3, 0);
+
+ int j=0;
+ for(j=0; j<Bindingtest1.ARRAY_SIZE; j++) {
+ Assert.assertTrue("Wrong result: s:"+larray2[j]+" d: "+larray3[j], 1+larray2[j]==larray3[j]);
+ }
+ }
+
// PointerBuffer arrayTestFoo3ArrayToPtrPtr(LongBuffer)
// PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
{
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 2d7aa71..ae3c8a5 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -36,7 +36,7 @@ MYAPI int64_t MYAPIENTRY arrayTestInt64(int64_t context, int64_t * array) {
return r+context;
}
-MYAPI foo * MYAPIENTRY arrayTestFoo2( foo * array ) {
+MYAPI foo * MYAPIENTRY arrayTestFoo2( const foo * array ) {
int i;
foo * result = calloc(ARRAY_SIZE, sizeof(foo));
assert(NULL!=array);
@@ -47,11 +47,20 @@ MYAPI foo * MYAPIENTRY arrayTestFoo2( foo * array ) {
return result;
}
-MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array) {
+MYAPI void MYAPIENTRY arrayTestFoo3( foo * array ) {
+ int i;
+ assert(NULL!=array);
+ for(i=0; i<ARRAY_SIZE; i++) {
+ array[i] += 1;
+ // printf("array[%d]: %d -> %d\n", i, (int)array[i], (int)result[i]);
+ }
+}
+
+MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(const foo * array) {
int j;
foo * * result = calloc(ARRAY_SIZE, sizeof(foo *));
for(j=0; j<ARRAY_SIZE; j++) {
- result[j] = array + ARRAY_SIZE * j ;
+ result[j] = (foo *) ( array + ARRAY_SIZE * j ) ;
}
return result;
}
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 3e20307..6c38a03 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -42,10 +42,13 @@ MYAPI int64_t MYAPIENTRY arrayTestInt64(int64_t context, int64_t * 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 );
+MYAPI foo * MYAPIENTRY arrayTestFoo2(const foo * array );
+
+/** Increments each element of the passed array by 1 - IDENTITY */
+MYAPI void MYAPIENTRY arrayTestFoo3(foo * array );
/** Returns a array-array of the passed array, split at ARRAY size - IDENTITY! */
-MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array);
+MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(const 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);