1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Include Browser: Adds a simple testcase.

This commit is contained in:
Markus Schorn 2006-12-12 13:34:24 +00:00
parent 9840f921ae
commit 11719658ed
6 changed files with 245 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.refactoring.tests.RenameRegressionTests;
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
import org.eclipse.cdt.ui.tests.text.TextTestSuite;
import org.eclipse.cdt.ui.tests.text.contentassist.ContentAssistTestSuite;
import org.eclipse.cdt.ui.tests.viewsupport.ViewSupportTestSuite;
@ -47,7 +48,10 @@ public class AutomatedSuite extends TestSuite {
// tests for package org.eclipse.cdt.ui.tests.callhierarchy
addTest(CallHierarchyTestSuite.suite());
// tests for package org.eclipse.cdt.ui.tests.callhierarchy
addTest(IncludeBrowserTestSuite.suite());
// tests from package org.eclipse.cdt.ui.tests.text.contentAssist
addTest(ContentAssistTestSuite.suite());

View file

@ -49,7 +49,15 @@ public class BaseUITestCase extends BaseTestCase {
protected String readTaggedComment(final String tag) throws IOException {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", getClass(), tag);
}
/**
* Reads multiple sections in comments from the source of the given class.
* @since 4.0
*/
public StringBuffer[] getContentsForTest(int sections) throws IOException {
return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", getClass(), getName(), sections);
}
protected IFile createFile(IContainer container, String fileName, String contents) throws Exception {
return TestSourceReader.createFile(container, new Path(fileName), contents);
}

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* 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.includebrowser;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest {
public BasicIncludeBrowserTest(String name) {
super(name);
}
public static Test suite() {
return suite(BasicIncludeBrowserTest.class);
}
// // source
// #include "user.h"
// #include <system.h>
public void testSimpleInclusion() throws Exception {
TestScannerProvider.sIncludes= new String[]{getProject().getProject().getLocation().toOSString()};
StringBuffer[] contents= getContentsForTest(1);
IFile user= createFile(getProject(), "user.h", "");
IFile system= createFile(getProject(), "system.h", "");
IFile source= createFile(getProject(), "source.cpp", contents[0].toString());
waitForIndexer(fIndex, source, INDEXER_WAIT_TIME);
openIncludeBrowser(source);
Tree tree = getIBTree();
checkTreeNode(tree, 0, "source.cpp");
checkTreeNode(tree, 0, 0, "user.h");
checkTreeNode(tree, 0, 1, "system.h");
// the tree has to be reversed
openIncludeBrowser(user, true);
checkTreeNode(tree, 0, "user.h");
checkTreeNode(tree, 0, 0, "source.cpp");
openIncludeBrowser(system);
checkTreeNode(tree, 0, "system.h");
checkTreeNode(tree, 0, 0, "source.cpp");
}
}

View file

@ -0,0 +1,135 @@
/*******************************************************************************
* 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.includebrowser;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.ui.includebrowser.IBViewPart;
public class IncludeBrowserBaseTest extends BaseUITestCase {
protected static final int INDEXER_WAIT_TIME = 8000;
protected static IProgressMonitor NPM= new NullProgressMonitor();
private ICProject fCProject;
protected IIndex fIndex;
public IncludeBrowserBaseTest(String name) {
super(name);
}
protected void setUp() throws CoreException {
fCProject= CProjectHelper.createCCProject("__ibTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
// clear the index
CCoreInternals.getPDOMManager().reindex(fCProject);
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
}
protected void tearDown() throws CoreException {
if (fCProject != null) {
CProjectHelper.delete(fCProject);
}
}
protected IProject getProject() {
return fCProject.getProject();
}
protected IBViewPart openIncludeBrowser(IFile file) throws PartInitException {
IBViewPart result = doOpenIncludeBrowser(file);
runEventQueue(200);
return result;
}
protected IBViewPart openIncludeBrowser(IFile file, boolean includedBy) throws PartInitException {
IBViewPart result = doOpenIncludeBrowser(file);
result.onSetDirection(includedBy);
runEventQueue(200);
return result;
}
private IBViewPart doOpenIncludeBrowser(IFile file) throws PartInitException {
ITranslationUnit tu= CoreModelUtil.findTranslationUnit(file);
if (tu == null) {
fail(file.getFullPath().toString() + " is no translation unit!");
}
IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IBViewPart result= (IBViewPart)page.showView(CUIPlugin.ID_INCLUDE_BROWSER);
result.setInput(tu);
return result;
}
protected Tree getIBTree() {
IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
runEventQueue(0);
IBViewPart ib= (IBViewPart)page.findView(CUIPlugin.ID_INCLUDE_BROWSER);
assertNotNull(ib);
Tree tree= ib.getTreeViewer().getTree();
return tree;
}
protected void checkTreeNode(Tree tree, int i0, String label) {
TreeItem root= null;
try {
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);
}
assertEquals(label, root.getText());
}
protected void checkTreeNode(Tree tree, int i0, int i1, String label) {
try {
TreeItem root= tree.getItem(i0);
TreeItem item= root.getItem(i1);
for (int i=0; i<40; 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);
}
}
}

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* 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.includebrowser;
import junit.framework.TestSuite;
public class IncludeBrowserTestSuite extends TestSuite {
public static TestSuite suite() {
return new IncludeBrowserTestSuite();
}
public IncludeBrowserTestSuite() {
super("Tests in package org.eclipse.cdt.ui.tests.inlucdebrowser");
addTest(BasicIncludeBrowserTest.suite());
}
}

View file

@ -33,6 +33,7 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
@ -45,7 +46,6 @@ import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Text;
@ -176,8 +176,12 @@ public class IBViewPart extends ViewPart
fContentProvider.setComputeIncludedBy(isHeader);
fIncludedByAction.setChecked(isHeader);
fIncludesToAction.setChecked(!isHeader);
fIncludedByAction.setEnabled(false);
updateSorter();
}
else {
fIncludedByAction.setEnabled(true);
}
fTreeViewer.setInput(input);
fPagebook.showPage(fViewerPage);
updateHistory(input);
@ -609,7 +613,7 @@ public class IBViewPart extends ViewPart
}
}
protected void onSetDirection(boolean includedBy) {
public void onSetDirection(boolean includedBy) {
if (includedBy != fContentProvider.getComputeIncludedBy()) {
Object input= fTreeViewer.getInput();
fTreeViewer.setInput(null);
@ -734,8 +738,9 @@ public class IBViewPart extends ViewPart
};
}
public Control getPageBook() {
return fPagebook;
// access for tests
public TreeViewer getTreeViewer() {
return fTreeViewer;
}
public ITranslationUnit[] getHistoryEntries() {