blob: e4ef1c580291b8f7a28589a7321ea9c4b7a0eb48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
}
}
|