aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-13 23:00:09 +0200
committerSven Gothel <[email protected]>2013-04-13 23:00:09 +0200
commit47333929fd4e563d61996654d2a435b52b904ef0 (patch)
tree712142b23921f20831403054f042f20f5245a702 /src/junit
parent21fc00af1c404d93280e21d05efc124ec23d575b (diff)
Bug 715: Adding unit test w/ 'intArrayCopy(int *dest, int *src, int num)' to test array offset working correct.
The 'carray' pointer returned from GetPrimitiveArrayCritical(..) is moved about the array offset and used in ReleasePrimitiveArrayCritical(..) to release the pinpointed memory. Even though this 'is' a bug by violating the _sparse_ specification, Hotspot impl. doesn't use the value at all (NOP) and hence this code didn't produce an error since .. (Same w/ Dalvik). A followup commit will fix this issue.
Diffstat (limited to 'src/junit')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java49
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c10
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h3
3 files changed, 62 insertions, 0 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 357ccea..f22b1df 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -38,6 +38,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
+import java.util.Arrays;
import jogamp.common.os.MachineDescriptionRuntime;
@@ -725,6 +726,54 @@ public class BaseClass extends JunitTracer {
i = binding.intArrayRead(iarray, 0, 3);
Assert.assertTrue("Wrong result: "+i, 6==i);
+
+ final int[] src = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+ final IntBuffer srcB = IntBuffer.wrap(src);
+ {
+ final int[] dst = new int[src.length];
+ i = binding.intArrayCopy(dst, 0, src, 0, src.length);
+ System.err.println("ArrayCopy.01: "+Arrays.toString(dst));
+ Assert.assertTrue("Wrong result: "+i, src.length==i);
+ Assert.assertTrue(Arrays.equals(src, dst));
+ }
+ {
+ IntBuffer dstB = IntBuffer.allocate(src.length);
+ i = binding.intArrayCopy(dstB, srcB, src.length);
+ System.err.println("ArrayCopy.02: "+Arrays.toString(dstB.array())+", "+dstB);
+ Assert.assertTrue("Wrong result: "+i, src.length==i);
+ Assert.assertTrue(Arrays.equals(src, dstB.array()));
+ }
+
+ {
+ final int[] src36 = new int[] { 4, 5, 6, 7 };
+ final int[] dst = new int[src36.length];
+ i = binding.intArrayCopy(dst, 0, src, 3, src36.length);
+ System.err.println("ArrayCopy.03: "+Arrays.toString(dst));
+ Assert.assertTrue("Wrong result: "+i, src36.length==i);
+ Assert.assertTrue(Arrays.equals(src36, dst));
+ }
+
+ final int[] src2 = new int[] { 0, 0, 0, 4, 5, 6, 7, 0, 0, 0 };
+ {
+ final int[] dst = new int[src2.length];
+ i = binding.intArrayCopy(dst, 3, src, 3, 4);
+ System.err.println("ArrayCopy.04: "+Arrays.toString(dst));
+ Assert.assertTrue("Wrong result: "+i, 4==i);
+ Assert.assertTrue(Arrays.equals(src2, dst));
+ }
+ {
+ IntBuffer dstB = IntBuffer.allocate(src2.length);
+ {
+ dstB.position(3);
+ srcB.position(3);
+ i = binding.intArrayCopy(dstB, srcB, 4);
+ dstB.position(0);
+ srcB.position(0);
+ }
+ System.err.println("ArrayCopy.05: "+Arrays.toString(dstB.array())+", "+dstB);
+ Assert.assertTrue("Wrong result: "+i, 4==i);
+ Assert.assertTrue(Arrays.equals(src2, dstB.array()));
+ }
}
void assertAPTR(final long expected, final long actual) {
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 c32b54b..31307a9 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -246,6 +246,16 @@ MYAPI int MYAPIENTRY intArrayRead(const int * ints, int num) {
return s;
}
+MYAPI int MYAPIENTRY intArrayCopy(int * dest, const int * src, int num) {
+ int i=0;
+ if(NULL!=dest && NULL!=src) {
+ for(i=0; i<num; i++) {
+ dest[i] = src[i];
+ }
+ }
+ return num;
+}
+
/**
MYAPI int intArrayWrite(int * * ints, int num) {
int i=0, s=0;
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 49510b4..555a113 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -122,6 +122,9 @@ MYAPI int MYAPIENTRY stringArrayRead(const char * * strings, int num);
/** Returns the sum of all integers, ints maybe NULL. */
MYAPI int MYAPIENTRY intArrayRead(const int * ints, int num);
+/** Copies num integer from src to dest. */
+MYAPI int MYAPIENTRY intArrayCopy(int * dest, const int * src, int num);
+
/** Increases the elements by 1, and returns the sum
MYAPI int MYAPIENTRY intArrayWrite(int * * ints, int num); */