blob: ad6a1b467f6e6d6e56329acf774442b03e02f516 (
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
|
package com.jogamp.gluegen.jcpp;
import java.io.IOException;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import com.jogamp.junit.util.SingletonJunitCase;
import static com.jogamp.gluegen.jcpp.Token.*;
import static org.junit.Assert.*;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ErrorTest extends SingletonJunitCase {
private boolean testError(final Preprocessor p)
throws LexerException,
IOException {
for (;;) {
final Token tok = p.token();
if (tok.getType() == EOF)
break;
if (tok.getType() == INVALID)
return true;
}
return false;
}
private void testError(final String input) throws Exception {
StringLexerSource sl;
DefaultPreprocessorListener pl;
Preprocessor p;
/* Without a PreprocessorListener, throws an exception. */
sl = new StringLexerSource(input, true);
p = new Preprocessor();
p.addFeature(Feature.CSYNTAX);
p.addInput(sl);
try {
assertTrue(testError(p));
fail("Lexing unexpectedly succeeded without listener.");
} catch (final LexerException e) {
/* required */
}
/* With a PreprocessorListener, records the error. */
sl = new StringLexerSource(input, true);
p = new Preprocessor();
p.addFeature(Feature.CSYNTAX);
p.addInput(sl);
pl = new DefaultPreprocessorListener();
p.setListener(pl);
assertNotNull("CPP has listener", p.getListener());
assertTrue(testError(p));
assertTrue("Listener has errors", pl.getErrors() > 0);
/* Without CSYNTAX, works happily. */
sl = new StringLexerSource(input, true);
p = new Preprocessor();
p.addInput(sl);
assertTrue(testError(p));
}
@Test
public void testErrors() throws Exception {
testError("\"");
testError("'");
// testError("''");
}
}
|