aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-03-27 02:46:25 +0100
committerMichael Bien <[email protected]>2010-03-27 02:46:25 +0100
commit45ef1faaecdb809d8724fbe6762dd3c23976b526 (patch)
tree427f441ed44008e654a1ecd2d2245f5327d656cc
parentbb9028843b1e382180fd2663e5c98b86fc37718b (diff)
parent2b61964060ffb79a313030d795ad069fbbe97b88 (diff)
Merge branch 'master' of [email protected]:mbien/gluegen
Conflicts: src/junit/com/jogamp/gluegen/test/junit/Test1.java
-rw-r--r--make/build-junit.xml8
-rwxr-xr-xmake/gluegen-cpptasks.xml8
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/Test1.java151
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg9
4 files changed, 102 insertions, 74 deletions
diff --git a/make/build-junit.xml b/make/build-junit.xml
index 2a6807d..dd87cdd 100644
--- a/make/build-junit.xml
+++ b/make/build-junit.xml
@@ -48,6 +48,8 @@
<property name="gluegen.jar" value="${gluegen.root}/${rootrel.build}/gluegen.jar" />
<property name="gluegen-rt.jar" value="${gluegen.root}/${rootrel.build}/gluegen-rt.jar" />
+ <property name="gluegen.lib" value="${gluegen.root}/${rootrel.build}/obj" />
+
<property name="junit.jar" value="${gluegen.root}/make/lib/junit-4.5.jar" />
<property name="gluegen-test.jar" value="${build_t}/gluegen-test.jar" />
@@ -106,7 +108,7 @@
<jar destfile="${gluegen-test.jar}">
<fileset dir="${build_t.java}">
- <include name="${test.junit.rel}/*.class"/>
+ <include name="${test.junit.rel}/**/*.class"/>
</fileset>
</jar>
</target>
@@ -189,7 +191,7 @@
<!-- Perform the junit tests-->
<mkdir dir="${results}"/>
<junit forkmode="once" showoutput="true" fork="true" haltonerror="true">
- <jvmarg value="-Djava.library.path=${build_t.lib}"/>
+ <jvmarg value="-Djava.library.path=${gluegen.lib}:${build_t.lib}"/>
<jvmarg value="-Drootrel.build=${rootrel.build}"/>
<formatter usefile="false" type="plain"/>
<formatter usefile="true" type="xml"/>
@@ -240,7 +242,7 @@
<target name="junit.test1.c.build" unless="build.javaonly" >
<patternset id="junit.test1.c.src.files">
<include name="${test.junit.rootrel}/test1.c"/>
- <include name="${build_t.gen.rootrel}/native/BindingTest1_JNI.c"/>
+ <include name="${build_t.gen.rootrel}/native/BindingTest1Impl_JNI.c"/>
</patternset>
<c.build c.compiler.src.files="junit.test1.c.src.files"
diff --git a/make/gluegen-cpptasks.xml b/make/gluegen-cpptasks.xml
index dc88340..f569ea7 100755
--- a/make/gluegen-cpptasks.xml
+++ b/make/gluegen-cpptasks.xml
@@ -26,18 +26,20 @@
<typedef resource="net/sf/antcontrib/cpptasks/antlib.xml" classpath="${gluegen.root}/make/lib/cpptasks.jar;${gluegen.root}/make/lib/CppTasksGCCNamespaceHack.jar"/>
<condition property="gluegen-cpptasks.file"
- value="${basedir}/${gluegen.root}/make/gluegen-cpptasks-base.xml">
+ value="${gluegen.root}/make/gluegen-cpptasks-base.xml">
<not>
<isset property="gluegen-cpptask.file" />
</not>
</condition>
+ <property name="gluegen-cpptasks.file.abs-path" location="${gluegen-cpptasks.file}" />
+
<!--
<echo message="gluegen-cpptasks.xml: gluegen.root ${gluegen.root}"/>
- <echo message="gluegen-cpptasks.xml: gluegen-cpptasks.file ${gluegen-cpptasks.file}"/>
+ <echo message="gluegen-cpptasks.xml: gluegen-cpptasks.file ${gluegen-cpptasks.file} -> ${gluegen-cpptasks.file.abs-path}"/>
<echo message="gluegen-cpptasks.xml: basedir ${basedir}"/>
-->
- <import file="${gluegen-cpptasks.file}" optional="false" />
+ <import file="${gluegen-cpptasks.file.abs-path}" optional="false" />
</project>
diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1.java b/src/junit/com/jogamp/gluegen/test/junit/Test1.java
index 07bd971..bbb7a0a 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/Test1.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/Test1.java
@@ -1,21 +1,21 @@
/*
* 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
@@ -32,8 +32,11 @@
package com.jogamp.gluegen.test.junit;
+import com.jogamp.gluegen.test.junit.impl.BindingTest1Impl;
+
import com.jogamp.gluegen.runtime.BufferFactory;
import com.jogamp.gluegen.runtime.PointerBuffer;
+import java.nio.*;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -57,78 +60,92 @@ import static com.jogamp.gluegen.test.junit.BuildEnvironment.*;
*/
public class Test1 {
+ /**
+ * Verifies loading of the new library.
+ */
@Test
- public void bindingTest1() throws Exception {
-
+ public void chapter01TestLoadLibrary() throws Exception {
String nativesPath = testOutput + "/build/natives";
System.load(nativesPath + "/libtest1.so");
+ }
+
+ /**
+ * Verifies the existence and creation of the generated class.
+ */
+ @Test
+ public void chapter01TestClassExist() throws Exception {
+ Class<?> clazzIf = Class.forName("com.jogamp.gluegen.test.junit.BindingTest1");
+ Class<?> clazzImpl = Class.forName("com.jogamp.gluegen.test.junit.impl.BindingTest1Impl");
- Class<?> clazz = Class.forName("com.jogamp.gluegen.test.junit.BindingTest1");
+ Assert.assertNotNull("com.jogamp.gluegen.test.junit.BindingTest1 does not exist", clazzIf);
+ Assert.assertNotNull("com.jogamp.gluegen.test.junit.impl.BindingTest1Impl does not exist", clazzImpl);
- Assert.assertNotNull("com.jogamp.gluegen.test.junit.BindingTest1 does not exist", clazz);
- Assert.assertEquals((int)1, clazz.getDeclaredField("CONSTANT_ONE").get(null));
+ Assert.assertEquals((int)1, clazzIf.getDeclaredField("CONSTANT_ONE").get(null));
- Object obj = clazz.newInstance();
+ Object obj = clazzImpl.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;
+ BindingTest1 bindingTest1 = (BindingTest1) obj;
Assert.assertTrue("nopTest1 failed", 42==bindingTest1.nopTest());
+ }
+
+ /**
+ * Verifies if all methods / signatures are properly generated,
+ * and can be invoked.
+ * Gluegen Coverage test.
+ * This is a compilation and runtime time test.
+ */
+ @Test
+ public void chapter01TestCoverage() throws Exception {
+ int dummy;
+
+ int array_size = 10;
+ long context = 0;
+ ByteBuffer bb1 = BufferFactory.newDirectByteBuffer(PointerBuffer.elementSize() * array_size);
+ ByteBuffer bb2 = BufferFactory.newDirectByteBuffer(PointerBuffer.elementSize() * array_size);
+
+ PointerBuffer pb1 = PointerBuffer.allocateDirect(array_size);
+ PointerBuffer pb2 = PointerBuffer.allocateDirect(array_size);
+
+ long[] larray1 = new long[array_size];
+ int array1_offset = 0;
+
+ long[] larray2 = new long[array_size];
+ int array2_offset = 0;
+
+ BindingTest1 binding = new BindingTest1Impl();
+
+ /** Interface to C language function: <br> <code> int arrayTest(long context, foo * array); </code> */
+ dummy = binding.arrayTest(context, pb1);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int arrayTest(long context, foo * array); </code> */
+ dummy = binding.arrayTest(context, larray1, array1_offset);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int bufferTest(void * object); </code> */
+ dummy = binding.bufferTest(bb1);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int doubleTest(long context, void * object1, foo * array1, void * object2, foo * array2); </code> */
+ dummy = binding.doubleTest(context, bb1, pb1, bb2, pb2);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int doubleTest(long context, void * object1, foo * array1, void * object2, foo * array2); </code> */
+ dummy = binding.doubleTest(context, bb1, larray1, array1_offset, bb2, larray2, array2_offset);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int mixedTest(long context, void * object, foo * array); </code> */
+ dummy = binding.mixedTest(context, bb1, pb1);
+ Assert.assertTrue(42==dummy);
+
+ /** Interface to C language function: <br> <code> int mixedTest(long context, void * object, foo * array); </code> */
+ dummy = binding.mixedTest(context, bb1, larray1, array1_offset);
+ Assert.assertTrue(42==dummy);
- // 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");
- }
- */
+ /** Interface to C language function: <br> <code> int nopTest(); </code> */
+ dummy = binding.nopTest();
+ Assert.assertTrue(42==dummy);
}
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
index fe6cb5c..291e6cc 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
@@ -1,6 +1,6 @@
Package com.jogamp.gluegen.test.junit
JavaClass BindingTest1
-Style AllStatic
+Style InterfaceAndImpl
JavaOutputDir classes
NativeOutputDir native
@@ -19,10 +19,17 @@ NativeOutputDir native
# pointer typedefs for these routines to MYAPIENTRY
#LocalProcAddressCallingConvention __ALL__ MYAPIENTRY
+#EmitProcAddressTable true
+#ProcAddressTableClassName CLProcAddressTable
+#GetProcAddressTableExpr addressTable
+#ProcAddressNameExpr $UpperCase(arg)
+#ForceProcAddressGen clGetGLContextInfoKHR
+
CustomCCode #include "test1.h"
# Imports needed by all glue code
Import java.nio.*
Import java.util.*
+Import com.jogamp.gluegen.test.junit.BindingTest1