diff options
Diffstat (limited to 'src/junit/com/jogamp')
6 files changed, 294 insertions, 0 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java b/src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java new file mode 100644 index 0000000..16d5053 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java @@ -0,0 +1,85 @@ +/* + * 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 java.io.File; +import java.net.URISyntaxException; + +import org.apache.tools.ant.DefaultLogger; + +import static java.lang.System.*; + +/** + * @author Michael Bien + * @author Sven Gothel + */ +public final class BuildEnvironment { + + public static final String gluegenRoot; + public static final String testOutput; + public static final String rootrel_build; + + static { + + out.println(" - - - System info - - - "); + out.println("OS: " + System.getProperty("os.name")); + out.println("VM: " + System.getProperty("java.vm.name")); + + String rootrel_build_tmp = System.getProperty("rootrel.build"); + if(null==rootrel_build_tmp || rootrel_build_tmp.length()==0) { + rootrel_build_tmp = "build" ; + } + rootrel_build = rootrel_build_tmp; + out.println("rootrel.build: " + rootrel_build); + + // setup paths + try { + File executionRoot = new File(BuildEnvironment.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + out.println("execution root: " + executionRoot); + gluegenRoot = executionRoot.getParentFile().getParentFile().getParentFile().getParentFile().toString(); + out.println("gluegen project root: " + gluegenRoot); + } catch (URISyntaxException ex) { + throw new RuntimeException("can not determine gluegen root", ex); + } + + testOutput = gluegenRoot + "/" + rootrel_build + "/test"; + + out.println("testOutput: "+testOutput); + out.println(" - - - - - - - - - - - - "); + + DefaultLogger logger = new DefaultLogger(); + logger.setErrorPrintStream(out); + logger.setOutputPrintStream(out); + } +} + diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1.java b/src/junit/com/jogamp/gluegen/test/junit/Test1.java new file mode 100644 index 0000000..258256a --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/Test1.java @@ -0,0 +1,134 @@ +/* + * 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.sun.gluegen.runtime.BufferFactory; +import com.sun.gluegen.runtime.PointerBuffer; +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 Test1 { + + @Test + public void bindingTest1() throws Exception { + + String nativesPath = testOutput + "/build/natives"; + System.load(nativesPath + "/libtest1.so"); + + Class<?> clazz = Class.forName("com.jogamp.gluegen.test.junit.BindingTest1"); + + Assert.assertNotNull("com.jogamp.gluegen.test.junit.BindingTest1 does not exist", clazz); + Assert.assertEquals((int)1, clazz.getDeclaredField("CONSTANT_ONE").get(null)); + + Object obj = clazz.newInstance(); + Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.BindingTest1)); + + com.jogamp.gluegen.test.junit.BindingTest1 bindingTest1 = (com.jogamp.gluegen.test.junit.BindingTest1) obj; + Assert.assertTrue("nopTest1 failed", 42==bindingTest1.nopTest()); + + // assertEquals((long)0xFFFFFFFF, clazz.getDeclaredField("GL_INVALID_INDEX").get(null)); + // assertEquals(-0.5f, clazz.getDeclaredField("AL_FLANGER_DEFAULT_FEEDBACK").get(null)); + + // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError: test.BindingTest.arrayTest0(JLjava/lang/Object;I)I + /* + // test values + ByteBuffer dbb = BufferFactory.newDirectByteBuffer(32); + ByteBuffer bb = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder()); + + PointerBuffer dpb = PointerBuffer.allocateDirect(32); + PointerBuffer pb = PointerBuffer.allocate(32); + + long[] array = new long[] {1,2,3,4,5,6,7,8,9}; + int offset = 0; + long id = 42; + + + // invoke everything public + Object bindingTest = clazz.newInstance(); + Method[] methods = clazz.getDeclaredMethods(); + + for (Method method : methods) { + + // prepare method parameters + Class<?>[] paramTypes = method.getParameterTypes(); + Object[] paramInstances = new Object[paramTypes.length]; + + for (int i = 0; i < paramTypes.length; i++) { + Class<?> paramType = paramTypes[i]; + if(paramType.isInstance(dbb)) { + paramInstances[i] = dbb; + }else if(paramType.isInstance(bb)) { + paramInstances[i] = bb; + }else if(paramType.isInstance(dpb)) { + paramInstances[i] = dpb; + }else if(paramType.isInstance(pb)) { + paramInstances[i] = pb; + }else if(paramType.isPrimitive()) { // TODO primitive types + paramInstances[i] = offset; + }else if(paramType.isArray()) { // TODO array types + paramInstances[i] = array; + } + } + + out.println("invoking: "+method); + out.println("with params: "); + for (Object param : paramInstances) + out.print(param+", "); + out.println(); + + Object result = method.invoke(bindingTest, paramInstances); + out.println("result: "+result); + out.println("success"); + } + */ + } + +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c new file mode 100644 index 0000000..bf6ad97 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c @@ -0,0 +1,2 @@ + +#include "test1.h" diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg new file mode 100644 index 0000000..fe6cb5c --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg @@ -0,0 +1,28 @@ +Package com.jogamp.gluegen.test.junit +JavaClass BindingTest1 +Style AllStatic +JavaOutputDir classes +NativeOutputDir native + +# Use a ProcAddressTable so we dynamically look up the routines +#ProcAddressNameExpr PFN $UPPERCASE({0}) PROC +#EmitProcAddressTable true +#ProcAddressTableClassName BindingTest1ProcAddressTable +#GetProcAddressTableExpr _table + +# Force all of the methods to be emitted using dynamic linking so we +# don't need to link against any emulation library on the desktop or +# depend on the presence of an import library for a particular device +#ForceProcAddressGen __ALL__ + +# Also force the calling conventions of the locally generated function +# pointer typedefs for these routines to MYAPIENTRY +#LocalProcAddressCallingConvention __ALL__ MYAPIENTRY + +CustomCCode #include "test1.h" + +# Imports needed by all glue code +Import java.nio.* +Import java.util.* + + diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.c b/src/junit/com/jogamp/gluegen/test/junit/test1.c new file mode 100644 index 0000000..6b63f90 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/test1.c @@ -0,0 +1,21 @@ +#include "test1.h" + +int nopTest() { + return 42; +} + +int arrayTest(long context, foo * array) { + return 42; +} + +int bufferTest(void * object) { + return 42; +} + +int mixedTest(long context, void * object, foo * array){ + return 42; +} + +int doubleTest(long context, void * object1, foo * array1, void * object2, foo * array2) { + return 42; +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.h b/src/junit/com/jogamp/gluegen/test/junit/test1.h new file mode 100644 index 0000000..776bc0a --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/test1.h @@ -0,0 +1,24 @@ + +#ifndef MYAPIENTRY +#define MYAPIENTRY +#endif +#ifndef MYAPIENTRYP +#define MYAPIENTRYP MYAPIENTRY * +#endif + +#define MYAPI + +#define CONSTANT_ONE 1 + +typedef unsigned long foo; + +MYAPI int MYAPIENTRY nopTest(); + +MYAPI int MYAPIENTRY arrayTest(long context, foo * array ); + +MYAPI int MYAPIENTRY bufferTest(void * object); + +MYAPI int MYAPIENTRY mixedTest(long context, void * object, foo * array ); + +MYAPI int MYAPIENTRY doubleTest(long context, void * object1, foo * array1, void * object2, foo * array2 ); + |