summaryrefslogtreecommitdiffstats
path: root/test/junit/com
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-12 20:35:34 +0100
committerMichael Bien <[email protected]>2010-02-12 20:35:34 +0100
commiteca540f632a80aa002d1c4304d73eaf4513ab27e (patch)
tree99c7f56a7808eadd3e3b21f827aaaaf0f9d2b483 /test/junit/com
parent3f1bda99f1e4aec19c1c71de5324814bfc1c2eaa (diff)
junit test code cleanup and some build preperations for hudson.
Diffstat (limited to 'test/junit/com')
-rw-r--r--test/junit/com/sun/gluegen/BasicTest.java9
-rw-r--r--test/junit/com/sun/gluegen/BuildUtil.java (renamed from test/junit/com/sun/gluegen/AbstractTest.java)67
-rw-r--r--test/junit/com/sun/gluegen/StructAccessorTest.java33
-rw-r--r--test/junit/com/sun/gluegen/build.xml15
4 files changed, 71 insertions, 53 deletions
diff --git a/test/junit/com/sun/gluegen/BasicTest.java b/test/junit/com/sun/gluegen/BasicTest.java
index 89a4c21..dc6efb9 100644
--- a/test/junit/com/sun/gluegen/BasicTest.java
+++ b/test/junit/com/sun/gluegen/BasicTest.java
@@ -6,14 +6,16 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.junit.AfterClass;
import org.junit.Test;
import static java.lang.System.*;
+import static com.sun.gluegen.BuildUtil.*;
/**
*
* @author Michael Bien
*/
-public class BasicTest extends AbstractTest {
+public class BasicTest {
@Test
public void generateBindingTest() {
@@ -98,4 +100,9 @@ public class BasicTest extends AbstractTest {
}
+ @AfterClass
+ public static void tearDown() {
+// cleanGeneratedFiles();
+ }
+
}
diff --git a/test/junit/com/sun/gluegen/AbstractTest.java b/test/junit/com/sun/gluegen/BuildUtil.java
index 9262347..de4f8e2 100644
--- a/test/junit/com/sun/gluegen/AbstractTest.java
+++ b/test/junit/com/sun/gluegen/BuildUtil.java
@@ -5,27 +5,21 @@ 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 {
+public final class BuildUtil {
- static final Project project = new Project();
+ private static final Project project;
- protected static String gluegenRoot;
- protected static String path;
- protected static String output;
-
+ public static final String gluegenRoot;
+ public static final String path;
+ public static final String output;
- @BeforeClass
- public static void setUp() throws Exception {
+ static {
out.println(" - - - System info - - - ");
out.println("OS: " + System.getProperty("os.name"));
@@ -33,7 +27,7 @@ public abstract class AbstractTest {
// setup paths
try {
- File executionRoot = new File(AbstractTest.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+ 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);
@@ -48,13 +42,14 @@ public abstract class AbstractTest {
out.println("output: "+output);
out.println(" - - - - - - - - - - - - ");
- deleteDirectory(new File(output+"/gensrc"));
+ cleanGeneratedFiles();
//setup ant build file
+ project = new Project();
project.setBaseDir(new File(gluegenRoot));
DefaultLogger logger = new DefaultLogger();
- logger.setErrorPrintStream(err);
+ logger.setErrorPrintStream(out);
logger.setOutputPrintStream(out);
logger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener(logger);
@@ -62,45 +57,53 @@ public abstract class AbstractTest {
project.init();
File buildFile = new File(path, "build.xml");
+ if(!buildFile.exists()) {
+ throw new RuntimeException("buildfile "+buildFile+" does not exist");
+ }
+
ProjectHelper.configureProject(project, buildFile);
}
- @AfterClass
- public static void tearDown() {
-// deleteDirectory(new File(output));
+ public static void cleanGeneratedFiles() {
+ out.println("cleaning generated files");
+ deleteDirectory(new File(output+"/gensrc"));
+ out.println("done");
}
/**
* fails if ant script fails (which is a good thing).
* executeTarget throws RuntimeException on failure
*/
- public final void compileJava() {
+ 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 final void compileNatives() {
+ public static void compileNatives() {
+ out.println("compiling native files");
project.executeTarget("compile.native");
+ out.println("done");
}
- 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"
- }
- );
+ public static void generate(String bindingName) {
+
+ out.println("generate binding: " + bindingName);
+
+ GlueGen.main( "-I"+path,
+ "-O"+output+"/gensrc",
+ // "-Ecom.sun.gluegen.DebugEmitter",
+ "-C"+path+"/"+bindingName+".cfg",
+ path+"/"+bindingName+".h" );
+
out.println("done");
}
- static final void deleteDirectory(File path) {
+ public static void deleteDirectory(File path) {
if(path.exists()) {
File[] files = path.listFiles();
diff --git a/test/junit/com/sun/gluegen/StructAccessorTest.java b/test/junit/com/sun/gluegen/StructAccessorTest.java
index f89eb43..0cd2953 100644
--- a/test/junit/com/sun/gluegen/StructAccessorTest.java
+++ b/test/junit/com/sun/gluegen/StructAccessorTest.java
@@ -14,14 +14,16 @@ 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.sun.gluegen.BuildUtil.*;
/**
*
* @author Michael Bien
*/
-public class StructAccessorTest extends AbstractTest {
+public class StructAccessorTest {
@Test
public void generateStruct() {
@@ -30,13 +32,13 @@ public class StructAccessorTest extends AbstractTest {
@Test
public void compileStructJava() {
- super.compileJava();
+ compileJava();
}
@Test
public void compileStructNatives() {
// this will only copy gluegen-rt to the right place
- super.compileNatives();
+ compileNatives();
}
@Test
@@ -58,7 +60,7 @@ public class StructAccessorTest extends AbstractTest {
// 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));
+ out.println("compiling files:\n " + Arrays.asList(files));
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
@@ -66,15 +68,17 @@ public class StructAccessorTest extends AbstractTest {
Iterable<? extends JavaFileObject> fileObj = fileManager.getJavaFileObjects(files);
- compiler.getTask( new OutputStreamWriter(out),
- fileManager,
- collector,
- Arrays.asList("-d", destination/*, "-verbose"*/),
- null,
- fileObj ).call();
+ boolean success = compiler.getTask( new OutputStreamWriter(out),
+ fileManager,
+ collector,
+ Arrays.asList("-d", destination/*, "-verbose"*/),
+ null,
+ fileObj ).call();
+
+ fileManager.close();
List<Diagnostic<? extends JavaFileObject>> list = collector.getDiagnostics();
- if(!list.isEmpty()) {
+ if(!list.isEmpty() || !success) {
for (Diagnostic<? extends JavaFileObject> d : list) {
out.println("Error on line "+ d.getLineNumber());
out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH));
@@ -82,12 +86,13 @@ public class StructAccessorTest extends AbstractTest {
Assert.fail("compilation failed");
}
- fileManager.close();
-
out.println("done");
}
-
+ @AfterClass
+ public static void tearDown() {
+// cleanGeneratedFiles();
+ }
}
diff --git a/test/junit/com/sun/gluegen/build.xml b/test/junit/com/sun/gluegen/build.xml
index 58ab781..08405bf 100644
--- a/test/junit/com/sun/gluegen/build.xml
+++ b/test/junit/com/sun/gluegen/build.xml
@@ -4,25 +4,28 @@
<description>Tests GlueGen</description>
- <property name="gluegen.root" value="${basedir}" />
- <property name="build.dir" value="${gluegen.root}/build/test/build" />
- <property name="src.dir" value="${gluegen.root}/build/test/gensrc/java" />
+ <property name="gluegen.root" value="${basedir}" />
+ <property name="src.dir" value="${gluegen.root}/build/test/gensrc/java" />
+ <property name="build.dir" value="${gluegen.root}/build/test/build" />
<!-- Pull in GlueGen cpptasks build file -->
<import file="${gluegen.root}/make/gluegen-cpptasks.xml" />
- <target name="compile.java" depends="c.configure.linux">
+ <target name="compile.java">
<echo message=" - - - compiling java files - - - "/>
+
<property name="build.dir.java" value="${build.dir}/classes"/>
+
<echo message="src: ${src.dir} "/>
<echo message="build: ${build.dir.java} "/>
+ <echo message="jdkhome: ${jdk.home} "/>
<mkdir dir="${build.dir.java}"/>
- <javac destdir="${build.dir.java}" source="1.5" debug="true" verbose="true" debuglevel="lines,vars,source">
+ <javac destdir="${build.dir.java}" source="1.5" failonerror="true" debug="true" verbose="true" debuglevel="lines,vars,source">
<src path="${src.dir}"/>
- <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}"/>
+ <classpath path="${gluegen.root}/build/classes:${src.dir}:${gluegen.root}/build/antlr-3.2.jar:${gluegen.root}/make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/>
</javac>
<echo message=" - - - java files compiled - - - "/>