mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Fix tests: avoid using getFocusControl(), returns null on build machine.
This commit is contained in:
parent
4eb9c1a712
commit
00b6127937
5 changed files with 115 additions and 44 deletions
|
@ -11,6 +11,8 @@
|
|||
package org.eclipse.cdt.ui.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.NotEnabledException;
|
||||
|
@ -22,6 +24,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.SWTException;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
|
@ -220,24 +223,52 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
assertNotNull(hs);
|
||||
hs.executeCommand(commandID, null);
|
||||
}
|
||||
|
||||
protected Control getFocusControl(Class clazz, int wait) {
|
||||
return getFocusControl(clazz, null, wait);
|
||||
|
||||
private Control[] findControls(Control w, Class clazz) {
|
||||
ArrayList result= new ArrayList();
|
||||
findControls(w, clazz, result);
|
||||
return (Control[]) result.toArray(new Control[result.size()]);
|
||||
}
|
||||
|
||||
protected Control getFocusControl(Class clazz, Control differentTo, int wait) {
|
||||
Control fc= null;
|
||||
for (int i = 0; i <= wait/10; i++) {
|
||||
fc= Display.getCurrent().getFocusControl();
|
||||
if (clazz.isInstance(fc) && fc != differentTo) {
|
||||
return fc;
|
||||
private void findControls(Control w, Class clazz, List result) {
|
||||
if (clazz.isInstance(w)) {
|
||||
result.add(w);
|
||||
}
|
||||
if (w instanceof Composite) {
|
||||
Composite comp= (Composite) w;
|
||||
Control[] children= comp.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
findControls(children[i], clazz, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final protected TreeItem checkTreeNode(IViewPart part, int i0, String label) {
|
||||
Tree tree= null;
|
||||
TreeItem root= null;
|
||||
for (int i=0; i<400; i++) {
|
||||
Control[] trees= findControls(part.getSite().getShell(), Tree.class);
|
||||
for (int j = 0; j < trees.length; j++) {
|
||||
try {
|
||||
tree= (Tree) trees[j];
|
||||
root= tree.getItem(i0);
|
||||
if (label.equals(root.getText())) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
catch (SWTException e) {
|
||||
// in case widget was disposed, item may be replaced
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// item does not yet exist.
|
||||
}
|
||||
}
|
||||
runEventQueue(10);
|
||||
}
|
||||
assertNotNull(fc);
|
||||
assertTrue(fc != differentTo);
|
||||
assertTrue("Unexpected class " + fc.getClass().getName(), clazz.isInstance(fc));
|
||||
return fc;
|
||||
assertNotNull("No tree in viewpart", tree);
|
||||
assertNotNull("Tree node " + label + "{" + i0 + "} does not exist!", root);
|
||||
assertEquals(label, root.getText());
|
||||
return root;
|
||||
}
|
||||
|
||||
final protected TreeItem checkTreeNode(Tree tree, int i0, String label) {
|
||||
|
|
|
@ -87,10 +87,12 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
|
|||
String header= content[0].toString();
|
||||
String source = content[1].toString();
|
||||
IFile headerFile= createFile(fCProject.getProject(), "testMethods.h", header);
|
||||
waitForIndexer(fIndex, headerFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
IFile sourceFile= createFile(fCProject2.getProject(), "testMethods.cpp", source);
|
||||
waitForIndexer(fIndex, sourceFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
CEditor editor= (CEditor) IDE.openEditor(page, sourceFile);
|
||||
waitForIndexer(fIndex, sourceFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
|
||||
|
||||
editor.selectAndReveal(source.indexOf("method"), 2);
|
||||
openCallHierarchy(editor, true);
|
||||
|
|
|
@ -14,8 +14,6 @@ package org.eclipse.cdt.ui.tests.callhierarchy;
|
|||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
|
@ -60,19 +58,22 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
|
|||
IFile file1= createFile(getProject(), "SomeClass.h", contents[0].toString());
|
||||
IFile file2= createFile(getProject(), "SomeClass.cpp", contents[1].toString());
|
||||
waitForIndexer(fIndex, file2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
|
||||
|
||||
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
|
||||
// open editor, check outline
|
||||
openEditor(file1);
|
||||
IViewPart outline = activateView(IPageLayout.ID_OUTLINE);
|
||||
Tree outlineTree= (Tree) getFocusControl(Tree.class, 8000);
|
||||
checkTreeNode(outlineTree, 0, "SomeClass");
|
||||
Tree outlineTree= checkTreeNode(outline, 0, "SomeClass").getParent();
|
||||
expandTreeItem(outlineTree, 0);
|
||||
checkTreeNode(outlineTree, 0, 0, "method() : void");
|
||||
|
||||
// open and check call hierarchy
|
||||
activateView(IPageLayout.ID_OUTLINE);
|
||||
selectTreeItem(outlineTree, 0, 0);
|
||||
executeCommand(outline, ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
|
||||
CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
Tree chTree= (Tree) getFocusControl(Tree.class, 8000);
|
||||
checkTreeNode(chTree, 0, "SomeClass::method()");
|
||||
Tree chTree= checkTreeNode(ch, 0, "SomeClass::method()").getParent();
|
||||
checkTreeNode(chTree, 0, 1, null);
|
||||
|
||||
ch.onSetShowReferencedBy(false);
|
||||
|
@ -102,47 +103,48 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
|
|||
IFile file2= createFile(getProject(), "SomeClass.cpp", contents[1].toString());
|
||||
waitForIndexer(fIndex, file2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
|
||||
IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
Control avoid= getFocusControl(Control.class, 8000);
|
||||
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
|
||||
// open editor, check outline
|
||||
openEditor(file1);
|
||||
outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
Tree outlineTree= (Tree) getFocusControl(Tree.class, avoid, 8000);
|
||||
checkTreeNode(outlineTree, 1, "SomeClass::ambiguous_impl() : void");
|
||||
Tree outlineTree= checkTreeNode(outline, 1, "SomeClass::ambiguous_impl() : void").getParent();
|
||||
checkTreeNode(outlineTree, 2, "other() : void");
|
||||
|
||||
// open and check call hierarchy
|
||||
activateView(IPageLayout.ID_OUTLINE);
|
||||
selectTreeItem(outlineTree, 1); // select the definition
|
||||
executeCommand(outline, ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
|
||||
CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
|
||||
ch.onSetShowReferencedBy(false);
|
||||
Tree chTree= (Tree) getFocusControl(Tree.class, 8000);
|
||||
checkTreeNode(chTree, 0, "SomeClass::ambiguous_impl()");
|
||||
Tree chTree= checkTreeNode(ch, 0, "SomeClass::ambiguous_impl()").getParent();
|
||||
checkTreeNode(chTree, 0, 0, "SomeClass::ref1");
|
||||
|
||||
// just change the call hierarchy
|
||||
outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
outlineTree= (Tree) getFocusControl(Tree.class, avoid, 8000);
|
||||
checkTreeNode(outlineTree, 2, "other() : void");
|
||||
// open and check call hierarchy
|
||||
activateView(IPageLayout.ID_OUTLINE);
|
||||
selectTreeItem(outlineTree, 2);
|
||||
executeCommand(outline, ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
checkTreeNode(chTree, 0, "other()");
|
||||
|
||||
openEditor(file2);
|
||||
outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
outlineTree= (Tree) getFocusControl(Tree.class, outlineTree, 8000);
|
||||
|
||||
// open editor, check outline
|
||||
openEditor(file2);
|
||||
outlineTree= checkTreeNode(outline, 0, "SomeClass.h").getParent();
|
||||
checkTreeNode(outlineTree, 1, "SomeClass::ambiguous_impl() : void");
|
||||
|
||||
// open and check call hierarchy
|
||||
activateView(IPageLayout.ID_OUTLINE);
|
||||
selectTreeItem(outlineTree, 1); // select the definition
|
||||
executeCommand(outline, ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
|
||||
ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
ch.onSetShowReferencedBy(false);
|
||||
chTree= (Tree) getFocusControl(Tree.class, 8000);
|
||||
checkTreeNode(chTree, 0, "SomeClass::ambiguous_impl()");
|
||||
chTree= checkTreeNode(ch, 0, "SomeClass::ambiguous_impl()").getParent();
|
||||
checkTreeNode(chTree, 0, 0, "SomeClass::ref2");
|
||||
}
|
||||
|
||||
private void openEditor(IFile file) throws WorkbenchException {
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
IDE.openEditor(page, file, true);
|
||||
getFocusControl(StyledText.class, 8000);
|
||||
runEventQueue(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.ui.tests.typehierarchy;
|
|||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
|
@ -65,6 +66,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("Simple1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Simple1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -157,6 +162,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("field1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Simple1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -250,6 +259,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("Multi1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Multi1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -357,6 +370,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("field1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Multi1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -464,6 +481,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("Diamond1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Diamond1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -571,6 +592,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("field1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "Diamond1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -672,6 +697,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("ViaTypedef1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "ViaTypedef1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -762,6 +791,10 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
editor.selectAndReveal(content.indexOf("field1"), 1);
|
||||
openQuickTypeHierarchy(editor);
|
||||
tree= getQuickTypeHierarchyViewer(editor);
|
||||
if (tree == null) {
|
||||
checkPlatform();
|
||||
return;
|
||||
}
|
||||
|
||||
item1= checkTreeNode(tree, 0, "ViaTypedef1");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
@ -822,4 +855,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
assertEquals(0, item4.getItemCount());
|
||||
|
||||
}
|
||||
|
||||
private void checkPlatform() {
|
||||
assertFalse(Platform.getOS().equals(Platform.OS_WIN32));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,6 @@ public class TypeHierarchyBaseTest extends BaseUITestCase {
|
|||
}
|
||||
runEventQueue(10);
|
||||
}
|
||||
fail();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue