summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/build.xml32
-rw-r--r--make/lib/junit-4.5.jarbin0 -> 198945 bytes
-rw-r--r--nbproject/ide-file-targets.xml38
-rwxr-xr-xnbproject/project.xml35
-rw-r--r--test/junit/com/sun/gluegen/AbstractTest.java120
-rw-r--r--test/junit/com/sun/gluegen/BasicTest.java101
-rw-r--r--test/junit/com/sun/gluegen/GlueGenTest.java206
-rw-r--r--test/junit/com/sun/gluegen/StructAccessorTest.java93
-rw-r--r--test/junit/com/sun/gluegen/StructValidator.java77
-rw-r--r--test/junit/com/sun/gluegen/build.xml10
-rw-r--r--test/junit/com/sun/gluegen/struct.cfg7
-rw-r--r--test/junit/com/sun/gluegen/struct.h21
-rw-r--r--test/junit/com/sun/gluegen/test.c4
-rw-r--r--test/junit/com/sun/gluegen/test.h2
14 files changed, 517 insertions, 229 deletions
diff --git a/make/build.xml b/make/build.xml
index 7832aea..fdcdbb0 100755
--- a/make/build.xml
+++ b/make/build.xml
@@ -419,7 +419,7 @@
<javac destdir="${classes-cdc}"
source="1.4"
debug="true"
- debuglevel="source,lines"
+ debuglevel="source,lines,vars"
excludes="${gluegen.excludes}"
bootclasspath="${javac.bootclasspath-cdc.jar}">
<src path="${src.java}" />
@@ -489,7 +489,7 @@
<javac destdir="${classes}"
source="1.4"
debug="true"
- debuglevel="source,lines"
+ debuglevel="source,lines,vars"
includes="${gluegen-rt.classes}"
excludes="${gluegen.excludes}">
<src path="${src.java}" />
@@ -501,7 +501,7 @@
<javac destdir="${classes}"
source="1.5"
debug="true"
- debuglevel="source,lines"
+ debuglevel="source,lines,vars"
excludes="${gluegen.excludes},${gluegen-rt.classes}">
<src path="${src.java}" />
<src path="${src.generated.java}" />
@@ -562,11 +562,35 @@
<copy file="${antlr.jar}" todir="${build}" />
</target>
- <target name="all" depends="gluegen.build" />
+ <target name="all" depends="gluegen.build,test" />
<target name="clean" depends="init">
<delete includeEmptyDirs="true">
<fileset dir="${build}" />
</delete>
</target>
+
+ <target name="test">
+ <mkdir dir="${basedir}/../build/test/build/classes"/>
+ <mkdir dir="${basedir}/../build/test/results"/>
+
+ <javac destdir="${basedir}/../build/test/build/classes" failonerror="false" source="1.5" srcdir="${basedir}/../test/junit" debug="true" debuglevel="lines,vars,source">
+ <classpath path="${basedir}/../make/lib/junit-4.5.jar:${basedir}/../build/classes:${basedir}/../build/test/gensrc/java:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ </javac>
+
+ <junit forkmode="once" showoutput="true" fork="true">
+ <jvmarg value="-Djava.library.path=${basedir}/../build/test/build/natives"/>
+ <batchtest todir="${basedir}/../build/test/results">
+ <fileset dir="${basedir}/../build/test/build/classes">
+ <include name="com/sun/gluegen/**"/>
+ </fileset>
+ <formatter usefile="false" type="brief"/>
+ <formatter usefile="true" type="xml"/>
+ </batchtest>
+ <classpath>
+ <path path="${basedir}/../build/test/build/classes:${basedir}/../build/test/gensrc/java:${basedir}/../build/classes:${basedir}/../lib/antlr-3.2.jar:${basedir}/../make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ </classpath>
+ </junit>
+ </target>
+
</project>
diff --git a/make/lib/junit-4.5.jar b/make/lib/junit-4.5.jar
new file mode 100644
index 0000000..7339216
--- /dev/null
+++ b/make/lib/junit-4.5.jar
Binary files differ
diff --git a/nbproject/ide-file-targets.xml b/nbproject/ide-file-targets.xml
index b1b8475..f763c48 100644
--- a/nbproject/ide-file-targets.xml
+++ b/nbproject/ide-file-targets.xml
@@ -1,60 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir=".." name="GlueGen-IDE">
- <property name="ant.script" value="make/build.xml"/>
-
<!-- edit the following targets according to your needs -->
<!-- (more info: http://www.netbeans.org/kb/articles/freeform-config.html-->
+ <target name="compile-test">
+
+ <mkdir dir="build/test/build/classes"/>
+
+ <javac destdir="build/test/build/classes" failonerror="false" source="1.5" srcdir="test/junit" debug="true" debuglevel="lines,vars,source">
+ <classpath path="build/test/build/classes:build/classes:build/test/gensrc/java:lib/antlr-3.2.jar:make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ </javac>
+ </target>
+
<target name="compile-selected-files-in-junit">
<fail unless="files">Must set property 'files'</fail>
<mkdir dir="build/test/build/classes"/>
<javac destdir="build/test/build/classes" includes="${files}" source="1.5" srcdir="test/junit" debug="true" debuglevel="lines,vars,source">
- <classpath path="build/test/build/classes:build/classes:build/test/gensrc/java:lib/antlr-3.2.jar:lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ <classpath path="build/test/build/classes:build/classes:build/test/gensrc/java:lib/antlr-3.2.jar:make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</javac>
</target>
- <target name="run-selected-file-in-junit">
+ <target name="run-selected-file-in-junit" depends="compile-test">
<fail unless="run.class">Must set property 'run.class'</fail>
<java classname="${run.class}" failonerror="true" fork="true">
<classpath>
- <path path="build/test/build/classes:build/classes:lib/antlr-3.2.jar:lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ <path path="build/test/build/classes:build/classes:lib/antlr-3.2.jar:make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</classpath>
</java>
</target>
- <target name="test-selected-file-in-junit">
+ <target name="test-selected-file-in-junit" depends="compile-test">
<fail unless="run.class">Must set property 'run.class'</fail>
-
<junit forkmode="once" showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed">
<test name="${run.class}">
</test>
+ <jvmarg value="-Djava.library.path=${basedir}/build/test/build/natives"/>
<classpath>
- <path path="build/test/build/classes:build/test/gensrc/java:build/classes:lib/antlr-3.2.jar:lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ <path path="build/test/build/classes:build/test/gensrc/java:build/classes:lib/antlr-3.2.jar:make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</classpath>
<formatter usefile="false" type="brief"/>
- <formatter type="xml"/>
</junit>
</target>
- <target name="debug-selected-file-in-junit">
- <fail unless="debug.class">Must set property 'debug.class'</fail>
+ <target name="debug-selected-file-in-junit" depends="compile-test">
+ <fail unless="run.class">Must set property 'debug.class'</fail>
<path id="cp">
- <path path="build/test/build/classes:build/classes:lib/antlr-3.2.jar:lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ <path path="build/test/build/classes:build/test/gensrc/java:build/classes:lib/antlr-3.2.jar:make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</path>
<nbjpdastart addressproperty="jpda.address" name="GlueGen" transport="dt_socket">
<classpath refid="cp"/>
</nbjpdastart>
- <java classname="${debug.class}" fork="true">
+ <junit forkmode="once" showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed">
+ <test name="${run.class}">
+ </test>
<classpath refid="cp"/>
+ <jvmarg value="-Djava.library.path=${basedir}/build/test/build/natives"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
+ <formatter usefile="false" type="brief"/>
+ </junit>
+ <java classname="${run.class}" fork="true">
</java>
</target>
diff --git a/nbproject/project.xml b/nbproject/project.xml
index e42488b..84bdc44 100755
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -41,6 +41,12 @@
<location>build/test</location>
<encoding>UTF-8</encoding>
</source-folder>
+ <source-folder>
+ <label>build/test/gensrc/java</label>
+ <type>java</type>
+ <location>build/test/gensrc/java</location>
+ <encoding>UTF-8</encoding>
+ </source-folder>
</folders>
<ide-actions>
<action name="build">
@@ -82,6 +88,19 @@
</arity>
</context>
</action>
+ <action name="debug.test.single">
+ <script>nbproject/ide-file-targets.xml</script>
+ <target>debug-selected-file-in-junit</target>
+ <context>
+ <property>run.class</property>
+ <folder>test/junit</folder>
+ <pattern>\.java$</pattern>
+ <format>java-name</format>
+ <arity>
+ <one-file-only/>
+ </arity>
+ </context>
+ </action>
<action name="compile.single">
<script>nbproject/ide-file-targets.xml</script>
<target>compile-selected-files-in-junit</target>
@@ -108,6 +127,10 @@
</arity>
</context>
</action>
+ <action name="test">
+ <script>${ant.script}</script>
+ <target>test</target>
+ </action>
</ide-actions>
<export>
<type>folder</type>
@@ -145,6 +168,10 @@
<label>build/test</label>
<location>build/test</location>
</source-folder>
+ <source-folder style="packages">
+ <label>build/test/gensrc/java</label>
+ <location>build/test/gensrc/java</location>
+ </source-folder>
<source-file>
<location>${ant.script}</location>
</source-file>
@@ -153,6 +180,7 @@
<ide-action name="build"/>
<ide-action name="rebuild"/>
<ide-action name="clean"/>
+ <ide-action name="test"/>
</context-menu>
</view>
<subprojects/>
@@ -173,7 +201,7 @@
<compilation-unit>
<package-root>test/junit</package-root>
<unit-tests/>
- <classpath mode="compile">build/classes:build/test/gensrc/java:lib/antlr-3.2.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}:lib/junit-4.5.jar</classpath>
+ <classpath mode="compile">build/classes:build/test/build/classes:lib/antlr-3.2.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}:make/lib/junit-4.5.jar</classpath>
<built-to>build/classes</built-to>
<source-level>1.5</source-level>
</compilation-unit>
@@ -181,6 +209,11 @@
<package-root>build/test</package-root>
<source-level>1.5</source-level>
</compilation-unit>
+ <compilation-unit>
+ <package-root>build/test/gensrc/java</package-root>
+ <unit-tests/>
+ <source-level>1.5</source-level>
+ </compilation-unit>
</java-data>
<preferences xmlns="http://www.netbeans.org/ns/auxiliary-configuration-preferences/1">
<module name="org-netbeans-modules-editor-indent"/>
diff --git a/test/junit/com/sun/gluegen/AbstractTest.java b/test/junit/com/sun/gluegen/AbstractTest.java
new file mode 100644
index 0000000..9262347
--- /dev/null
+++ b/test/junit/com/sun/gluegen/AbstractTest.java
@@ -0,0 +1,120 @@
+package com.sun.gluegen;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+import static java.lang.System.*;
+
+/**
+ * @author Michael Bien
+ */
+@Ignore
+public abstract class AbstractTest {
+
+ static final Project project = new Project();
+
+ protected static String gluegenRoot;
+ protected static String path;
+ protected static String output;
+
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
+ out.println(" - - - System info - - - ");
+ out.println("OS: " + System.getProperty("os.name"));
+ out.println("VM: " + System.getProperty("java.vm.name"));
+
+ // setup paths
+ try {
+ File executionRoot = new File(AbstractTest.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);
+ }
+
+ path = gluegenRoot + "/test/junit/com/sun/gluegen";
+ output = gluegenRoot + "/build/test";
+
+ out.println("path: "+path);
+ out.println("output: "+output);
+ out.println(" - - - - - - - - - - - - ");
+
+ deleteDirectory(new File(output+"/gensrc"));
+
+ //setup ant build file
+ project.setBaseDir(new File(gluegenRoot));
+
+ DefaultLogger logger = new DefaultLogger();
+ logger.setErrorPrintStream(err);
+ logger.setOutputPrintStream(out);
+ logger.setMessageOutputLevel(Project.MSG_INFO);
+ project.addBuildListener(logger);
+
+ project.init();
+
+ File buildFile = new File(path, "build.xml");
+ ProjectHelper.configureProject(project, buildFile);
+ }
+
+ @AfterClass
+ public static void tearDown() {
+// deleteDirectory(new File(output));
+ }
+
+ /**
+ * fails if ant script fails (which is a good thing).
+ * executeTarget throws RuntimeException on failure
+ */
+ public final void compileJava() {
+ project.executeTarget("compile.java");
+ }
+
+ /**
+ * fails if ant script fails (which is a good thing)
+ * executeTarget throws RuntimeException on failure
+ */
+ public final void compileNatives() {
+ project.executeTarget("compile.native");
+ }
+
+ static final void generate(String config) {
+ out.println("generate: "+config);
+ GlueGen.main(
+ new String[] {
+ "-I"+path,
+ "-O"+output+"/gensrc",
+// "-Ecom.sun.gluegen.DebugEmitter",
+ "-C"+path+"/"+config+".cfg",
+ path+"/"+config+".h"
+ }
+ );
+ out.println("done");
+ }
+
+ static final void deleteDirectory(File path) {
+ if(path.exists()) {
+
+ File[] files = path.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ deleteDirectory(files[i]);
+ } else {
+ files[i].delete();
+ }
+ }
+
+ path.delete();
+ }
+ }
+
+
+}
diff --git a/test/junit/com/sun/gluegen/BasicTest.java b/test/junit/com/sun/gluegen/BasicTest.java
new file mode 100644
index 0000000..89a4c21
--- /dev/null
+++ b/test/junit/com/sun/gluegen/BasicTest.java
@@ -0,0 +1,101 @@
+package com.sun.gluegen;
+
+import com.sun.gluegen.runtime.BufferFactory;
+import com.sun.gluegen.runtime.PointerBuffer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import org.junit.Test;
+import static java.lang.System.*;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class BasicTest extends AbstractTest {
+
+ @Test
+ public void generateBindingTest() {
+ generate("test");
+ }
+
+ /**
+ * fails if ant script fails (which is a good thing).
+ * executeTarget throws RuntimeException on failure
+ */
+ @Test
+ public void compileJavaTest() {
+ compileJava();
+ }
+
+ /*
+ * fails if ant script fails (which is a good thing)
+ * executeTarget throws RuntimeException on failure
+ */
+ @Test
+ public void compileNativesTest() {
+ compileNatives();
+ }
+
+// @Test
+ public void bindingTest() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, InstantiationException {
+
+ String nativesPath = gluegenRoot + "/build/test/build/natives";
+ System.load(nativesPath + "/librofl.so");
+
+ Object bindingTest = Class.forName("test.BindingTest").newInstance();
+
+ // 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
+ Method[] methods = bindingTest.getClass().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();
+
+ // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError: test.BindingTest.arrayTest0(JLjava/lang/Object;I)I
+
+ Object result = method.invoke(bindingTest, paramInstances);
+ out.println("result: "+result);
+ out.println("success");
+ }
+
+ }
+
+}
diff --git a/test/junit/com/sun/gluegen/GlueGenTest.java b/test/junit/com/sun/gluegen/GlueGenTest.java
deleted file mode 100644
index c21f1ba..0000000
--- a/test/junit/com/sun/gluegen/GlueGenTest.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package com.sun.gluegen;
-
-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.apache.tools.ant.DefaultLogger;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectHelper;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static java.lang.System.*;
-
-/**
- * @author Michael Bien
- */
-public class GlueGenTest {
-
- private static final Project project = new Project();
-
- private static String gluegenRoot;
- private static String path;
- private static String output;
-
-
- @BeforeClass
- public static void setUpTest() throws Exception {
-
- out.println("System info: ");
- out.println("OS: " + System.getProperty("os.name"));
- out.println("VM: " + System.getProperty("java.vm.name"));
-
- // setup paths
- try {
- File executionRoot = new File(GlueGenTest.class.getProtectionDomain().getCodeSource().getLocation().toURI());
- System.out.println("execution root: " + executionRoot);
- gluegenRoot = executionRoot.getParentFile().getParentFile().getParentFile().getParentFile().toString();
- System.out.println("gluegen project root: " + gluegenRoot);
- } catch (URISyntaxException ex) {
- Logger.getLogger(GlueGenTest.class.getName()).log(Level.SEVERE, "can not determine gluegen root", ex);
- Assert.fail();
- }
-
- path = gluegenRoot + "/test/junit/com/sun/gluegen";
- output = gluegenRoot + "/build/test";
-
- //setup ant build file
- project.setBaseDir(new File(gluegenRoot));
-
- DefaultLogger logger = new DefaultLogger();
- logger.setErrorPrintStream(err);
- logger.setOutputPrintStream(out);
- logger.setMessageOutputLevel(Project.MSG_INFO);
- project.addBuildListener(logger);
-
- project.init();
-
- File buildFile = new File(path, "build.xml");
- ProjectHelper.configureProject(project, buildFile);
- }
-
- @Test
- public void generateBindingTest() {
-
- out.println("path: "+path);
- out.println("output: "+output);
-
- String name = "test";
-
- GlueGen.main(
- new String[] {
- "-I"+path,
- "-O"+output+"/gensrc",
-// "-Ecom.sun.gluegen.DebugEmitter",
- "-C"+path+"/"+name+".cfg",
- path+"/"+name+".h"
- }
- );
- }
-
- /* yeah, java 6 has even a compiler api...
- @Test
- public void compileJavaTest() throws IOException {
-
- out.println("compiling generated files...");
-
- String source = output+"/gensrc/java/test/BindingTest.java";
-
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
- StandardJavaFileManager fileManager = compiler.getStandardFileManager(collector, null, null);
-
- Iterable<? extends JavaFileObject> fileObj = fileManager.getJavaFileObjects(source);
-
- compiler.getTask( new OutputStreamWriter(out),
- fileManager,
- collector,
- Arrays.asList("-d",output+"/build/java","-verbose"),
- null,
- fileObj ).call();
-
- List<Diagnostic<? extends JavaFileObject>> list = collector.getDiagnostics();
- if(!list.isEmpty()) {
- for (Diagnostic<? extends JavaFileObject> d : list) {
- out.println("Error on line "+ d.getLineNumber());
- out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH));
- }
- Assert.fail("compilation test failed");
- }
-
- fileManager.close();
-
- out.println("done");
-
- }
-*/
-
- /*
- * fails when ant script fails (which is a good thing).
- * executeTarget throws RuntimeException on failure
- */
- @Test
- public void compileJavaTest() {
- project.executeTarget("compile.java");
- }
-
- /*
- * fails when ant script fails (which is a good thing)
- * executeTarget throws RuntimeException on failure
- */
- @Test
- public void compileNativesTest() {
- project.executeTarget("compile.native");
- }
-
- @Test
- public void bindingTest() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, InstantiationException {
-
- String nativesPath = output + "/build/natives";
- System.load(nativesPath + "/libgluegen-rt.so");
- System.load(nativesPath + "/librofl.so");
-
- Object bindingTest = Class.forName("test.BindingTest").newInstance();
-
- // 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
- Method[] methods = bindingTest.getClass().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();
-
- // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError: test.BindingTest.arrayTest0(JLjava/lang/Object;I)I
-
- Object result = method.invoke(bindingTest, paramInstances);
- out.println("result: "+result);
- out.println("success");
- }
-
- }
-
-
-}
diff --git a/test/junit/com/sun/gluegen/StructAccessorTest.java b/test/junit/com/sun/gluegen/StructAccessorTest.java
new file mode 100644
index 0000000..f89eb43
--- /dev/null
+++ b/test/junit/com/sun/gluegen/StructAccessorTest.java
@@ -0,0 +1,93 @@
+package com.sun.gluegen;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import junit.framework.Assert;
+import org.junit.Test;
+import static java.lang.System.*;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class StructAccessorTest extends AbstractTest {
+
+ @Test
+ public void generateStruct() {
+ generate("struct");
+ }
+
+ @Test
+ public void compileStructJava() {
+ super.compileJava();
+ }
+
+ @Test
+ public void compileStructNatives() {
+ // this will only copy gluegen-rt to the right place
+ super.compileNatives();
+ }
+
+ @Test
+ public void validateGeneratedStructs() throws IOException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException {
+
+ // compile testcase
+ String source = gluegenRoot + "/test/junit/com/sun/gluegen/StructValidator.java";
+ compile(new File(source), gluegenRoot+"/build/test/build/classes");
+
+ // invoke test
+ Class<?> test = Class.forName("com.sun.gluegen.StructValidator");
+ test.getDeclaredMethod("validate").invoke(null);
+ }
+
+ private void compile(File file, String dest) throws IOException {
+ compile(new File[] {file}, dest);
+ }
+
+ // yeah, java 6 has even a compiler api...
+ private void compile(File[] files, String destination) throws IOException {
+
+ out.println("compiling files:\n" + Arrays.asList(files));
+
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
+ StandardJavaFileManager fileManager = compiler.getStandardFileManager(collector, null, null);
+
+ Iterable<? extends JavaFileObject> fileObj = fileManager.getJavaFileObjects(files);
+
+ compiler.getTask( new OutputStreamWriter(out),
+ fileManager,
+ collector,
+ Arrays.asList("-d", destination/*, "-verbose"*/),
+ null,
+ fileObj ).call();
+
+ List<Diagnostic<? extends JavaFileObject>> list = collector.getDiagnostics();
+ if(!list.isEmpty()) {
+ for (Diagnostic<? extends JavaFileObject> d : list) {
+ out.println("Error on line "+ d.getLineNumber());
+ out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH));
+ }
+ Assert.fail("compilation failed");
+ }
+
+ fileManager.close();
+
+ out.println("done");
+
+ }
+
+
+
+}
diff --git a/test/junit/com/sun/gluegen/StructValidator.java b/test/junit/com/sun/gluegen/StructValidator.java
new file mode 100644
index 0000000..1fe845c
--- /dev/null
+++ b/test/junit/com/sun/gluegen/StructValidator.java
@@ -0,0 +1,77 @@
+package com.sun.gluegen;
+
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Ignore;
+
+import static org.junit.Assert.*;
+
+/**
+ * this file will not compile unless {@link com.sun.gluegen.StructAccessorTest} has been run.
+ * @author Michael Bien
+ */
+@Ignore
+public class StructValidator {
+
+ // invoked via reflection from StructAccessorTest1
+ public static void validate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
+
+ System.out.println("validating struct accessors...");
+
+ float[] mu = new float[] {1, 2, 3, 4};
+ float[] light = new float[] {5, 6, 7};
+ int fastRendering = 1;
+ int shadow = 42;
+ int iterations = 512;
+ int sss = 12;
+ float epsilon = (float) Math.PI;
+ int height = 640;
+ int width = 480;
+
+ structtest.RenderingConfig config = structtest.RenderingConfig.create();
+
+ //set
+ config.setLight(light);
+ config.setMu(mu);
+ config.setActvateFastRendering(fastRendering);
+ config.setEnableShadow(shadow);
+ config.setMaxIterations(iterations);
+ config.setEpsilon(epsilon);
+ config.setSuperSamplingSize(sss);
+ config.setWidth(width);
+ config.setHeight(height);
+
+ structtest.Camera camera = config.getCamera();
+ camera.getOrig().setX(1001).setY(1002).setZ(1003);
+ camera.getDir().setX(2001).setY(2002).setZ(2003);
+
+ //get and validate
+ assertArrayEquals(mu, config.getMu());
+ assertArrayEquals(light, config.getLight());
+
+ assertEquals(fastRendering, config.getActvateFastRendering());
+ assertEquals(shadow, config.getEnableShadow());
+ assertEquals(iterations, config.getMaxIterations());
+ assertEquals(epsilon, config.getEpsilon(), 0.01f);
+ assertEquals(sss, config.getSuperSamplingSize());
+ assertEquals(width, config.getWidth());
+ assertEquals(height, config.getHeight());
+
+ assertEquals(camera.getOrig().getX(), 1001, 0.001);
+ assertEquals(camera.getOrig().getY(), 1002, 0.001);
+ assertEquals(camera.getOrig().getZ(), 1003, 0.001);
+
+ assertEquals(camera.getDir().getX(), 2001, 0.001);
+ assertEquals(camera.getDir().getY(), 2002, 0.001);
+ assertEquals(camera.getDir().getZ(), 2003, 0.001);
+
+ System.out.println("done");
+
+ }
+
+ private static final void assertArrayEquals(float[] a, float[] b) {
+ for (int i = 0; i < b.length; i++) {
+ assertEquals(a[i], b[i], 0.0001f);
+ }
+ }
+
+}
diff --git a/test/junit/com/sun/gluegen/build.xml b/test/junit/com/sun/gluegen/build.xml
index cdc11ea..58ab781 100644
--- a/test/junit/com/sun/gluegen/build.xml
+++ b/test/junit/com/sun/gluegen/build.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project name="GlueGenTest" default="default" basedir=".">
+<project name="GlueGenTest" default="default" basedir="../../../../../">
<description>Tests GlueGen</description>
@@ -20,9 +20,9 @@
<mkdir dir="${build.dir.java}"/>
- <javac destdir="${build.dir.java}" includes="test/**" source="1.5" debug="true" verbose="true" debuglevel="lines,vars,source">
+ <javac destdir="${build.dir.java}" source="1.5" debug="true" verbose="true" debuglevel="lines,vars,source">
<src path="${src.dir}"/>
- <classpath path="build/test/build/java:build/classes:build/test/gensrc/java:lib/antlr-2.7.7.jar:lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
+ <classpath path="${basedir}/build/test/build/java:${basedir}/build/classes:${basedir}/build/test/gensrc/java:${basedir}/lib/antlr-2.7.7.jar:${basedir}/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</javac>
<echo message=" - - - java files compiled - - - "/>
@@ -38,7 +38,6 @@
<property name="output.lib.name" value="rofl"/>
<property name="obj.dir" value="${obj.dir}/${output.lib.name}"/>
- <property name="natives.dir" value="${build.dir}/natives/${output.lib.name}"/>
<property name="c.compiler.optimise" value="none"/>
<property name="c.compiler.debug" value="false"/>
@@ -84,9 +83,10 @@
<echo message="configure for Linux.AMD64 build" />
<linker id="linker.cfg.linux.amd64.test">
+ <linkerparam name="-m64"/>
</linker>
- <property name="compiler.cfg.id" value="compiler.cfg.linux" />
+ <property name="compiler.cfg.id" value="compiler.cfg.linux.amd64" />
<property name="linker.cfg.id" value="linker.cfg.linux.amd64.test" />
</target>
diff --git a/test/junit/com/sun/gluegen/struct.cfg b/test/junit/com/sun/gluegen/struct.cfg
new file mode 100644
index 0000000..a1e1138
--- /dev/null
+++ b/test/junit/com/sun/gluegen/struct.cfg
@@ -0,0 +1,7 @@
+Package structtest
+
+JavaOutputDir java
+
+EmitStruct Vec
+EmitStruct Camera
+EmitStruct RenderingConfig
diff --git a/test/junit/com/sun/gluegen/struct.h b/test/junit/com/sun/gluegen/struct.h
new file mode 100644
index 0000000..2819d5c
--- /dev/null
+++ b/test/junit/com/sun/gluegen/struct.h
@@ -0,0 +1,21 @@
+
+typedef struct {
+ float x, y, z;
+} Vec;
+
+typedef struct {
+ Vec orig, dir;
+} Camera;
+
+typedef struct {
+ unsigned int width, height;
+ int superSamplingSize;
+ int actvateFastRendering;
+ int enableShadow;
+
+ unsigned int maxIterations;
+ float epsilon;
+ float mu[4];
+ float light[3];
+ Camera camera;
+} RenderingConfig;
diff --git a/test/junit/com/sun/gluegen/test.c b/test/junit/com/sun/gluegen/test.c
index d8c26a1..06d5508 100644
--- a/test/junit/com/sun/gluegen/test.c
+++ b/test/junit/com/sun/gluegen/test.c
@@ -8,6 +8,10 @@ int bufferTest(void * object) {
return 42;
}
+int manyBuffersTest(void * object1, void * object2, void * object3, void * object4, void * object5) {
+ return 42;
+}
+
int mixedTest(long context, void * object, foo * array){
return 42;
}
diff --git a/test/junit/com/sun/gluegen/test.h b/test/junit/com/sun/gluegen/test.h
index 02a22c1..b15b7e5 100644
--- a/test/junit/com/sun/gluegen/test.h
+++ b/test/junit/com/sun/gluegen/test.h
@@ -5,6 +5,8 @@ int arrayTest(long context, foo * array );
int bufferTest(void * object);
+int manyBuffersTest(void * object1, void * object2, void * object3, void * object4, void * object5);
+
int mixedTest(long context, void * object, foo * array );
int doubleTest(long context, void * object1, foo * array1, void * object2, foo * array2 );