summaryrefslogtreecommitdiffstats
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
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.
-rwxr-xr-xmake/scripts/runtest.sh4
-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
4 files changed, 64 insertions, 2 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh
index 657c217..f38d179 100755
--- a/make/scripts/runtest.sh
+++ b/make/scripts/runtest.sh
@@ -75,7 +75,7 @@ function onetest() {
#
#onetest com.jogamp.common.GlueGenVersion 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestSystemPropsAndEnvs 2>&1 | tee -a $LOG
-onetest com.jogamp.common.util.TestVersionInfo 2>&1 | tee -a $LOG
+#onetest com.jogamp.common.util.TestVersionInfo 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestVersionNumber 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestIteratorIndexCORE 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.locks.TestRecursiveLock01 2>&1 | tee -a $LOG
@@ -95,7 +95,7 @@ onetest com.jogamp.common.util.TestVersionInfo 2>&1 | tee -a $LOG
#onetest com.jogamp.common.nio.TestStructAccessorEndian 2>&1 | tee -a $LOG
#onetest com.jogamp.common.os.TestElfReader01 2>&1 | tee -a $LOG
#onetest com.jogamp.gluegen.test.junit.generation.Test1p1JavaEmitter 2>&1 | tee -a $LOG
-#onetest com.jogamp.gluegen.test.junit.generation.Test1p2ProcAddressEmitter 2>&1 | tee -a $LOG
+onetest com.jogamp.gluegen.test.junit.generation.Test1p2ProcAddressEmitter 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestPlatform01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestRunnableTask01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestIOUtil01 2>&1 | tee -a $LOG
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); */