From a2c5e8987cf0b01d755dd731ba8bbe5df58c3e79 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 7 Sep 2006 14:50:58 +0000 Subject: [PATCH] Additional test cases for Call Hierarchy --- .../eclipse/cdt/ui/tests/BaseTestCase.java | 82 ++++ .../callhierarchy/BasicCallHierarchyTest.java | 62 +-- .../BasicCppCallHierarchyTest.java | 363 +++++++++++++++++- .../callhierarchy/CallHierarchyBaseTest.java | 45 +-- .../callhierarchy/CallHierarchyTestSuite.java | 4 +- .../text/selection/ResolveBindingTests.java | 136 +++++++ .../text/selection/SelectionTestSuite.java | 1 + .../internal/ui/missingapi/CIndexQueries.java | 4 - 8 files changed, 600 insertions(+), 97 deletions(-) create mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseTestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseTestCase.java index 489de45f6ed..14098a9e42c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseTestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseTestCase.java @@ -17,18 +17,34 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import junit.framework.TestFailure; +import junit.framework.TestResult; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.testplugin.CTestPlugin; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; + public class BaseTestCase extends TestCase { + private boolean fExpectFailure= false; + private int fBugnumber= 0; + public BaseTestCase() { super(); } @@ -37,6 +53,39 @@ public class BaseTestCase extends TestCase { super(name); } + public void run( TestResult result ) { + if (!fExpectFailure) { + super.run(result); + return; + } + + result.startTest( this ); + + TestResult r = new TestResult(); + super.run( r ); + if (r.failureCount() == 1) { + TestFailure failure= (TestFailure) r.failures().nextElement(); + String msg= failure.exceptionMessage(); + if (msg != null && msg.startsWith("Method \"" + getName() + "\"")) { + result.addFailure(this, new AssertionFailedError(msg)); + } + } + else if( r.errorCount() == 0 && r.failureCount() == 0 ) + { + String err = "Unexpected success"; //$NON-NLS-1$ + if( fBugnumber != -1 ) + err += ", bug #" + fBugnumber; //$NON-NLS-1$ + result.addFailure( this, new AssertionFailedError( err ) ); + } + + result.endTest( this ); + } + + public void setExpectFailure(int bugnumber) { + fExpectFailure= true; + fBugnumber= bugnumber; + } + /** * Reads a section in comments form the source of the given class. The section * is started with '// {tag}' and ends with the first line not started by '//' @@ -119,4 +168,37 @@ public class BaseTestCase extends TestCase { protected IFile createFile(IContainer container, String fileName, String contents) throws Exception { return createFile(container, new Path(fileName), contents); } + + protected IASTTranslationUnit createPDOMBasedAST(ICProject project, IFile file) throws CModelException, CoreException { + ICElement elem= project.findElement(file.getFullPath()); + if (elem instanceof ITranslationUnit) { + ITranslationUnit tu= (ITranslationUnit) elem; + if (tu != null) { + return tu.getLanguage().getASTTranslationUnit(tu, ILanguage.AST_SKIP_INDEXED_HEADERS |ILanguage.AST_USE_INDEX); + } + } + fail("Could not create ast for " + file.getFullPath()); + return null; + } + + protected void waitForIndexer(PDOM pdom, IFile file, int maxmillis) throws Exception { + long endTime= System.currentTimeMillis() + maxmillis; + do { + pdom.acquireReadLock(); + try { + PDOMFile pfile= pdom.getFile(file.getLocation()); + // mstodo check timestamp + if (pfile != null) { + return; + } + } + finally { + pdom.releaseReadLock(); + } + + Thread.sleep(50); + } while (System.currentTimeMillis() < endTime); + throw new Exception("Indexer did not complete in time!"); + } + } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java index 6cf4d1eef2b..3a44449139c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java @@ -23,20 +23,18 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; -import org.eclipse.cdt.core.tests.FailingTest; +import org.eclipse.cdt.ui.tests.BaseTestCase; import org.eclipse.cdt.internal.ui.editor.CEditor; public class BasicCallHierarchyTest extends CallHierarchyBaseTest { - private static final int EVENT_QUEUE_MILLIS = 100; - public BasicCallHierarchyTest(String name) { super(name); } - public static Test getSuite() { + public static Test suite() { TestSuite suite= new TestSuite("BasicCallHierarchyTest"); suite.addTestSuite(BasicCallHierarchyTest.class); suite.addTest(getFailingTests()); @@ -54,8 +52,10 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { return suite; } - private static FailingTest getFailingTest(String name) { - return new FailingTest(new BasicCallHierarchyTest(name)); + private static Test getFailingTest(String name) { + BaseTestCase failingTest= new BasicCallHierarchyTest(name); + failingTest.setExpectFailure(0); + return failingTest; } public void testFunctionsC() throws Exception { @@ -77,33 +77,29 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestFunctions(String filename) throws IOException, Exception, PartInitException { String content = readTaggedComment("testFunctions"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("proto"), 5); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "proto()"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("func"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "func()"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("proto(); //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "proto()"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("func(); //ref"), 7); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "func()"); checkTreeNode(tree, 0, 0, "main()"); @@ -127,33 +123,29 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestVariables(String filename) throws Exception { String content = readTaggedComment("testVariables"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("extern_var"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "extern_var"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("global_var"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "global_var"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("extern_var; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "extern_var"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("global_var; //ref"), 7); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "global_var"); checkTreeNode(tree, 0, 0, "main()"); @@ -189,32 +181,28 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestEnumerator(String filename, String contentTag) throws Exception { String content = readTaggedComment(contentTag); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("enumerator"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "enumerator"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("main"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "main()"); editor.selectAndReveal(content.indexOf("enumerator; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "enumerator"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("main"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "main()"); } @@ -258,56 +246,48 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestStructMembers(String filename) throws Exception { String content = readTaggedComment("testStructMembers"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("mem1"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "s1::mem1"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "(anon)::mem3"); editor.selectAndReveal(content.indexOf("mem4"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "s4::mem4"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "s4::(anon)::mem5"); editor.selectAndReveal(content.indexOf("mem1; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "s1::mem1"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "s4::mem4"); checkTreeNode(tree, 0, 0, "main()"); @@ -324,33 +304,29 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestAnonymousStructMembers(String filename) throws Exception { String content = readTaggedComment("testStructMembers"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "(anon)::mem3"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "s4::(anon)::mem5"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem3; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "(anon)::mem3"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "s4::(anon)::mem5"); checkTreeNode(tree, 0, 0, "main()"); @@ -402,56 +378,48 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestUnionMembers(String filename) throws Exception { String content = readTaggedComment("testUnionMembers"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("mem1"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "u1::mem1"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "(anon)::mem3"); editor.selectAndReveal(content.indexOf("mem4"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "u4::mem4"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "u4::(anon)::mem5"); editor.selectAndReveal(content.indexOf("mem1; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "u1::mem1"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "u4::mem4"); checkTreeNode(tree, 0, 0, "main()"); @@ -468,33 +436,29 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { private void doTestAnonymousUnionMembers(String filename) throws Exception { String content = readTaggedComment("testUnionMembers"); IFile file= createFile(getProject(), filename, content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "(anon)::mem3"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "u4::(anon)::mem5"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem3; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "(anon)::mem3"); checkTreeNode(tree, 0, 0, "main()"); editor.selectAndReveal(content.indexOf("mem5; //ref"), 0); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); tree = getCHTree(page); checkTreeNode(tree, 0, "u4::(anon)::mem5"); checkTreeNode(tree, 0, 0, "main()"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java index 504bd86f26e..e6720dbf17a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java @@ -20,20 +20,18 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; -import org.eclipse.cdt.core.tests.FailingTest; +import org.eclipse.cdt.ui.tests.BaseTestCase; import org.eclipse.cdt.internal.ui.editor.CEditor; public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { - private static final int EVENT_QUEUE_MILLIS = 100; - public BasicCppCallHierarchyTest(String name) { super(name); } - public static Test getSuite() { + public static Test suite() { TestSuite suite= new TestSuite("BasicCppCallHierarchyTest"); suite.addTestSuite(BasicCppCallHierarchyTest.class); suite.addTest(getFailingTests()); @@ -42,11 +40,16 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { private static Test getFailingTests() { TestSuite suite= new TestSuite("Failing Tests"); + suite.addTest(getFailingTest("_testAutomaticConstructor")); + suite.addTest(getFailingTest("_testDestructor")); + suite.addTest(getFailingTest("_testNamespacePart2")); return suite; } - private static FailingTest getFailingTest(String name) { - return new FailingTest(new BasicCppCallHierarchyTest(name)); + private static Test getFailingTest(String name) { + BaseTestCase failingTest= new BasicCppCallHierarchyTest(name); + failingTest.setExpectFailure(0); + return failingTest; } // {testMethods} @@ -72,13 +75,12 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { public void testMethods() throws Exception { String content = readTaggedComment("testMethods"); IFile file= createFile(getProject(), "testMethods.cpp", content); - waitForIndexer(file, 1000); + waitForIndexer(fPdom, file, 1000); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CEditor editor= (CEditor) IDE.openEditor(page, file); editor.selectAndReveal(content.indexOf("method"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); Tree tree = getCHTree(page); checkTreeNode(tree, 0, "MyClass::method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); @@ -87,7 +89,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("inline_method"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -95,7 +96,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("method(); // r1"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -103,7 +103,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("inline_method(); // r1"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -111,7 +110,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("method(); // r2"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -119,7 +117,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("inline_method(); // r2"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -127,7 +124,6 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("method(); // r3"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); @@ -135,10 +131,347 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("inline_method(); // r3"), 2); openCallHierarchy(editor); - runEventQueue(EVENT_QUEUE_MILLIS); checkTreeNode(tree, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); checkTreeNode(tree, 0, 1, "MyClass::method()"); checkTreeNode(tree, 0, 2, "func()"); } + + // {testStaticMethods} + // class MyClass { + // public: + // static void method(); + // static void inline_method() { + // method(); // r1 + // inline_method(); // r1 + // } + // }; + // + // void MyClass::method() { + // method(); // r2 + // inline_method(); // r2 + // } + // + // void func() { + // MyClass::method(); // r3 + // MyClass::inline_method(); // r3 + // } + public void testStaticMethods() throws Exception { + String content = readTaggedComment("testStaticMethods"); + IFile file= createFile(getProject(), "testStaticMethods.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("method"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "MyClass::method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("inline_method"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("method(); // r1"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("inline_method(); // r1"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("method(); // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("inline_method(); // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("method(); // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("inline_method(); // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + } + + + // {testFields} + // class MyClass { + // public: + // int field; + // int static_field; + // void method(); + // void inline_method() { + // int i= field; // r1 + // i= static_field; // r1 + // } + // }; + // + // void MyClass::method() { + // int i= field; // r2 + // i= static_field; // r2 + // } + // + // void func() { + // MyClass m; + // int i= m.field; // r3 + // i= MyClass::static_field; // r3 + // } + + public void testFields() throws Exception { + String content = readTaggedComment("testFields"); + IFile file= createFile(getProject(), "testFields.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("field"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "MyClass::field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("static_field"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::static_field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("field; // r1"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("static_field; // r1"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::static_field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("field; // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("static_field; // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::static_field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("field; // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + + editor.selectAndReveal(content.indexOf("static_field; // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::static_field"); + checkTreeNode(tree, 0, 0, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 1, "MyClass::method()"); + checkTreeNode(tree, 0, 2, "func()"); + } + + // {testAutomaticConstructor} + // class MyClass { + // public: + // MyClass(); + // virtual ~MyClass(); + // }; + // + // void automatic() { + // MyClass m; + // } + public void _testAutomaticConstructor() throws Exception { + String content = readTaggedComment("testAutomaticConstructor"); + IFile file= createFile(getProject(), "testConstructor.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("MyClass()"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "MyClass::MyClass()"); + checkTreeNode(tree, 0, 0, "automatic()"); + + editor.selectAndReveal(content.indexOf("~MyClass"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "MyClass::~MyClass()"); + checkTreeNode(tree, 0, 0, "automatic()"); + } + + // {testConstructor} + // class MyClass { + // public: + // MyClass(); + // virtual ~MyClass(); + // }; + // + // void heap() { + // MyClass* m= new MyClass(); + // delete m; + // } + public void testConstructor() throws Exception { + String content = readTaggedComment("testConstructor"); + IFile file= createFile(getProject(), "testConstructor.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("MyClass()"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "MyClass::MyClass()"); + checkTreeNode(tree, 0, 0, "heap()"); + } + + public void _testDestructor() throws Exception { + String content = readTaggedComment("testConstructor"); + IFile file= createFile(getProject(), "testConstructor.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("~MyClass()"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "MyClass::~MyClass()"); + checkTreeNode(tree, 0, 0, "heap()"); + } + + + // {testNamespace} + // namespace ns { + // int var; + // void func(); + // }; + // + // void ns::func() { + // --var; // r1 + // func(); // r1 + // } + // + // void gfunc1() { + // int i= ns::var; // r2 + // ns::func(); // r2 + // } + // + // using namespace ns; + // void gfunc2() { + // int i= var; // r3 + // func(); // r3 + // } + public void testNamespace() throws Exception { + String content = readTaggedComment("testNamespace"); + IFile file= createFile(getProject(), "testNamespace.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("var"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + checkTreeNode(tree, 0, "ns::var"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("func()"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::func()"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("func(); // r1"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::func()"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("var; // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::var"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("func(); // r2"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::func()"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("var; // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::var"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + + editor.selectAndReveal(content.indexOf("func(); // r3"), 2); + openCallHierarchy(editor); + checkTreeNode(tree, 0, "ns::func()"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + } + + public void _testNamespacePart2() throws Exception { + String content = readTaggedComment("testNamespace"); + IFile file= createFile(getProject(), "testNamespace.cpp", content); + waitForIndexer(fPdom, file, 1000); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("var; // r1"), 2); + openCallHierarchy(editor); + Tree tree = getCHTree(page); + + checkTreeNode(tree, 0, "ns::var"); + checkTreeNode(tree, 0, 0, "gfunc1()"); + checkTreeNode(tree, 0, 1, "gfunc2()"); + checkTreeNode(tree, 0, 2, "ns::func()"); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java index 1a39cce0248..7de0e9fc0d5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.ui.tests.callhierarchy; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; @@ -28,7 +27,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.tests.BaseTestCase; import org.eclipse.cdt.internal.core.pdom.PDOM; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; import org.eclipse.cdt.internal.ui.callhierarchy.CHViewPart; import org.eclipse.cdt.internal.ui.callhierarchy.CallHierarchyUI; @@ -37,7 +35,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor; public class CallHierarchyBaseTest extends BaseTestCase { private ICProject fCProject; - private PDOM fPdom; + public PDOM fPdom; public CallHierarchyBaseTest(String name) { super(name); @@ -60,32 +58,14 @@ public class CallHierarchyBaseTest extends BaseTestCase { return fCProject.getProject(); } - protected void waitForIndexer(IFile file, int maxmillis) throws Exception { - long endTime= System.currentTimeMillis() + maxmillis; - do { - fPdom.acquireReadLock(); - try { - PDOMFile pfile= fPdom.getFile(file.getLocation()); - // mstodo check timestamp - if (pfile != null) { - return; - } - } - finally { - fPdom.releaseReadLock(); - } - - Thread.sleep(50); - } while (System.currentTimeMillis() < endTime); - throw new Exception("Indexer did not complete in time!"); - } - protected void openCallHierarchy(CEditor editor) { CallHierarchyUI.setIsJUnitTest(true); CallHierarchyUI.open(editor, (ITextSelection) editor.getSelectionProvider().getSelection()); + runEventQueue(0); } protected Tree getCHTree(IWorkbenchPage page) { + runEventQueue(0); CHViewPart ch= (CHViewPart)page.findView(CUIPlugin.ID_CALL_HIERARCHY); assertNotNull(ch); Tree tree= ch.getTreeViewer().getTree(); @@ -103,7 +83,13 @@ public class CallHierarchyBaseTest extends BaseTestCase { protected void checkTreeNode(Tree tree, int i0, String label) { TreeItem root= null; try { - root= tree.getItem(i0); + for (int i=0; i<20; i++) { + root= tree.getItem(i0); + if (!"...".equals(root.getText())) { + break; + } + runEventQueue(50); + } } catch (IllegalArgumentException e) { assertTrue("Tree node " + label + "{" + i0 + "} does not exist!", false); @@ -112,14 +98,19 @@ public class CallHierarchyBaseTest extends BaseTestCase { } protected void checkTreeNode(Tree tree, int i0, int i1, String label) { - TreeItem item= null; try { TreeItem root= tree.getItem(i0); - item= root.getItem(i1); + TreeItem item= root.getItem(i1); + for (int i=0; i<20; i++) { + if (!"...".equals(item.getText())) { + break; + } + runEventQueue(50); + } + assertEquals(label, item.getText()); } catch (IllegalArgumentException e) { assertTrue("Tree node " + label + "{" + i0 + "," + i1 + "} does not exist!", false); } - assertEquals(label, item.getText()); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyTestSuite.java index 2d15a2df133..0d80c302e80 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyTestSuite.java @@ -21,7 +21,7 @@ public class CallHierarchyTestSuite extends TestSuite { public CallHierarchyTestSuite() { super("Tests in package org.eclipse.cdt.ui.tests.callhierarchy"); - addTest(BasicCallHierarchyTest.getSuite()); - addTest(BasicCppCallHierarchyTest.getSuite()); + addTest(BasicCallHierarchyTest.suite()); + addTest(BasicCppCallHierarchyTest.suite()); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java new file mode 100644 index 00000000000..663b6fcba4a --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.ui.tests.text.selection; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.ui.tests.BaseTestCase; + +import org.eclipse.cdt.internal.core.pdom.PDOM; + +public class ResolveBindingTests extends BaseTestCase { + + private ICProject fCProject; + private PDOM fPdom; + + public ResolveBindingTests(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite= new TestSuite("ResolveBindingTests"); + suite.addTestSuite(ResolveBindingTests.class); + suite.addTest(getFailingTests()); + return suite; + } + + private static Test getFailingTests() { + TestSuite suite= new TestSuite("Failing Tests"); + suite.addTest(getFailingTest("_testNamespaceVarBinding2", 156519)); + return suite; + } + + private static Test getFailingTest(String name, int bug) { + BaseTestCase failingTest= new ResolveBindingTests(name); + failingTest.setExpectFailure(bug); + return failingTest; + } + + protected void setUp() throws Exception { + super.setUp(); + fCProject= CProjectHelper.createCProject("ResolveBindingTests", "bin"); + CCorePlugin.getPDOMManager().setIndexerId(fCProject, "org.eclipse.cdt.core.fastIndexer"); + fPdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(fCProject); + fPdom.clear(); + } + + protected void tearDown() throws Exception { + if (fCProject != null) { + fCProject.getProject().delete(IProject.FORCE | IProject.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + } + super.tearDown(); + } + + private IASTName getSelectedName(IASTTranslationUnit astTU, int offset, int len) { + IASTName[] names= astTU.getLanguage().getSelectedNames(astTU, offset, len); + assertEquals(1, names.length); + return names[0]; + } + + private void checkBinding(IASTName name, Class clazz) { + IBinding binding; + binding= name.resolveBinding(); + assertNotNull("Cannot resolve binding", binding); + if (binding instanceof IProblemBinding) { + IProblemBinding problem= (IProblemBinding) binding; + fail("Cannot resolve binding: " + problem.getMessage()); + } + assertTrue(clazz.isInstance(binding)); + } + + // {namespace-var-test} + // namespace ns { + // int var; + // void func(); + // }; + // + // void ns::func() { + // ++var; // r1 + // ++ns::var; // r2 + // } + + public void testNamespaceVarBinding() throws Exception { + String content = readTaggedComment("namespace-var-test"); + IFile file= createFile(fCProject.getProject(), "nsvar.cpp", content); + waitForIndexer(fPdom, file, 2000); + + IASTTranslationUnit astTU= createPDOMBasedAST(fCProject, file); + IASTName name= getSelectedName(astTU, content.indexOf("var"), 3); + IBinding binding= name.resolveBinding(); + assertTrue(binding instanceof IVariable); + + name= getSelectedName(astTU, content.indexOf("var; // r1"), 3); + checkBinding(name, IVariable.class); + + name= getSelectedName(astTU, content.indexOf("var; // r2"), 3); + checkBinding(name, IVariable.class); + } + + public void _testNamespaceVarBinding2() throws Exception { + String content = readTaggedComment("namespace-var-test"); + IFile file= createFile(fCProject.getProject(), "nsvar.cpp", content); + waitForIndexer(fPdom, file, 2000); + + IASTTranslationUnit astTU= createPDOMBasedAST(fCProject, file); + + IASTName name= getSelectedName(astTU, content.indexOf("var; // r1"), 3); + IBinding binding= name.resolveBinding(); + checkBinding(name, IVariable.class); + + name= getSelectedName(astTU, content.indexOf("var; // r2"), 3); + checkBinding(name, IVariable.class); + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/SelectionTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/SelectionTestSuite.java index f0d7341471b..def1a8bed2a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/SelectionTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/SelectionTestSuite.java @@ -23,6 +23,7 @@ public class SelectionTestSuite extends TestSuite { super("Tests in package org.eclipse.cdt.ui.tests.text.selection"); // selection tests + addTest( ResolveBindingTests.suite() ); addTest( CPPSelectionTestsNoIndexer.suite() ); addTest( CSelectionTestsNoIndexer.suite() ); addTest( CPPSelectionTestsDOMIndexer.suite() ); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java index fb4e5f32960..a59d58427cf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java @@ -235,10 +235,6 @@ public class CIndexQueries { return; } IASTName name= names[names.length-1]; - IASTName[] a= ast.getReferences(name.resolveBinding()); - if (a.length > 0) { - a[0]= null; - } for (int i = 0; i < scope.length; i++) { ICProject project = scope[i]; findCalledBy(name, project, result);