From 47333929fd4e563d61996654d2a435b52b904ef0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 13 Apr 2013 23:00:09 +0200 Subject: 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. --- .../gluegen/test/junit/generation/BaseClass.java | 49 ++++++++++++++++++++++ .../jogamp/gluegen/test/junit/generation/test1.c | 10 +++++ .../jogamp/gluegen/test/junit/generation/test1.h | 3 ++ 3 files changed, 62 insertions(+) (limited to 'src/junit') 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