aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java')
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java
new file mode 100644
index 0000000..e4ef1c5
--- /dev/null
+++ b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java
@@ -0,0 +1,73 @@
+package com.jogamp.gluegen.jcpp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Collections;
+
+import javax.annotation.Nonnull;
+
+import org.junit.Test;
+
+import com.jogamp.gluegen.test.junit.generation.BuildEnvironment;
+
+import static org.junit.Assert.assertEquals;
+
+public class CppReaderTest {
+
+ public static String testCppReader(@Nonnull final String in, final Feature... f) throws Exception {
+ final String inclpath = BuildEnvironment.gluegenRoot + "/jcpp/src/test/resources" ;
+
+ System.out.println("Testing " + in);
+ final StringReader r = new StringReader(in);
+ final CppReader p = new CppReader(r);
+ p.getPreprocessor().setSystemIncludePath(
+ Collections.singletonList(inclpath)
+ );
+ p.getPreprocessor().addFeatures(f);
+ final BufferedReader b = new BufferedReader(p);
+
+ final StringBuilder out = new StringBuilder();
+ String line;
+ while ((line = b.readLine()) != null) {
+ System.out.println(" >> " + line);
+ out.append(line).append("\n");
+ }
+
+ return out.toString();
+ }
+
+ @Test
+ public void testCppReader()
+ throws Exception {
+ testCppReader("#include <test0.h>\n", Feature.LINEMARKERS);
+ }
+
+ @Test
+ public void testVarargs()
+ throws Exception {
+ // The newlines are irrelevant, We want exactly one "foo"
+ testCppReader("#include <varargs.c>\n");
+ }
+
+ @Test
+ public void testPragmaOnce()
+ throws Exception {
+ // The newlines are irrelevant, We want exactly one "foo"
+ final String out = testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE);
+ assertEquals("foo", out.trim());
+ }
+
+ @Test
+ public void testPragmaOnceWithMarkers()
+ throws Exception {
+ // The newlines are irrelevant, We want exactly one "foo"
+ testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE, Feature.LINEMARKERS);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = CppReaderTest.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}