From 59dd3702912b0b1af441a32b450265aef251d475 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 17 Nov 2006 13:38:40 +0000 Subject: [PATCH] Fixes a few testcases --- .../index/tests/IndexIncludeTest.java | 1 + .../index/tests/IndexListenerTest.java | 12 +- .../cdt/internal/index/tests/IndexTests.java | 1 + .../testplugin/util/TestSourceReader.java | 35 +++-- .../BasicCppCallHierarchyTest.java | 144 +++++++++--------- 5 files changed, 103 insertions(+), 90 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 9ae4dd9ccb2..345f6fc7a0b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -126,6 +126,7 @@ public class IndexIncludeTest extends IndexTestBase { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { file.setContents(new ByteArrayInputStream( "int included; int CONTEXT;\n".getBytes()), false, false, NPM); + file.setLocalTimeStamp(timestamp+1000); } }, NPM); assertTrue("Timestamp was not increased", file.getLocalTimeStamp() >= timestamp); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java index eb2c9a0cd06..b7358ff8208 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java @@ -77,14 +77,16 @@ public class IndexListenerTest extends BaseTestCase { try { IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;"); synchronized (mutex) { - mutex.wait(8000); if (state[0]+state[1] < 2) { - mutex.wait(1000); + mutex.wait(8000); + if (state[0]+state[1] < 2) { + mutex.wait(2000); + } } + assertEquals(1, state[0]); + assertEquals(1, state[1]); + assertEquals(0, state[2]); } - assertEquals(1, state[0]); - assertEquals(1, state[1]); - assertEquals(0, state[2]); } finally { im.removeIndexerStateListener(listener); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java index 486dd054ff0..ff8647f3776 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java @@ -24,6 +24,7 @@ public class IndexTests extends TestSuite { suite.addTest(IndexSearchTest.suite()); suite.addTest(IndexIncludeTest.suite()); suite.addTest(IndexBugsTests.suite()); + suite.addTest(EnclosingNamesTest.suite()); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index f4ae524cc01..543ecfd5a46 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -35,10 +35,13 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.osgi.framework.Bundle; @@ -201,19 +204,25 @@ public class TestSourceReader { * @throws Exception * @since 4.0 */ - public static IFile createFile(IContainer container, IPath filePath, String contents) throws CoreException { - //Obtain file handle - IFile file = container.getFile(filePath); - - InputStream stream = new ByteArrayInputStream(contents.getBytes()); - //Create file input stream - if (file.exists()) { - file.setContents(stream, false, false, new NullProgressMonitor()); - } - else { - file.create(stream, false, new NullProgressMonitor()); - } - return file; + public static IFile createFile(final IContainer container, final IPath filePath, final String contents) throws CoreException { + final IWorkspace ws = ResourcesPlugin.getWorkspace(); + final IFile result[] = new IFile[1]; + ws.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + //Obtain file handle + IFile file = container.getFile(filePath); + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + //Create file input stream + if (file.exists()) { + file.setContents(stream, false, false, new NullProgressMonitor()); + } + else { + file.create(stream, false, new NullProgressMonitor()); + } + result[0]= file; + } + }, null); + return result[0]; } /** 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 d3b8f175789..7ac10bec7b9 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 @@ -65,58 +65,58 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); } // {testStaticMethods} @@ -149,58 +149,58 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); } @@ -238,58 +238,58 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); 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()"); + checkTreeNode(tree, 0, 0, "func()"); + checkTreeNode(tree, 0, 1, "MyClass::inline_method()"); + checkTreeNode(tree, 0, 2, "MyClass::method()"); } // {testAutomaticConstructor}