From ed83567444bd803918b8904eb71b155d4eff2de4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 7 Nov 2010 04:35:47 +0100 Subject: com.sun -> com.jogamp --- .../gluegen/BasicProcAddressEmitterTest.java | 96 +++++++++++ test/junit/com/jogamp/gluegen/BasicTest.java | 143 ++++++++++++++++ test/junit/com/jogamp/gluegen/BuildUtil.java | 179 +++++++++++++++++++++ test/junit/com/jogamp/gluegen/PCPPTest.java | 76 +++++++++ .../com/jogamp/gluegen/StructAccessorTest.java | 126 +++++++++++++++ test/junit/com/jogamp/gluegen/StructValidator.java | 105 ++++++++++++ test/junit/com/jogamp/gluegen/build.xml | 95 +++++++++++ test/junit/com/jogamp/gluegen/dyntest.cfg | 25 +++ test/junit/com/jogamp/gluegen/pcpptest.h | 6 + test/junit/com/jogamp/gluegen/struct.cfg | 7 + test/junit/com/jogamp/gluegen/struct.h | 21 +++ test/junit/com/jogamp/gluegen/test.c | 24 +++ test/junit/com/jogamp/gluegen/test.cfg | 9 ++ test/junit/com/jogamp/gluegen/test.h | 17 ++ .../sun/gluegen/BasicProcAddressEmitterTest.java | 96 ----------- test/junit/com/sun/gluegen/BasicTest.java | 143 ---------------- test/junit/com/sun/gluegen/BuildUtil.java | 179 --------------------- test/junit/com/sun/gluegen/PCPPTest.java | 76 --------- test/junit/com/sun/gluegen/StructAccessorTest.java | 126 --------------- test/junit/com/sun/gluegen/StructValidator.java | 105 ------------ test/junit/com/sun/gluegen/build.xml | 95 ----------- test/junit/com/sun/gluegen/dyntest.cfg | 25 --- test/junit/com/sun/gluegen/pcpptest.h | 6 - test/junit/com/sun/gluegen/struct.cfg | 7 - test/junit/com/sun/gluegen/struct.h | 21 --- test/junit/com/sun/gluegen/test.c | 24 --- test/junit/com/sun/gluegen/test.cfg | 9 -- test/junit/com/sun/gluegen/test.h | 17 -- 28 files changed, 929 insertions(+), 929 deletions(-) create mode 100644 test/junit/com/jogamp/gluegen/BasicProcAddressEmitterTest.java create mode 100644 test/junit/com/jogamp/gluegen/BasicTest.java create mode 100644 test/junit/com/jogamp/gluegen/BuildUtil.java create mode 100644 test/junit/com/jogamp/gluegen/PCPPTest.java create mode 100644 test/junit/com/jogamp/gluegen/StructAccessorTest.java create mode 100644 test/junit/com/jogamp/gluegen/StructValidator.java create mode 100644 test/junit/com/jogamp/gluegen/build.xml create mode 100644 test/junit/com/jogamp/gluegen/dyntest.cfg create mode 100644 test/junit/com/jogamp/gluegen/pcpptest.h create mode 100644 test/junit/com/jogamp/gluegen/struct.cfg create mode 100644 test/junit/com/jogamp/gluegen/struct.h create mode 100644 test/junit/com/jogamp/gluegen/test.c create mode 100644 test/junit/com/jogamp/gluegen/test.cfg create mode 100644 test/junit/com/jogamp/gluegen/test.h delete mode 100644 test/junit/com/sun/gluegen/BasicProcAddressEmitterTest.java delete mode 100644 test/junit/com/sun/gluegen/BasicTest.java delete mode 100644 test/junit/com/sun/gluegen/BuildUtil.java delete mode 100644 test/junit/com/sun/gluegen/PCPPTest.java delete mode 100644 test/junit/com/sun/gluegen/StructAccessorTest.java delete mode 100644 test/junit/com/sun/gluegen/StructValidator.java delete mode 100644 test/junit/com/sun/gluegen/build.xml delete mode 100644 test/junit/com/sun/gluegen/dyntest.cfg delete mode 100644 test/junit/com/sun/gluegen/pcpptest.h delete mode 100644 test/junit/com/sun/gluegen/struct.cfg delete mode 100644 test/junit/com/sun/gluegen/struct.h delete mode 100644 test/junit/com/sun/gluegen/test.c delete mode 100644 test/junit/com/sun/gluegen/test.cfg delete mode 100644 test/junit/com/sun/gluegen/test.h (limited to 'test') diff --git a/test/junit/com/jogamp/gluegen/BasicProcAddressEmitterTest.java b/test/junit/com/jogamp/gluegen/BasicProcAddressEmitterTest.java new file mode 100644 index 0000000..10156f9 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/BasicProcAddressEmitterTest.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.gluegen; + +import com.jogamp.gluegen.procaddress.ProcAddressEmitter; +import java.lang.reflect.Field; +import java.util.HashSet; +import java.util.Set; +import org.junit.AfterClass; +import org.junit.Test; +import static java.util.Arrays.*; +import static com.jogamp.gluegen.BuildUtil.*; +import static org.junit.Assert.*; + +/** + * Basic test using ProcAddressEmitter. + * @author Michael Bien + */ +public class BasicProcAddressEmitterTest { + + @Test + public void generateBindingTest() { + generate("dyntest", "test", ProcAddressEmitter.class.getName()); + } + + /** + * 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 renameTest() throws Exception { + + Class binding = Class.forName("test.DynBindingTest"); + Class table = Class.forName("test.Table"); + + Field[] fields = table.getDeclaredFields(); + + + Set expected = new HashSet( + asList("arrayTest", "bufferTest", "pbTest", "manyBuffersTest", "mixedTest", "doubleTest")); + + for (Field field : fields) { + System.out.println("address field: "+field); + + String function = field.getName().substring("_addressoff_".length()-1); + assertTrue("unexpected field: '"+function+"'",expected.contains(function)); + } + + } + + @AfterClass + public static void tearDown() { +// cleanGeneratedFiles(); + } + +} diff --git a/test/junit/com/jogamp/gluegen/BasicTest.java b/test/junit/com/jogamp/gluegen/BasicTest.java new file mode 100644 index 0000000..38bb7f9 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/BasicTest.java @@ -0,0 +1,143 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.gluegen; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import org.junit.AfterClass; +import org.junit.Test; +import static org.junit.Assert.*; +import static java.lang.System.*; +import static com.jogamp.gluegen.BuildUtil.*; + +/** + * + * @author Michael Bien + */ +public class BasicTest { + + @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 Exception { + + // String nativesPath = testOutput + "/build/natives"; + // System.load(nativesPath + "/librofl.so"); + System.loadLibrary("rofl"); + + Class clazz = Class.forName("test.BindingTest"); + + 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 = Buffers.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"); + } + */ + } + + @AfterClass + public static void tearDown() { +// cleanGeneratedFiles(); + } + +} diff --git a/test/junit/com/jogamp/gluegen/BuildUtil.java b/test/junit/com/jogamp/gluegen/BuildUtil.java new file mode 100644 index 0000000..ce88ba2 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/BuildUtil.java @@ -0,0 +1,179 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.gluegen; + +import com.jogamp.gluegen.JavaEmitter; +import com.jogamp.gluegen.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 static java.lang.System.*; + +/** + * @author Michael Bien + */ +public final class BuildUtil { + + private static final Project project; + + public static final String gluegenRoot; + public static final String path; + 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(BuildUtil.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/jogamp/gluegen"; + testOutput = gluegenRoot + "/" + rootrel_build + "/test"; + + out.println("path: "+path); + out.println("testOutput: "+testOutput); + out.println(" - - - - - - - - - - - - "); + + cleanGeneratedFiles(); + + //setup ant build file + project = new Project(); + project.setProperty("rootrel.build", rootrel_build); + passSystemProperty(project, "gluegen-cpptasks.file"); + passSystemProperty(project, "os.arch"); + + DefaultLogger logger = new DefaultLogger(); + logger.setErrorPrintStream(out); + logger.setOutputPrintStream(out); + logger.setMessageOutputLevel(Project.MSG_WARN); + project.addBuildListener(logger); + + project.init(); + + File buildFile = new File(path, "build.xml"); + if(!buildFile.exists()) { + throw new RuntimeException("buildfile "+buildFile+" does not exist"); + } + + ProjectHelper.configureProject(project, buildFile); + } + + public static Project passSystemProperty(Project p, String name) { + String tmp = System.getProperty(name); + if(null!=tmp && tmp.length()>0) { + p.setProperty(name, tmp); + } + return p; + } + + public static void cleanGeneratedFiles() { + out.println("cleaning generated files"); + deleteDirectory(new File(testOutput+"/gensrc")); + out.println("done"); + } + + /** + * fails if ant script fails (which is a good thing). + * executeTarget throws RuntimeException on failure + */ + public static void compileJava() { + out.println("compiling java files"); + project.executeTarget("compile.java"); + out.println("done"); + } + + /** + * fails if ant script fails (which is a good thing) + * executeTarget throws RuntimeException on failure + */ + public static void compileNatives() { + out.println("compiling native files"); + project.executeTarget("compile.native"); + out.println("done"); + } + + public static void generate(String bindingName) { + generate(bindingName, JavaEmitter.class.getName()); +// generate(bindingName, DebugEmitter.class.getName()); + } + + public static void generate(String bindingName, String emitter) { + generate(bindingName, bindingName, emitter); + } + public static void generate(String bindingName, String header, String emitter) { + + out.println("generate binding to '" + bindingName+"' using '"+emitter+"'"); + + GlueGen.main( "-I"+path, + "-O"+testOutput+"/gensrc", + "-E"+emitter, + "-C"+path+"/"+bindingName+".cfg", + path+"/"+header+".h" ); + + out.println("done"); + } + + public static 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/jogamp/gluegen/PCPPTest.java b/test/junit/com/jogamp/gluegen/PCPPTest.java new file mode 100644 index 0000000..c1f12ab --- /dev/null +++ b/test/junit/com/jogamp/gluegen/PCPPTest.java @@ -0,0 +1,76 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.gluegen; + +import com.jogamp.gluegen.pcpp.PCPP; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Collections; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * serves mainly as entry point for debugging purposes. + * @author Michael Bien + */ +public class PCPPTest { + + @Test + public void pcppMacroDefinitionTest() throws FileNotFoundException, IOException { + + PCPP pp = new PCPP(Collections.emptyList()); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + pp.setOut(output); + + String filename = "pcpptest.h"; + String filepath = BuildUtil.path + "/" + filename; + + pp.run(new BufferedReader(new FileReader(filepath)), filename); + + String expected = "# 1 \"pcpptest.h\""+ + "# define CL_SCHAR_MIN (-127-1)"+ + " cl_char __attribute__(( aligned(2))) s[ 2];"+ + "# 7 \"pcpptest.h\""; + output.flush(); + String result = output.toString(); + output.close(); + + assertEquals(killWhitespace(expected), killWhitespace(result)); + + } + + private String killWhitespace(String a) { + return a.replaceAll("\\p{javaWhitespace}+", ""); + } + + +} diff --git a/test/junit/com/jogamp/gluegen/StructAccessorTest.java b/test/junit/com/jogamp/gluegen/StructAccessorTest.java new file mode 100644 index 0000000..4d1bffd --- /dev/null +++ b/test/junit/com/jogamp/gluegen/StructAccessorTest.java @@ -0,0 +1,126 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.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.AfterClass; +import org.junit.Test; +import static java.lang.System.*; +import static com.jogamp.gluegen.BuildUtil.*; + +/** + * + * @author Michael Bien + */ +public class StructAccessorTest { + + @Test + public void generateStruct() { + generate("struct"); + } + + @Test + public void compileStructJava() { + compileJava(); + } + + @Test + public void compileStructNatives() { + // this will only copy gluegen-rt to the right place + compileNatives(); + } + + @Test + public void validateGeneratedStructs() throws IOException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException { + + // compile testcase + String source = gluegenRoot + "/test/junit/com/jogamp/gluegen/StructValidator.java"; + compile(new File(source), testOutput + "/build/classes"); + + // invoke test + Class test = Class.forName("com.jogamp.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 collector = new DiagnosticCollector(); + StandardJavaFileManager fileManager = compiler.getStandardFileManager(collector, null, null); + + Iterable fileObj = fileManager.getJavaFileObjects(files); + + boolean success = compiler.getTask( new OutputStreamWriter(out), + fileManager, + collector, + Arrays.asList("-d", destination/*, "-verbose"*/), + null, + fileObj ).call(); + + fileManager.close(); + + List> list = collector.getDiagnostics(); + if(!list.isEmpty() || !success) { + for (Diagnostic d : list) { + out.println("Error on line "+ d.getLineNumber()); + out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH)); + } + Assert.fail("compilation failed"); + } + + out.println("done"); + + } + + @AfterClass + public static void tearDown() { +// cleanGeneratedFiles(); + } + +} diff --git a/test/junit/com/jogamp/gluegen/StructValidator.java b/test/junit/com/jogamp/gluegen/StructValidator.java new file mode 100644 index 0000000..b6eb426 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/StructValidator.java @@ -0,0 +1,105 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.gluegen; + +import java.lang.reflect.InvocationTargetException; +import org.junit.Ignore; + +import static org.junit.Assert.*; + +/** + * this file will not compile unless {@link com.jogamp.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/jogamp/gluegen/build.xml b/test/junit/com/jogamp/gluegen/build.xml new file mode 100644 index 0000000..95617be --- /dev/null +++ b/test/junit/com/jogamp/gluegen/build.xml @@ -0,0 +1,95 @@ + + + + + Tests GlueGen + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/junit/com/jogamp/gluegen/dyntest.cfg b/test/junit/com/jogamp/gluegen/dyntest.cfg new file mode 100644 index 0000000..60b8764 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/dyntest.cfg @@ -0,0 +1,25 @@ +Package test +Style AllStatic +JavaClass DynBindingTest +JavaOutputDir java +NativeOutputDir native + +CustomCCode #include "test.h" + +Import com.jogamp.common.nio.* + + +EmitProcAddressTable true +ProcAddressTableClassName Table +GetProcAddressTableExpr table +ProcAddressNameExpr $UpperCase(arg) + +ForceProcAddressGen __ALL__ + +CustomJavaCode DynBindingTest private final static Table table; +CustomJavaCode DynBindingTest static { +CustomJavaCode DynBindingTest table = new Table(); +CustomJavaCode DynBindingTest //table.reset(); +CustomJavaCode DynBindingTest } + +RenameJavaMethod arrayTest fancyArrayTest \ No newline at end of file diff --git a/test/junit/com/jogamp/gluegen/pcpptest.h b/test/junit/com/jogamp/gluegen/pcpptest.h new file mode 100644 index 0000000..58b8935 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/pcpptest.h @@ -0,0 +1,6 @@ + +#define CL_SCHAR_MIN (-127-1) +#define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) + +cl_char CL_ALIGNED(2) s[2]; + diff --git a/test/junit/com/jogamp/gluegen/struct.cfg b/test/junit/com/jogamp/gluegen/struct.cfg new file mode 100644 index 0000000..a1e1138 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/struct.cfg @@ -0,0 +1,7 @@ +Package structtest + +JavaOutputDir java + +EmitStruct Vec +EmitStruct Camera +EmitStruct RenderingConfig diff --git a/test/junit/com/jogamp/gluegen/struct.h b/test/junit/com/jogamp/gluegen/struct.h new file mode 100644 index 0000000..2819d5c --- /dev/null +++ b/test/junit/com/jogamp/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/jogamp/gluegen/test.c b/test/junit/com/jogamp/gluegen/test.c new file mode 100644 index 0000000..c511a53 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/test.c @@ -0,0 +1,24 @@ +#include "test.h" + +int arrayTest(long context, foo * array) { + return 42; +} + +int bufferTest(void * object) { + return 42; +} + +void pbTest(size_t * object) { +} + +int manyBuffersTest(void * object1, void * object2, void * object3, void * object4, void * object5) { + 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/test/junit/com/jogamp/gluegen/test.cfg b/test/junit/com/jogamp/gluegen/test.cfg new file mode 100644 index 0000000..a2ac567 --- /dev/null +++ b/test/junit/com/jogamp/gluegen/test.cfg @@ -0,0 +1,9 @@ +Package test +Style AllStatic +JavaClass BindingTest +JavaOutputDir java +NativeOutputDir native + +CustomCCode #include "test.h" + +Import com.jogamp.common.nio.* \ No newline at end of file diff --git a/test/junit/com/jogamp/gluegen/test.h b/test/junit/com/jogamp/gluegen/test.h new file mode 100644 index 0000000..cef2b7e --- /dev/null +++ b/test/junit/com/jogamp/gluegen/test.h @@ -0,0 +1,17 @@ +#define GL_INVALID_INDEX 0xFFFFFFFFu +#define AL_FLANGER_DEFAULT_FEEDBACK (-0.5f) + +typedef unsigned long foo; +typedef unsigned long size_t; + +int arrayTest(long context, foo * array ); + +int bufferTest(void * object); + +void pbTest(size_t * 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 ); diff --git a/test/junit/com/sun/gluegen/BasicProcAddressEmitterTest.java b/test/junit/com/sun/gluegen/BasicProcAddressEmitterTest.java deleted file mode 100644 index 10156f9..0000000 --- a/test/junit/com/sun/gluegen/BasicProcAddressEmitterTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.gluegen; - -import com.jogamp.gluegen.procaddress.ProcAddressEmitter; -import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.Set; -import org.junit.AfterClass; -import org.junit.Test; -import static java.util.Arrays.*; -import static com.jogamp.gluegen.BuildUtil.*; -import static org.junit.Assert.*; - -/** - * Basic test using ProcAddressEmitter. - * @author Michael Bien - */ -public class BasicProcAddressEmitterTest { - - @Test - public void generateBindingTest() { - generate("dyntest", "test", ProcAddressEmitter.class.getName()); - } - - /** - * 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 renameTest() throws Exception { - - Class binding = Class.forName("test.DynBindingTest"); - Class table = Class.forName("test.Table"); - - Field[] fields = table.getDeclaredFields(); - - - Set expected = new HashSet( - asList("arrayTest", "bufferTest", "pbTest", "manyBuffersTest", "mixedTest", "doubleTest")); - - for (Field field : fields) { - System.out.println("address field: "+field); - - String function = field.getName().substring("_addressoff_".length()-1); - assertTrue("unexpected field: '"+function+"'",expected.contains(function)); - } - - } - - @AfterClass - public static void tearDown() { -// cleanGeneratedFiles(); - } - -} diff --git a/test/junit/com/sun/gluegen/BasicTest.java b/test/junit/com/sun/gluegen/BasicTest.java deleted file mode 100644 index 38bb7f9..0000000 --- a/test/junit/com/sun/gluegen/BasicTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.gluegen; - -import com.jogamp.common.nio.Buffers; -import com.jogamp.common.nio.PointerBuffer; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import org.junit.AfterClass; -import org.junit.Test; -import static org.junit.Assert.*; -import static java.lang.System.*; -import static com.jogamp.gluegen.BuildUtil.*; - -/** - * - * @author Michael Bien - */ -public class BasicTest { - - @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 Exception { - - // String nativesPath = testOutput + "/build/natives"; - // System.load(nativesPath + "/librofl.so"); - System.loadLibrary("rofl"); - - Class clazz = Class.forName("test.BindingTest"); - - 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 = Buffers.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"); - } - */ - } - - @AfterClass - public static void tearDown() { -// cleanGeneratedFiles(); - } - -} diff --git a/test/junit/com/sun/gluegen/BuildUtil.java b/test/junit/com/sun/gluegen/BuildUtil.java deleted file mode 100644 index ce88ba2..0000000 --- a/test/junit/com/sun/gluegen/BuildUtil.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.gluegen; - -import com.jogamp.gluegen.JavaEmitter; -import com.jogamp.gluegen.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 static java.lang.System.*; - -/** - * @author Michael Bien - */ -public final class BuildUtil { - - private static final Project project; - - public static final String gluegenRoot; - public static final String path; - 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(BuildUtil.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/jogamp/gluegen"; - testOutput = gluegenRoot + "/" + rootrel_build + "/test"; - - out.println("path: "+path); - out.println("testOutput: "+testOutput); - out.println(" - - - - - - - - - - - - "); - - cleanGeneratedFiles(); - - //setup ant build file - project = new Project(); - project.setProperty("rootrel.build", rootrel_build); - passSystemProperty(project, "gluegen-cpptasks.file"); - passSystemProperty(project, "os.arch"); - - DefaultLogger logger = new DefaultLogger(); - logger.setErrorPrintStream(out); - logger.setOutputPrintStream(out); - logger.setMessageOutputLevel(Project.MSG_WARN); - project.addBuildListener(logger); - - project.init(); - - File buildFile = new File(path, "build.xml"); - if(!buildFile.exists()) { - throw new RuntimeException("buildfile "+buildFile+" does not exist"); - } - - ProjectHelper.configureProject(project, buildFile); - } - - public static Project passSystemProperty(Project p, String name) { - String tmp = System.getProperty(name); - if(null!=tmp && tmp.length()>0) { - p.setProperty(name, tmp); - } - return p; - } - - public static void cleanGeneratedFiles() { - out.println("cleaning generated files"); - deleteDirectory(new File(testOutput+"/gensrc")); - out.println("done"); - } - - /** - * fails if ant script fails (which is a good thing). - * executeTarget throws RuntimeException on failure - */ - public static void compileJava() { - out.println("compiling java files"); - project.executeTarget("compile.java"); - out.println("done"); - } - - /** - * fails if ant script fails (which is a good thing) - * executeTarget throws RuntimeException on failure - */ - public static void compileNatives() { - out.println("compiling native files"); - project.executeTarget("compile.native"); - out.println("done"); - } - - public static void generate(String bindingName) { - generate(bindingName, JavaEmitter.class.getName()); -// generate(bindingName, DebugEmitter.class.getName()); - } - - public static void generate(String bindingName, String emitter) { - generate(bindingName, bindingName, emitter); - } - public static void generate(String bindingName, String header, String emitter) { - - out.println("generate binding to '" + bindingName+"' using '"+emitter+"'"); - - GlueGen.main( "-I"+path, - "-O"+testOutput+"/gensrc", - "-E"+emitter, - "-C"+path+"/"+bindingName+".cfg", - path+"/"+header+".h" ); - - out.println("done"); - } - - public static 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/PCPPTest.java b/test/junit/com/sun/gluegen/PCPPTest.java deleted file mode 100644 index c1f12ab..0000000 --- a/test/junit/com/sun/gluegen/PCPPTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.gluegen; - -import com.jogamp.gluegen.pcpp.PCPP; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.Collections; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * serves mainly as entry point for debugging purposes. - * @author Michael Bien - */ -public class PCPPTest { - - @Test - public void pcppMacroDefinitionTest() throws FileNotFoundException, IOException { - - PCPP pp = new PCPP(Collections.emptyList()); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - pp.setOut(output); - - String filename = "pcpptest.h"; - String filepath = BuildUtil.path + "/" + filename; - - pp.run(new BufferedReader(new FileReader(filepath)), filename); - - String expected = "# 1 \"pcpptest.h\""+ - "# define CL_SCHAR_MIN (-127-1)"+ - " cl_char __attribute__(( aligned(2))) s[ 2];"+ - "# 7 \"pcpptest.h\""; - output.flush(); - String result = output.toString(); - output.close(); - - assertEquals(killWhitespace(expected), killWhitespace(result)); - - } - - private String killWhitespace(String a) { - return a.replaceAll("\\p{javaWhitespace}+", ""); - } - - -} diff --git a/test/junit/com/sun/gluegen/StructAccessorTest.java b/test/junit/com/sun/gluegen/StructAccessorTest.java deleted file mode 100644 index 4d1bffd..0000000 --- a/test/junit/com/sun/gluegen/StructAccessorTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.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.AfterClass; -import org.junit.Test; -import static java.lang.System.*; -import static com.jogamp.gluegen.BuildUtil.*; - -/** - * - * @author Michael Bien - */ -public class StructAccessorTest { - - @Test - public void generateStruct() { - generate("struct"); - } - - @Test - public void compileStructJava() { - compileJava(); - } - - @Test - public void compileStructNatives() { - // this will only copy gluegen-rt to the right place - compileNatives(); - } - - @Test - public void validateGeneratedStructs() throws IOException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException { - - // compile testcase - String source = gluegenRoot + "/test/junit/com/jogamp/gluegen/StructValidator.java"; - compile(new File(source), testOutput + "/build/classes"); - - // invoke test - Class test = Class.forName("com.jogamp.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 collector = new DiagnosticCollector(); - StandardJavaFileManager fileManager = compiler.getStandardFileManager(collector, null, null); - - Iterable fileObj = fileManager.getJavaFileObjects(files); - - boolean success = compiler.getTask( new OutputStreamWriter(out), - fileManager, - collector, - Arrays.asList("-d", destination/*, "-verbose"*/), - null, - fileObj ).call(); - - fileManager.close(); - - List> list = collector.getDiagnostics(); - if(!list.isEmpty() || !success) { - for (Diagnostic d : list) { - out.println("Error on line "+ d.getLineNumber()); - out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH)); - } - Assert.fail("compilation failed"); - } - - out.println("done"); - - } - - @AfterClass - public static void tearDown() { -// cleanGeneratedFiles(); - } - -} diff --git a/test/junit/com/sun/gluegen/StructValidator.java b/test/junit/com/sun/gluegen/StructValidator.java deleted file mode 100644 index b6eb426..0000000 --- a/test/junit/com/sun/gluegen/StructValidator.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.gluegen; - -import java.lang.reflect.InvocationTargetException; -import org.junit.Ignore; - -import static org.junit.Assert.*; - -/** - * this file will not compile unless {@link com.jogamp.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 deleted file mode 100644 index 95617be..0000000 --- a/test/junit/com/sun/gluegen/build.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - Tests GlueGen - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/junit/com/sun/gluegen/dyntest.cfg b/test/junit/com/sun/gluegen/dyntest.cfg deleted file mode 100644 index 60b8764..0000000 --- a/test/junit/com/sun/gluegen/dyntest.cfg +++ /dev/null @@ -1,25 +0,0 @@ -Package test -Style AllStatic -JavaClass DynBindingTest -JavaOutputDir java -NativeOutputDir native - -CustomCCode #include "test.h" - -Import com.jogamp.common.nio.* - - -EmitProcAddressTable true -ProcAddressTableClassName Table -GetProcAddressTableExpr table -ProcAddressNameExpr $UpperCase(arg) - -ForceProcAddressGen __ALL__ - -CustomJavaCode DynBindingTest private final static Table table; -CustomJavaCode DynBindingTest static { -CustomJavaCode DynBindingTest table = new Table(); -CustomJavaCode DynBindingTest //table.reset(); -CustomJavaCode DynBindingTest } - -RenameJavaMethod arrayTest fancyArrayTest \ No newline at end of file diff --git a/test/junit/com/sun/gluegen/pcpptest.h b/test/junit/com/sun/gluegen/pcpptest.h deleted file mode 100644 index 58b8935..0000000 --- a/test/junit/com/sun/gluegen/pcpptest.h +++ /dev/null @@ -1,6 +0,0 @@ - -#define CL_SCHAR_MIN (-127-1) -#define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) - -cl_char CL_ALIGNED(2) s[2]; - diff --git a/test/junit/com/sun/gluegen/struct.cfg b/test/junit/com/sun/gluegen/struct.cfg deleted file mode 100644 index a1e1138..0000000 --- a/test/junit/com/sun/gluegen/struct.cfg +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 2819d5c..0000000 --- a/test/junit/com/sun/gluegen/struct.h +++ /dev/null @@ -1,21 +0,0 @@ - -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 deleted file mode 100644 index c511a53..0000000 --- a/test/junit/com/sun/gluegen/test.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "test.h" - -int arrayTest(long context, foo * array) { - return 42; -} - -int bufferTest(void * object) { - return 42; -} - -void pbTest(size_t * object) { -} - -int manyBuffersTest(void * object1, void * object2, void * object3, void * object4, void * object5) { - 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/test/junit/com/sun/gluegen/test.cfg b/test/junit/com/sun/gluegen/test.cfg deleted file mode 100644 index a2ac567..0000000 --- a/test/junit/com/sun/gluegen/test.cfg +++ /dev/null @@ -1,9 +0,0 @@ -Package test -Style AllStatic -JavaClass BindingTest -JavaOutputDir java -NativeOutputDir native - -CustomCCode #include "test.h" - -Import com.jogamp.common.nio.* \ No newline at end of file diff --git a/test/junit/com/sun/gluegen/test.h b/test/junit/com/sun/gluegen/test.h deleted file mode 100644 index cef2b7e..0000000 --- a/test/junit/com/sun/gluegen/test.h +++ /dev/null @@ -1,17 +0,0 @@ -#define GL_INVALID_INDEX 0xFFFFFFFFu -#define AL_FLANGER_DEFAULT_FEEDBACK (-0.5f) - -typedef unsigned long foo; -typedef unsigned long size_t; - -int arrayTest(long context, foo * array ); - -int bufferTest(void * object); - -void pbTest(size_t * 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 ); -- cgit v1.2.3