From 73829c38665c57052bf703ae58a2bd1dc7dc4625 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 31 Mar 2010 22:36:49 +0200 Subject: Buffer heritage added. Migrated old runtime tests. --- .../com/jogamp/gluegen/test/junit/BaseTest1.java | 427 --------------------- .../gluegen/test/junit/BuildEnvironment.java | 85 ---- .../gluegen/test/junit/Test1p1JavaEmitter.java | 107 ------ .../test/junit/Test1p2ProcAddressEmitter.java | 126 ------ .../gluegen/test/junit/generation/BaseTest1.java | 427 +++++++++++++++++++++ .../test/junit/generation/BuildEnvironment.java | 85 ++++ .../test/junit/generation/Test1p1JavaEmitter.java | 107 ++++++ .../generation/Test1p2ProcAddressEmitter.java | 126 ++++++ .../gluegen/test/junit/generation/test1-common.cfg | 33 ++ .../gluegen/test/junit/generation/test1-gluegen.c | 2 + .../test/junit/generation/test1-gluegen.cfg | 9 + .../jogamp/gluegen/test/junit/generation/test1.c | 172 +++++++++ .../jogamp/gluegen/test/junit/generation/test1.h | 82 ++++ .../test/junit/generation/test1p1-gluegen.cfg | 14 + .../test/junit/generation/test1p2-gluegen.cfg | 36 ++ .../junit/runtime/TestPointerBufferEndian.java | 53 +++ .../junit/runtime/TestStructAccessorEndian.java | 42 ++ .../com/jogamp/gluegen/test/junit/test1-common.cfg | 33 -- .../com/jogamp/gluegen/test/junit/test1-gluegen.c | 2 - .../jogamp/gluegen/test/junit/test1-gluegen.cfg | 9 - src/junit/com/jogamp/gluegen/test/junit/test1.c | 172 --------- src/junit/com/jogamp/gluegen/test/junit/test1.h | 82 ---- .../jogamp/gluegen/test/junit/test1p1-gluegen.cfg | 14 - .../jogamp/gluegen/test/junit/test1p2-gluegen.cfg | 36 -- 24 files changed, 1188 insertions(+), 1093 deletions(-) delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/BaseTest1.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.c create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1.c create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1.h create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg create mode 100644 src/junit/com/jogamp/gluegen/test/junit/runtime/TestPointerBufferEndian.java create mode 100644 src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1.c delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1.h delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1p1-gluegen.cfg delete mode 100644 src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg (limited to 'src/junit/com/jogamp/gluegen') diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java deleted file mode 100644 index f144a26..0000000 --- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java +++ /dev/null @@ -1,427 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -package com.jogamp.gluegen.test.junit; - -import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.PointerBuffer; -import com.jogamp.gluegen.runtime.Int64Buffer; -import com.jogamp.gluegen.runtime.Platform; -import java.nio.*; -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static java.lang.System.*; -import static com.jogamp.gluegen.test.junit.BuildEnvironment.*; - -/** - * @author Michael Bien - * @author Sven Gothel - */ -public class BaseTest1 { - - /** - * Verifies the existence and creation of the generated class. - */ - public void testClassExist(String name) throws Exception { - String ifName = "com.jogamp.gluegen.test.junit.Binding"+name; - String implName = "com.jogamp.gluegen.test.junit.impl.Binding"+name+"Impl"; - - Class clazzIf = Class.forName(ifName); - Class clazzImpl = Class.forName(implName); - - Assert.assertNotNull(ifName+" does not exist", clazzIf); - Assert.assertNotNull(implName+" does not exist", clazzImpl); - - Assert.assertEquals((int)1, clazzIf.getDeclaredField("CONSTANT_ONE").get(null)); - - Object obj = clazzImpl.newInstance(); - Assert.assertTrue("Not of type "+ifName, clazzIf.isAssignableFrom(obj.getClass())); - Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.BindingTest1)); - } - - /** - * Verifies if all generated method signatures are completed, - * ie a compilation only coverage test without functional tests. - */ - public void chapter__TestCoverageSignature(BindingTest1 binding) throws Exception { - int i; - long result; - long context = 0; - ByteBuffer bb=null; - Int64Buffer lb=null; - PointerBuffer pb=null; - IntBuffer ib=null; - long[] larray = null; - int larray_offset = 0; - String str=null; - String[] strings = null; - int[] iarray = null; - int iarray_offset = 0; - - result = binding.arrayTestInt32(context, ib); - result = binding.arrayTestInt32(context, iarray, iarray_offset); - - result = binding.arrayTestInt64(context, lb); - result = binding.arrayTestInt64(context, larray, larray_offset); - - result = binding.arrayTestFoo1(context, lb); - result = binding.arrayTestFoo1(context, larray, larray_offset); - result = binding.arrayTestFooNioOnly(context, lb); - - lb = binding.arrayTestFoo2(lb); - lb = binding.arrayTestFoo2(larray, larray_offset); - - pb = binding.arrayTestFoo3ArrayToPtrPtr(lb); - pb = binding.arrayTestFoo3PtrPtr(pb); - - result = binding.bufferTest(bb); - result = binding.bufferTestNioOnly(bb); - - result = binding.doubleTest(context, bb, lb, bb, lb); - result = binding.doubleTest(context, bb, larray, larray_offset, bb, larray, larray_offset); - result = binding.doubleTestNioOnly(context, bb, lb, bb, lb); - - result = binding.mixedTest(context, bb, lb); - result = binding.mixedTest(context, bb, larray, larray_offset); - result = binding.mixedTestNioOnly(context, bb, lb); - - result = binding.nopTest(); - - i = binding.strToInt(str); - str = binding.intToStr(i); - - i = binding.stringArrayRead(strings, i); - - i = binding.intArrayRead(ib, i); - i = binding.intArrayRead(iarray, iarray_offset, i); - - long cfg=0; - cfg = binding.typeTestAnonSingle(cfg); - pb = binding.typeTestAnonPointer(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 { - int i; - long result; - - long context = 1; - Int64Buffer lb = Int64Buffer.allocateDirect(1); - lb.put(0, 10); - - ByteBuffer bb2 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG); - Int64Buffer bb2L = Int64Buffer.wrap(bb2); - bb2L.put(0, 100); - - IntBuffer ib1 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT * BindingTest1.ARRAY_SIZE).asIntBuffer(); - for(i=0; i clazzIf = Class.forName(ifName); + Class clazzImpl = Class.forName(implName); + + Assert.assertNotNull(ifName+" does not exist", clazzIf); + Assert.assertNotNull(implName+" does not exist", clazzImpl); + + Assert.assertEquals((int)1, clazzIf.getDeclaredField("CONSTANT_ONE").get(null)); + + Object obj = clazzImpl.newInstance(); + Assert.assertTrue("Not of type "+ifName, clazzIf.isAssignableFrom(obj.getClass())); + Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.generation.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.generation.BindingTest1)); + } + + /** + * Verifies if all generated method signatures are completed, + * ie a compilation only coverage test without functional tests. + */ + public void chapter__TestCoverageSignature(BindingTest1 binding) throws Exception { + int i; + long result; + long context = 0; + ByteBuffer bb=null; + Int64Buffer lb=null; + PointerBuffer pb=null; + IntBuffer ib=null; + long[] larray = null; + int larray_offset = 0; + String str=null; + String[] strings = null; + int[] iarray = null; + int iarray_offset = 0; + + result = binding.arrayTestInt32(context, ib); + result = binding.arrayTestInt32(context, iarray, iarray_offset); + + result = binding.arrayTestInt64(context, lb); + result = binding.arrayTestInt64(context, larray, larray_offset); + + result = binding.arrayTestFoo1(context, lb); + result = binding.arrayTestFoo1(context, larray, larray_offset); + result = binding.arrayTestFooNioOnly(context, lb); + + lb = binding.arrayTestFoo2(lb); + lb = binding.arrayTestFoo2(larray, larray_offset); + + pb = binding.arrayTestFoo3ArrayToPtrPtr(lb); + pb = binding.arrayTestFoo3PtrPtr(pb); + + result = binding.bufferTest(bb); + result = binding.bufferTestNioOnly(bb); + + result = binding.doubleTest(context, bb, lb, bb, lb); + result = binding.doubleTest(context, bb, larray, larray_offset, bb, larray, larray_offset); + result = binding.doubleTestNioOnly(context, bb, lb, bb, lb); + + result = binding.mixedTest(context, bb, lb); + result = binding.mixedTest(context, bb, larray, larray_offset); + result = binding.mixedTestNioOnly(context, bb, lb); + + result = binding.nopTest(); + + i = binding.strToInt(str); + str = binding.intToStr(i); + + i = binding.stringArrayRead(strings, i); + + i = binding.intArrayRead(ib, i); + i = binding.intArrayRead(iarray, iarray_offset, i); + + long cfg=0; + cfg = binding.typeTestAnonSingle(cfg); + pb = binding.typeTestAnonPointer(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 { + int i; + long result; + + long context = 1; + Int64Buffer lb = Int64Buffer.allocateDirect(1); + lb.put(0, 10); + + ByteBuffer bb2 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG); + Int64Buffer bb2L = Int64Buffer.wrap(bb2); + bb2L.put(0, 100); + + IntBuffer ib1 = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT * BindingTest1.ARRAY_SIZE).asIntBuffer(); + for(i=0; i +#include +#include +#include + +foo nopTest() { + return 42; +} + +int32_t arrayTestInt32(int64_t context, int32_t * array) { + int32_t r=0; + int i; + assert(NULL!=array); + // printf("array test - %p sizeof(int32_t) %d\n", array, sizeof(int32_t)); + for(i=0; i %d\n", i, array[i], r); + } + return r+context; +} + +int64_t arrayTestInt64(int64_t context, int64_t * array) { + int64_t r=0; + int i; + assert(NULL!=array); + // printf("array test - %p sizeof(int64_t) %d\n", array, sizeof(int64_t)); + for(i=0; i %d\n", i, array[i], r); + } + return r+context; +} + +foo * arrayTestFoo2( foo * array ) { + int i; + foo * result = calloc(ARRAY_SIZE, sizeof(foo)); + assert(NULL!=array); + for(i=0; i %d\n", i, (int)array[i], (int)result[i]); + } + return result; +} + +foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { + int j; + foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); + for(j=0; j %d\n", i, array[i], r); + } + return r+context; +} + +foo bufferTest(void * object) { + assert(NULL!=object); + return *((foo *)object); +} + +foo mixedTest(int64_t context, void * object, foo * array){ + assert(NULL!=object); + assert(NULL!=array); + return arrayTestFoo1(context, array) + bufferTest(object); +} + +foo doubleTest(int64_t context, void * object1, foo * array1, void * object2, foo * array2) { + assert(NULL!=object1); + assert(NULL!=array1); + assert(NULL!=object2); + assert(NULL!=array2); + return arrayTestFoo1(context, array1) + + arrayTestFoo1( 0, array2) + + bufferTest(object1) + + bufferTest(object2); +} + +foo arrayTestFooNioOnly(int64_t context, foo * array ) { + return arrayTestFoo1(context, array); +} + +foo bufferTestNioOnly(void * object) { + return bufferTest(object); +} + +foo mixedTestNioOnly(int64_t context, void * object, foo * array ) { + return mixedTest(context, object, array); +} + +foo doubleTestNioOnly(int64_t context, void * object1, foo * array1, void * object2, foo * array2 ) { + return doubleTest(context, object1, array1, object2, array2); +} + +int strToInt(const char * str) { + return atoi(str); +} + +const char * intToStr(int i) { + static char singleton[200]; + snprintf(singleton, sizeof(singleton)-1, "%d", i); + return singleton; +} + +int stringArrayRead(const char * * strings, int num) { + int i=0, l=0; + if(NULL!=strings) { + for(i=0; i CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); + System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); + System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); + + long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL }; + long[] values32Bit = { 0x0000000089ABCDEFL, 0x0000000044332211L, 0x00000000BEEFAFFEL }; + + PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(valuesSource.length); + ptr.put(valuesSource, 0, valuesSource.length); + ptr.rewind(); + + int i=0; + while(ptr.hasRemaining()) { + long mask = Platform.is32Bit() ? 0x00000000FFFFFFFFL : 0xFFFFFFFFFFFFFFFFL ; + long v = ptr.get() & mask; + long t = Platform.is32Bit() ? values32Bit[i] : valuesSource[i]; + Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v); + i++; + } + Assert.assertTrue("iterator "+i+" != "+valuesSource.length, i==valuesSource.length); + } + + @Test + public void testDirect () { + testImpl (true); + } + + @Test + public void testIndirect () { + testImpl (false); + } +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java new file mode 100644 index 0000000..669fd78 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java @@ -0,0 +1,42 @@ +package com.jogamp.gluegen.test.junit.runtime; + +import com.jogamp.gluegen.runtime.*; + +import java.nio.*; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static java.lang.System.*; + +public class TestStructAccessorEndian { + + @Test + public void testStructAccessorEndian1 () { + int bitsPtr = Platform.getPointerSizeInBits(); + String bitsProp = System.getProperty("sun.arch.data.model"); + String os = System.getProperty("os.name"); + String cpu = System.getProperty("os.arch"); + System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); + System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); + System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); + + long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL }; + ByteBuffer tst = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG * valuesSource.length); + StructAccessor acc = new StructAccessor(tst); + + int i; + + for(i=0; i -#include -#include -#include - -foo nopTest() { - return 42; -} - -int32_t arrayTestInt32(int64_t context, int32_t * array) { - int32_t r=0; - int i; - assert(NULL!=array); - // printf("array test - %p sizeof(int32_t) %d\n", array, sizeof(int32_t)); - for(i=0; i %d\n", i, array[i], r); - } - return r+context; -} - -int64_t arrayTestInt64(int64_t context, int64_t * array) { - int64_t r=0; - int i; - assert(NULL!=array); - // printf("array test - %p sizeof(int64_t) %d\n", array, sizeof(int64_t)); - for(i=0; i %d\n", i, array[i], r); - } - return r+context; -} - -foo * arrayTestFoo2( foo * array ) { - int i; - foo * result = calloc(ARRAY_SIZE, sizeof(foo)); - assert(NULL!=array); - for(i=0; i %d\n", i, (int)array[i], (int)result[i]); - } - return result; -} - -foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { - int j; - foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); - for(j=0; j %d\n", i, array[i], r); - } - return r+context; -} - -foo bufferTest(void * object) { - assert(NULL!=object); - return *((foo *)object); -} - -foo mixedTest(int64_t context, void * object, foo * array){ - assert(NULL!=object); - assert(NULL!=array); - return arrayTestFoo1(context, array) + bufferTest(object); -} - -foo doubleTest(int64_t context, void * object1, foo * array1, void * object2, foo * array2) { - assert(NULL!=object1); - assert(NULL!=array1); - assert(NULL!=object2); - assert(NULL!=array2); - return arrayTestFoo1(context, array1) + - arrayTestFoo1( 0, array2) + - bufferTest(object1) + - bufferTest(object2); -} - -foo arrayTestFooNioOnly(int64_t context, foo * array ) { - return arrayTestFoo1(context, array); -} - -foo bufferTestNioOnly(void * object) { - return bufferTest(object); -} - -foo mixedTestNioOnly(int64_t context, void * object, foo * array ) { - return mixedTest(context, object, array); -} - -foo doubleTestNioOnly(int64_t context, void * object1, foo * array1, void * object2, foo * array2 ) { - return doubleTest(context, object1, array1, object2, array2); -} - -int strToInt(const char * str) { - return atoi(str); -} - -const char * intToStr(int i) { - static char singleton[200]; - snprintf(singleton, sizeof(singleton)-1, "%d", i); - return singleton; -} - -int stringArrayRead(const char * * strings, int num) { - int i=0, l=0; - if(NULL!=strings) { - for(i=0; i