diff options
Diffstat (limited to 'src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java')
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java new file mode 100644 index 0000000..12a5160 --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java @@ -0,0 +1,65 @@ +package com.jogamp.gluegen.jcpp; + +import java.io.IOException; +import org.junit.Test; +import static com.jogamp.gluegen.jcpp.Token.*; +import static org.junit.Assert.*; + +public class ErrorTest { + + private boolean testError(Preprocessor p) + throws LexerException, + IOException { + for (;;) { + Token tok = p.token(); + if (tok.getType() == EOF) + break; + if (tok.getType() == INVALID) + return true; + } + return false; + } + + private void testError(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 (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("''"); + } + +} |