From 46ab6162f7979c56dc285c5d4e581e607d4bb0ba Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 22 Dec 2008 01:39:25 +0000 Subject: [PATCH] Test case for bug 259460. --- .../core/parser/tests/ast2/AST2CPPTests.java | 2 +- .../parser/tests/ast2/AST2SpecBaseTest.java | 75 ++++++++----------- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 24120434c68..473a5f1a868 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -6284,7 +6284,7 @@ public class AST2CPPTests extends AST2BaseTest { // } // struct B {}; // }; - public void _testClassMemberScope_259460() throws Exception { + public void _testScopeOfClassMember_259460() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java index 290f74e795a..b46c803737d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java @@ -58,26 +58,25 @@ public class AST2SpecBaseTest extends AST2BaseTest { * @param expectedProblemBindings the number of problem bindings you expect to encounter * @throws ParserException */ - protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException { - parse( code, ParserLanguage.C, false, true, checkBindings, expectedProblemBindings, null); - parse( code, ParserLanguage.CPP, false, true, checkBindings, expectedProblemBindings, null ); + protected void parseCandCPP(String code, boolean checkBindings, int expectedProblemBindings) throws ParserException { + parse(code, ParserLanguage.C, false, true, checkBindings, expectedProblemBindings, null); + parse(code, ParserLanguage.CPP, false, true, checkBindings, expectedProblemBindings, null); } - protected IASTTranslationUnit parseWithErrors( String code, ParserLanguage lang) throws ParserException { - return parse(code, lang, false, false, false, 0, null ); + protected IASTTranslationUnit parseWithErrors(String code, ParserLanguage lang) throws ParserException { + return parse(code, lang, false, false, false, 0, null); } - protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException { - return parse(code, lang, false, true, checkBindings, expectedProblemBindings, null ); + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings) throws ParserException { + return parse(code, lang, false, true, checkBindings, expectedProblemBindings, null); } protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException { - return parse(code, lang, false, true, true, problems.length, problems ); + return parse(code, lang, false, true, true, problems.length, problems); } - - private IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, - boolean checkBindings, int expectedProblemBindings, String[] problems ) throws ParserException { + private IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, + boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException { // TODO beef this up with tests... i.e. run once with \n, and then run again with \r\n replacing \n ... etc // TODO another example might be to replace all characters with corresponding trigraph/digraph tests... @@ -85,7 +84,7 @@ public class AST2SpecBaseTest extends AST2BaseTest { return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings, problems); } -// private IASTTranslationUnit parse( IFile filename, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { +// private IASTTranslationUnit parse(IFile filename, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { // CodeReader codeReader=null; // try { // codeReader = new CodeReader(filename.getName(), filename.getContents()); @@ -98,25 +97,21 @@ public class AST2SpecBaseTest extends AST2BaseTest { // return parse(codeReader, lang, useGNUExtensions, expectNoProblems); // } - private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, boolean useGNUExtensions, - boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException { + private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, + boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, + int expectedProblemBindings, String[] problems) throws ParserException { ScannerInfo scannerInfo = new ScannerInfo(); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; - if( lang == ParserLanguage.CPP ) - { + if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (useGNUExtensions) config = new GPPParserExtensionConfiguration(); else config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, - config ); - } - else - { + parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); + } else { ICParserExtensionConfiguration config = null; if (useGNUExtensions) @@ -124,8 +119,8 @@ public class AST2SpecBaseTest extends AST2BaseTest { else config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, config ); + parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, + NULL_LOG, config); } if (expectedProblemBindings > 0) @@ -136,9 +131,10 @@ public class AST2SpecBaseTest extends AST2BaseTest { // resolve all bindings if (checkBindings) { NameResolver res = new NameResolver(); - tu.accept( res ); - if (res.problemBindings.size() != expectedProblemBindings ) - throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.problemBindings.size() ); + tu.accept(res); + if (res.problemBindings.size() != expectedProblemBindings) + throw new ParserException("Expected " + expectedProblemBindings + + " problems, encountered " + res.problemBindings.size()); if (problems != null) { for (int i = 0; i < problems.length; i++) { assertEquals(problems[i], res.problemBindings.get(i)); @@ -146,33 +142,28 @@ public class AST2SpecBaseTest extends AST2BaseTest { } } - if( parser2.encounteredError() && expectNoProblems ) - throw new ParserException( "FAILURE"); + if (parser2.encounteredError() && expectNoProblems) + throw new ParserException("FAILURE"); - if( lang == ParserLanguage.C && expectNoProblems ) - { + if (lang == ParserLanguage.C && expectNoProblems) { if (CVisitor.getProblems(tu).length != 0) { - throw new ParserException (" CVisitor has AST Problems " ); + throw new ParserException("CVisitor has AST Problems"); } if (tu.getPreprocessorProblems().length != 0) { - throw new ParserException (" C TranslationUnit has Preprocessor Problems " ); + throw new ParserException("C TranslationUnit has Preprocessor Problems"); } - } - else if ( lang == ParserLanguage.CPP && expectNoProblems ) - { + } else if (lang == ParserLanguage.CPP && expectNoProblems) { if (CPPVisitor.getProblems(tu).length != 0) { - throw new ParserException (" CPPVisitor has AST Problems " ); + throw new ParserException("CPPVisitor has AST Problems"); } if (tu.getPreprocessorProblems().length != 0) { - throw new ParserException (" CPP TranslationUnit has Preprocessor Problems " ); + throw new ParserException("CPP TranslationUnit has Preprocessor Problems"); } } return tu; } - - static protected class NameResolver extends ASTVisitor { { shouldVisitNames = true; @@ -182,7 +173,6 @@ public class AST2SpecBaseTest extends AST2BaseTest { public List problemBindings = new ArrayList(); public int numNullBindings = 0; - @Override public int visit(IASTName name) { nameList.add(name); @@ -195,7 +185,7 @@ public class AST2SpecBaseTest extends AST2BaseTest { } public IASTName getName(int idx) { - if(idx < 0 || idx >= nameList.size()) + if (idx < 0 || idx >= nameList.size()) return null; return nameList.get(idx); } @@ -204,5 +194,4 @@ public class AST2SpecBaseTest extends AST2BaseTest { return nameList.size(); } } - }