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 \n", Feature.LINEMARKERS); } @Test public void testVarargs() throws Exception { // The newlines are irrelevant, We want exactly one "foo" testCppReader("#include \n"); } @Test public void testPragmaOnce() throws Exception { // The newlines are irrelevant, We want exactly one "foo" final String out = testCppReader("#include \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 \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); } }