Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Niefer2004-10-19 10:26:06 -0400
committerAndrew Niefer2004-10-19 10:26:06 -0400
commitef6559d0139e5296338ec18d58120b2c093dc6b4 (patch)
treea43d98fd22893810c369304d27b282a58444a283 /core
parent1307a5b90562650ac6763bba0aee872e744c168b (diff)
downloadorg.eclipse.cdt-ef6559d0139e5296338ec18d58120b2c093dc6b4.tar.gz
org.eclipse.cdt-ef6559d0139e5296338ec18d58120b2c093dc6b4.tar.xz
org.eclipse.cdt-ef6559d0139e5296338ec18d58120b2c093dc6b4.zip
tests for the expression evaluator problems
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java27
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java65
2 files changed, 74 insertions, 18 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java
index 4589208bef2..3d0e7557675 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java
@@ -160,4 +160,31 @@ public class CompleteParsePluginTest extends FileBasePluginTest {
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
assertFalse( i.hasNext() );
}
+
+ public void testExpressionEvalProblems() throws Exception
+ {
+ String h = " #if 09 == 9 \n" + //$NON-NLS-1$ //bad octal
+ " #endif \n"; //$NON-NLS-1$
+
+ String code = "int i1; \n" + //$NON-NLS-1$
+ "#include \"h.h\"\n" + //$NON-NLS-1$
+ "int i2; \n"; //$NON-NLS-1$
+
+ importFile( "h.h", h ); //$NON-NLS-1$
+ IFile cpp = importFile( "c.cpp", code ); //$NON-NLS-1$
+
+ List calls = new ArrayList();
+ parse( cpp, calls );
+
+ Iterator i = calls.iterator();
+
+ assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
+ assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
+ assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
+ assertEquals( i.next(), CallbackTracker.ACCEPT_PROBLEM );
+ assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
+ assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
+ assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
+ assertFalse( i.hasNext() );
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
index 0f66bedc36a..fd4dc896264 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
@@ -1930,25 +1930,25 @@ public class Scanner2Test extends BaseScanner2Test
// when fixing 75532 several IProblems were added to ExpressionEvaluator and one to Scanner2, this is to test them
public void testBug75532IProblems() throws Exception {
Writer writer = new StringWriter();
- writer.write("#if 09 == 9\n#endif\n"); // malformed octal
- writer.write("#if 1A == 0x1A\n#endif\n"); // malformed decimal
- writer.write("#if 0x == 0x0\n#endif\n"); // malformed hex
- writer.write("#if 0xAX == 0xA\n#endif\n"); // malformed hex
- writer.write("#if 1/0 == 1\n#endif\n"); // division by zero
- writer.write("#if defined ( sadf a\n#endif\n"); // missing ')' in defined
- writer.write("#if defined ( sadf\n#endif\n"); // missing ')' in defined
- writer.write("#if defined ( 2sadf )\n#endif\n"); // illegal identifier in defined
- writer.write("#if ( 1 == 1 ? 1\n#endif\n"); // bad conditional expression
- writer.write("#if ( \n#endif\n"); // expression syntax error
- writer.write("#if @\n#endif\n"); // expression syntax error
- writer.write("#if \n#endif\n"); // expression syntax error
- writer.write("#if -\n#endif\n"); // expression syntax error
- writer.write("#if ( 1 == 1\n#endif\n"); // missing ')'
- writer.write("#if 1 = 1\n#endif\n"); // assignment not allowed
+ writer.write("#if 09 == 9\n#endif\n"); // malformed octal //$NON-NLS-1$
+ writer.write("#if 1A == 0x1A\n#endif\n"); // malformed decimal //$NON-NLS-1$
+ writer.write("#if 0x == 0x0\n#endif\n"); // malformed hex //$NON-NLS-1$
+ writer.write("#if 0xAX == 0xA\n#endif\n"); // malformed hex //$NON-NLS-1$
+ writer.write("#if 1/0 == 1\n#endif\n"); // division by zero //$NON-NLS-1$
+ writer.write("#if defined ( sadf a\n#endif\n"); // missing ')' in defined //$NON-NLS-1$
+ writer.write("#if defined ( sadf\n#endif\n"); // missing ')' in defined //$NON-NLS-1$
+ writer.write("#if defined ( 2sadf )\n#endif\n"); // illegal identifier in defined //$NON-NLS-1$
+ writer.write("#if ( 1 == 1 ? 1\n#endif\n"); // bad conditional expression //$NON-NLS-1$
+ writer.write("#if ( \n#endif\n"); // expression syntax error //$NON-NLS-1$
+ writer.write("#if @\n#endif\n"); // expression syntax error //$NON-NLS-1$
+ writer.write("#if \n#endif\n"); // expression syntax error //$NON-NLS-1$
+ writer.write("#if -\n#endif\n"); // expression syntax error //$NON-NLS-1$
+ writer.write("#if ( 1 == 1\n#endif\n"); // missing ')' //$NON-NLS-1$
+ writer.write("#if 1 = 1\n#endif\n"); // assignment not allowed //$NON-NLS-1$
- writer.write("int main(int argc, char **argv) {\n");
- writer.write("if ( 09 == 9 )\n"); // added while fixing this bug, IProblem on invalid octal number
- writer.write("return 1;\nreturn 0;\n}\n");
+ writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$
+ writer.write("if ( 09 == 9 )\n"); // added while fixing this bug, IProblem on invalid octal number //$NON-NLS-1$
+ writer.write("return 1;\nreturn 0;\n}\n"); //$NON-NLS-1$
Callback callback = new Callback( ParserMode.COMPLETE_PARSE );
initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback );
@@ -1973,4 +1973,33 @@ public class Scanner2Test extends BaseScanner2Test
assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED );
assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_OCTAL_FORMAT );
}
+
+ public void testExpressionEvalProblems() throws Exception
+ {
+ Writer writer = new StringWriter();
+ writer.write(" #if 1 == 1L \n" ); //$NON-NLS-1$
+ writer.write(" #endif \n" ); //$NON-NLS-1$
+
+ Callback callback = new Callback( ParserMode.COMPLETE_PARSE );
+ initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback );
+ validateEOF();
+
+ assertEquals( 0, callback.problems.size() );
+ }
+
+ public void testExpressionEvalProblems_2() throws Exception
+ {
+ Writer writer = new StringWriter();
+ writer.write( "#define FOO( a, b ) a##b \n"); //$NON-NLS-1$
+ writer.write( "#if FOO ( 1, 0 ) == 10 \n"); //$NON-NLS-1$
+ writer.write( "1 \n"); //$NON-NLS-1$
+ writer.write( "#endif \n"); //$NON-NLS-1$
+
+ Callback callback = new Callback( ParserMode.COMPLETE_PARSE );
+ initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback );
+ validateInteger( "1" ); //$NON-NLS-1$
+ validateEOF();
+
+ assertEquals( 0, callback.problems.size() );
+ }
}

Back to the top