diff options
4 files changed, 205 insertions, 0 deletions
diff --git a/src/test/java/com/jogamp/gluegen/jcpp/BuildMetadataTest.java b/src/test/java/com/jogamp/gluegen/jcpp/BuildMetadataTest.java new file mode 100644 index 0000000..42dc071 --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/BuildMetadataTest.java @@ -0,0 +1,33 @@ +package org.anarres.cpp; + +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import java.net.URL; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author shevek + */ +public class BuildMetadataTest { + + private static final Logger LOG = LoggerFactory.getLogger(BuildMetadataTest.class); + + @Test + public void testProperties() throws Exception { + URL url = Resources.getResource("META-INF/jcpp.properties"); + String text = Resources.asCharSource(url, Charsets.ISO_8859_1).read(); + LOG.info("Metadata is " + text); + } + + @Test + public void testMetadata() throws Exception { + BuildMetadata metadata = BuildMetadata.getInstance(); + LOG.info("Version is " + metadata.getVersion()); + LOG.info("BuildDate is " + metadata.getBuildDate()); + LOG.info("ChangeId is " + metadata.getChangeId()); + } + +} diff --git a/src/test/java/com/jogamp/gluegen/jcpp/PragmaTest.java b/src/test/java/com/jogamp/gluegen/jcpp/PragmaTest.java new file mode 100644 index 0000000..342bd52 --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/PragmaTest.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.anarres.cpp; + +import com.google.common.base.Charsets; +import com.google.common.io.CharSource; +import com.google.common.io.CharStreams; +import com.google.common.io.Files; +import java.io.File; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; + +/** + * + * @author shevek + */ +public class PragmaTest { + + private static final Logger LOG = LoggerFactory.getLogger(PragmaTest.class); + + @Test + public void testPragma() throws Exception { + File file = new File("build/resources/test/pragma.c"); + assertTrue(file.exists()); + + CharSource source = Files.asCharSource(file, Charsets.UTF_8); + CppReader r = new CppReader(source.openBufferedStream()); + r.getPreprocessor().setListener(new DefaultPreprocessorListener()); + String output = CharStreams.toString(r); + r.close(); + LOG.info("Output: " + output); + // assertTrue(output.contains("absolute-result")); + } +} diff --git a/src/test/java/com/jogamp/gluegen/jcpp/RegressionTest.java b/src/test/java/com/jogamp/gluegen/jcpp/RegressionTest.java new file mode 100644 index 0000000..3ce3568 --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/RegressionTest.java @@ -0,0 +1,70 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.anarres.cpp; + +import com.google.common.base.Charsets; +import com.google.common.io.CharStreams; +import com.google.common.io.Files; +import com.google.common.io.PatternFilenameFilter; +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.assertEquals; + +/** + * + * @author shevek + */ +@RunWith(Parameterized.class) +public class RegressionTest { + + private static final Logger LOG = LoggerFactory.getLogger(RegressionTest.class); + + @Parameterized.Parameters(name = "{0}") + public static List<Object[]> data() throws Exception { + List<Object[]> out = new ArrayList<Object[]>(); + + File dir = new File("build/resources/test/regression"); + for (File inFile : dir.listFiles(new PatternFilenameFilter(".*\\.in"))) { + String name = Files.getNameWithoutExtension(inFile.getName()); + File outFile = new File(dir, name + ".out"); + out.add(new Object[]{name, inFile, outFile}); + } + + return out; + } + + private final String name; + private final File inFile; + private final File outFile; + + public RegressionTest(String name, File inFile, File outFile) { + this.name = name; + this.inFile = inFile; + this.outFile = outFile; + } + + @Test + public void testRegression() throws Exception { + String inText = Files.toString(inFile, Charsets.UTF_8); + LOG.info("Read " + name + ":\n" + inText); + CppReader cppReader = new CppReader(new StringReader(inText)); + String cppText = CharStreams.toString(cppReader); + LOG.info("Generated " + name + ":\n" + cppText); + if (outFile.exists()) { + String outText = Files.toString(outFile, Charsets.UTF_8); + LOG.info("Expected " + name + ":\n" + outText); + assertEquals(outText, inText); + } + + } +} diff --git a/src/test/java/com/jogamp/gluegen/jcpp/VaArgsPastingTest.java b/src/test/java/com/jogamp/gluegen/jcpp/VaArgsPastingTest.java new file mode 100644 index 0000000..f1bcbcd --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/VaArgsPastingTest.java @@ -0,0 +1,63 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.anarres.cpp; + +import com.google.common.io.CharStreams; +import java.io.IOException; +import java.io.Reader; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; + +/** + * + * @author shevek + */ +public class VaArgsPastingTest { + + private static final Logger LOG = LoggerFactory.getLogger(VaArgsPastingTest.class); + + @Test + public void testWhitespacePasting() throws IOException { + String input + = "#define REGULAR_ARGS(x, y) foo(x, y)\n" + + "#define REGULAR_ELLIPSIS(x, y...) foo(x, y)\n" + + "#define REGULAR_VAARGS(x, ...) foo(x, __VA_ARGS__)\n" + + "#define PASTE_ARGS(x, y) foo(x, ## y)\n" + + "#define PASTE_ELLIPSIS(x, y...) foo(x, ## y)\n" + + "#define PASTE_VAARGS(x, ...) foo(x, ## __VA_ARGS__)\n" + + "" + + "REGULAR_ARGS(a, b) // REGULAR_ARGS 2\n" + + "REGULAR_ELLIPSIS(a, b) // REGULAR_ELLIPSIS 2\n" + + "REGULAR_ELLIPSIS(a) // REGULAR_ELLIPSIS 1\n" + + "REGULAR_VAARGS(a, b) // REGULAR_VAARGS 2\n" + + "REGULAR_VAARGS(a) // REGULAR_VAARGS 1\n" + + "" + + "PASTE_ARGS(a, b) // PASTE_ARGS 2\n" + + "PASTE_ELLIPSIS(a, b) // PASTE_ELLIPSIS 2\n" + + "PASTE_ELLIPSIS(a) // PASTE_ELLIPSIS 1\n" + + "PASTE_VAARGS(a, b) // PASTE_VAARGS 2\n" + + "PASTE_VAARGS(a) // PASTE_VAARGS 1\n"; + LOG.info("Input is:\n" + input); + Preprocessor pp = new Preprocessor(); + pp.addFeature(Feature.KEEPCOMMENTS); + pp.addInput(new StringLexerSource(input, true)); + Reader r = new CppReader(pp); + String output = CharStreams.toString(r).trim(); + LOG.info("Output is:\n" + output); + assertEquals("foo(a, b) // REGULAR_ARGS 2\n" + + "foo(a, b) // REGULAR_ELLIPSIS 2\n" + + "foo(a, ) // REGULAR_ELLIPSIS 1\n" + + "foo(a, b) // REGULAR_VAARGS 2\n" + + "foo(a, ) // REGULAR_VAARGS 1\n" + + "foo(a,b) // PASTE_ARGS 2\n" // cpp outputs a warning and a space after the comma, similar below. + + "foo(a,b) // PASTE_ELLIPSIS 2\n" + + "foo(a) // PASTE_ELLIPSIS 1\n" + + "foo(a,b) // PASTE_VAARGS 2\n" + + "foo(a) // PASTE_VAARGS 1", output); + } +} |