Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Parser correctness JUnit tests


This patch adds two JUnit tests for problems generated while parsing <stdio.h>.
PR 69791: [Parser] Indexer complains about va_list
PR 70928: [Parser] Indexer complains about __cdecl
Also an exception is thrown in CompleteParseBaseTest if parser generates problem markers (in addition to returning false as a parse result).

Thanks,
Vmir

Index: failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java,v
retrieving revision 1.8
diff -u -r1.8 FailedCompleteParseASTTest.java
--- failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java	28 May 2004 14:54:46 -0000	1.8
+++ failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java	29 Jul 2004 18:19:25 -0000
@@ -42,6 +42,7 @@
 		//parse no longer passes
 		try{
 			parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));"); //$NON-NLS-1$
+			fail();
 		} catch ( ParserException e ){
 			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
 		}
@@ -64,6 +65,7 @@
 		//parse no longer passes
 		try{
 			parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));"); //$NON-NLS-1$
+			fail();
 		} catch ( ParserException e ){
 			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
 		}
@@ -102,6 +104,7 @@
 		//parse no longer passes
 		try{
 			parse ( "class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);" ); //$NON-NLS-1$
+			fail();
 		} catch ( ParserException e ){
 			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
 		}
@@ -122,6 +125,7 @@
 		//parse no longer passes
 		try{
 			parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);"); //$NON-NLS-1$
+			fail();
 		} catch ( ParserException e ){
 			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
 		}
@@ -134,5 +138,32 @@
 //		IASTVariable x  = (IASTVariable) i.next();
 //		assertFalse( i.hasNext() );
 //		assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2)));
-	}	
+	}
+	
+	public void testPredefinedSymbol_bug69791() throws Exception {
+		// GNU builtin type __builtin_va_list
+		try {
+			parse("typedef __builtin_va_list __gnuc_va_list; \n");//$NON-NLS-1$
+			fail();
+		} catch ( ParserException e ){
+			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
+		}
+//		Iterator i = parse("typedef unsigned char byte; \n").getDeclarations();;//$NON-NLS-1$
+//		IASTTypedefDeclaration td = (IASTTypedefDeclaration) i.next();
+//		assertFalse(i.hasNext());
+	}
+
+	public void testPredefinedSymbol_bug70928() throws Exception {
+		// GNU builtin storage class type __cdecl preceded by a custom return type 
+		try {
+			parse("typedef int size_t; \n size_t __cdecl foo(); \n");//$NON-NLS-1$
+			fail();
+		} catch ( ParserException e ){
+			assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
+		}
+//		Iterator i = parse("typedef int size_t; \n int __cdecl foo(); \n").getDeclarations();//$NON-NLS-1$
+//		IASTTypedefDeclaration td = (IASTTypedefDeclaration) i.next();
+//		IASTFunction fd = (IASTFunction) i.next();
+//		assertFalse(i.hasNext());
+	}
 }
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java,v
retrieving revision 1.37
diff -u -r1.37 CompleteParseBaseTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java	21 Jul 2004 17:57:44 -0000	1.37
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java	29 Jul 2004 18:19:26 -0000
@@ -794,7 +794,8 @@
     			ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null 	
     		);
     	boolean parseResult = parser.parse();
-		if( ! parseResult && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
+    	// throw exception if there are generated IProblems
+		if( (! parseResult || callback.getProblems().hasNext() ) && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
 		if( parseResult  )
 			assertTrue( ((CompleteParser)parser).validateCaches());
         return callback.getCompilationUnit();

Back to the top