1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Cleanup test helper classes

This commit is contained in:
Anton Leherbauer 2010-02-18 08:47:25 +00:00
parent b9fcfb7d29
commit 29acaaa99c
31 changed files with 200 additions and 228 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Andrew Gvozdev and others.
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
@ -64,7 +64,8 @@ import org.eclipse.core.runtime.jobs.Job;
public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
private static final int MAX_RETRY= 5;
private final static Set<String> externalFilesCreated = new HashSet<String>();
private final static Set<IResource> resourcesCreated = new HashSet<IResource>();
@ -186,6 +187,74 @@ public class ResourceHelper {
return project;
}
/**
* Create a plain Eclipse project.
*
* @param projectName
* @return the project handle
* @throws CoreException if project could not be created
*/
public static IProject createProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName);
if (!project.exists())
project.create(NULL_MONITOR);
else
project.refreshLocal(IResource.DEPTH_INFINITE, null);
if (!project.isOpen())
project.open(NULL_MONITOR);
return project;
}
/**
* Delete project by name.
*
* @param projectName
* @throws CoreException
*/
public static void deleteProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName);
if (project.exists())
delete(project);
}
/**
* Delete given project with content.
*
* @param project
* @throws CoreException
*/
public static void delete(final IProject project) throws CoreException {
delete(project, true);
}
/**
* Delete project.
*
* @param project
* @param deleteContent whether to delete project content
* @throws CoreException
*/
public static void delete(final IProject project, boolean deleteContent) throws CoreException {
for (int i= 0; i < MAX_RETRY; i++) {
try {
project.delete(deleteContent, true, NULL_MONITOR);
i= MAX_RETRY;
} catch (CoreException x) {
if (i == MAX_RETRY - 1) {
CTestPlugin.getDefault().getLog().log(x.getStatus());
}
try {
Thread.sleep(1000); // sleep a second
} catch (InterruptedException e) {
}
}
}
}
/**
* Creates a file with specified content.
*

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
package org.eclipse.cdt.ui.testplugin;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -29,7 +29,7 @@ import junit.framework.Assert;
public class Accessor extends Assert {
/** The class to access. */
private Class fClass;
private Class<?> fClass;
/** The instance to access. */
private Object fInstance;
@ -41,7 +41,7 @@ public class Accessor extends Assert {
* @param instance the instance
* @param clazz the class
*/
public Accessor(Object instance, Class clazz) {
public Accessor(Object instance, Class<?> clazz) {
assertNotNull(instance);
assertNotNull(clazz);
fInstance= instance;
@ -95,7 +95,7 @@ public class Accessor extends Assert {
* @param constructorTypes the types of the constructor arguments
* @param constructorArgs the constructor arguments
*/
public Accessor(String className, ClassLoader classLoader, Class[] constructorTypes, Object[] constructorArgs) {
public Accessor(String className, ClassLoader classLoader, Class<?>[] constructorTypes, Object[] constructorArgs) {
try {
fClass= Class.forName(className, true, classLoader);
} catch (ClassNotFoundException e) {
@ -103,7 +103,7 @@ public class Accessor extends Assert {
} catch (ExceptionInInitializerError e) {
fail();
}
Constructor constructor= null;
Constructor<?> constructor= null;
try {
constructor= fClass.getDeclaredConstructor(constructorTypes);
} catch (SecurityException e2) {
@ -169,7 +169,7 @@ public class Accessor extends Assert {
* @param arguments the method arguments
* @return the method return value
*/
public Object invoke(String methodName, Class[] types, Object[] arguments) {
public Object invoke(String methodName, Class<?>[] types, Object[] arguments) {
Method method= null;
try {
method= fClass.getDeclaredMethod(methodName, types);
@ -313,12 +313,12 @@ public class Accessor extends Assert {
return field;
}
private static Class[] getTypes(Object[] objects) {
private static Class<?>[] getTypes(Object[] objects) {
if (objects == null)
return null;
int length= objects.length;
Class[] classes= new Class[length];
Class<?>[] classes= new Class[length];
for (int i= 0; i < length; i++) {
assertNotNull(objects[i]);
classes[i]= objects[i].getClass();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
package org.eclipse.cdt.ui.testplugin;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -102,6 +102,7 @@ public abstract class DisplayHelper {
*/
public static void sleep(Display display, long millis) {
new DisplayHelper() {
@Override
public boolean condition() {
return false;
}
@ -426,6 +427,7 @@ final class DisplayWaiter {
/*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
run2();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
package org.eclipse.cdt.ui.testplugin;
import java.io.ByteArrayInputStream;
@ -75,9 +75,9 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.ui.text.CReconcilingStrategy;
import org.eclipse.cdt.internal.ui.text.CompositeReconcilingStrategy;
@ -280,6 +280,7 @@ public class EditorTestHelper {
runEventQueue(minTime);
DisplayHelper helper= new DisplayHelper() {
@Override
public boolean condition() {
return allJobsQuiet();
}
@ -361,6 +362,7 @@ public class EditorTestHelper {
}
final Accessor cReconcilerAccessor= reconcilerAccessor;
DisplayHelper helper= new DisplayHelper() {
@Override
public boolean condition() {
return !isRunning(cReconcilerAccessor, backgroundThreadAccessor);
}
@ -443,9 +445,10 @@ public class EditorTestHelper {
public static ICProject createCProject(String project, String externalSourceFolder, boolean linkSourceFolder, boolean useIndexer) throws CoreException {
ICProject cProject= CProjectHelper.createCCProject(project, "bin", useIndexer ? IIndexManager.ID_FAST_INDEXER : IIndexManager.ID_NO_INDEXER);
IFolder folder;
if (linkSourceFolder)
folder= ResourceHelper.createLinkedFolder((IProject) cProject.getUnderlyingResource(), new Path("src"), CTestPlugin.getDefault(), new Path(externalSourceFolder));
else {
if (linkSourceFolder) {
File file= FileTool.getFileInPlugin(CTestPlugin.getDefault(), new Path(externalSourceFolder));
folder= ResourceHelper.createLinkedFolder((IProject) cProject.getUnderlyingResource(), "src", file.getAbsolutePath());
} else {
folder= ((IProject) cProject.getUnderlyingResource()).getFolder("src");
importFilesFromDirectory(FileTool.getFileInPlugin(CTestPlugin.getDefault(), new Path(externalSourceFolder)), folder.getFullPath(), null);
}
@ -481,9 +484,10 @@ public class EditorTestHelper {
final IProject project= newProject[0];
Assert.assertNotNull(project);
final IFolder folder;
if (linkSourceFolder)
folder= ResourceHelper.createLinkedFolder(project, new Path("src"), CTestPlugin.getDefault(), new Path(externalSourceFolder));
else {
if (linkSourceFolder) {
File file= FileTool.getFileInPlugin(CTestPlugin.getDefault(), new Path(externalSourceFolder));
folder= ResourceHelper.createLinkedFolder(project, "src", file.getAbsolutePath());
} else {
folder= project.getFolder("src");
importFilesFromDirectory(FileTool.getFileInPlugin(CTestPlugin.getDefault(), new Path(externalSourceFolder)), folder.getFullPath(), null);
}
@ -506,12 +510,12 @@ public class EditorTestHelper {
}
public static IFile[] findFiles(IResource resource) throws CoreException {
List files= new ArrayList();
List<IResource> files= new ArrayList<IResource>();
findFiles(resource, files);
return (IFile[]) files.toArray(new IFile[files.size()]);
return files.toArray(new IFile[files.size()]);
}
private static void findFiles(IResource resource, List files) throws CoreException {
private static void findFiles(IResource resource, List<IResource> files) throws CoreException {
if (resource instanceof IFile) {
files.add(resource);
return;
@ -534,7 +538,7 @@ public class EditorTestHelper {
public static void importFilesFromDirectory(File rootDir, IPath destPath, IProgressMonitor monitor) throws CoreException {
try {
IImportStructureProvider structureProvider= FileSystemStructureProvider.INSTANCE;
List files= new ArrayList(100);
List<File> files= new ArrayList<File>(100);
addFiles(rootDir, files);
ImportOperation op= new ImportOperation(destPath, rootDir, structureProvider, new ImportOverwriteQuery(), files);
op.setCreateContainerStructure(false);
@ -548,9 +552,9 @@ public class EditorTestHelper {
return new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, -1, "", x));
}
private static void addFiles(File dir, List collection) throws IOException {
private static void addFiles(File dir, List<File> collection) throws IOException {
File[] files= dir.listFiles();
List subDirs= new ArrayList(2);
List<File> subDirs= new ArrayList<File>(2);
for (int i= 0; i < files.length; i++) {
if (files[i].isFile()) {
collection.add(files[i]);
@ -558,9 +562,9 @@ public class EditorTestHelper {
subDirs.add(files[i]);
}
}
Iterator iter= subDirs.iterator();
Iterator<File> iter= subDirs.iterator();
while (iter.hasNext()) {
File subDir= (File)iter.next();
File subDir= iter.next();
addFiles(subDir, collection);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
package org.eclipse.cdt.ui.testplugin;
import java.io.File;
import java.io.FileInputStream;
@ -62,11 +62,11 @@ public class FileTool {
private static void unzip(ZipFile zipFile, File rootDstDir, File dstDir, int depth) throws IOException {
Enumeration entries = zipFile.entries();
Enumeration<? extends ZipEntry> entries = zipFile.entries();
try {
while(entries.hasMoreElements()){
ZipEntry entry = (ZipEntry)entries.nextElement();
ZipEntry entry = entries.nextElement();
if(entry.isDirectory()){
continue;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
package org.eclipse.cdt.ui.testplugin;
import java.io.File;
import java.io.IOException;
@ -141,6 +141,7 @@ public class ResourceTestHelper {
public static void write(String dest, final String content) throws IOException, CoreException {
InputStream stream= new InputStream() {
private Reader fReader= new StringReader(content);
@Override
public int read() throws IOException {
return fReader.read();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2010 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
@ -23,8 +23,8 @@ import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IBuildConsoleManager;
import org.eclipse.cdt.ui.testplugin.DisplayHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.DisplayHelper;
/**
* BuildConsoleTests.
@ -41,11 +41,13 @@ public class BuildConsoleTests extends BaseUITestCase {
return new TestSuite(BuildConsoleTests.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
fCProject= CProjectHelper.createCCProject(getName(), "unused", IPDOMManager.ID_FAST_INDEXER);
}
@Override
protected void tearDown() throws Exception {
CProjectHelper.delete(fCProject);
fCProject= null;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2010 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
@ -28,8 +28,8 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.ui.callhierarchy.CHViewPart;
import org.eclipse.cdt.internal.ui.callhierarchy.CallHierarchyUI;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2010 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
@ -29,8 +29,8 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -40,8 +40,8 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.ui.text.IInvocationContext;
import org.eclipse.cdt.ui.text.IProblemLocation;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -43,6 +43,9 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.Accessor;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2010 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
@ -21,6 +21,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.core.model.ext.SourceRange;

View file

@ -28,6 +28,8 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.editor.AddIncludeOnSelectionAction;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2010 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
@ -50,7 +50,13 @@ import org.eclipse.cdt.core.model.ICElement;
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.core.testplugin.ResourceHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.Accessor;
import org.eclipse.cdt.ui.testplugin.DisplayHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.FileTool;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.IColorManager;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -42,6 +42,9 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.Accessor;
import org.eclipse.cdt.ui.testplugin.DisplayHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2010 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
@ -30,6 +30,8 @@ import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.ui.compare.CStructureCreator;
@ -47,11 +49,13 @@ public class CStructureCreatorTest extends BaseUITestCase {
private ICProject fCProject;
@Override
protected void setUp() throws Exception {
super.setUp();
fCProject= EditorTestHelper.createCProject("CStructureCreatorTest", "resources/compare", false);
}
@Override
protected void tearDown() throws Exception {
if (fCProject != null) {
CProjectHelper.delete(fCProject);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2010 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
@ -35,6 +35,8 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2010 IBM Corporation 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
@ -26,6 +26,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -36,6 +38,7 @@ public class FormatActionTest extends TestCase {
private static final String PROJECT= "FormatTests";
private static final class EmptyBundle extends ListResourceBundle {
@Override
protected Object[][] getContents() {
return new Object[0][];
}
@ -49,6 +52,7 @@ public class FormatActionTest extends TestCase {
super(test);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -56,6 +60,7 @@ public class FormatActionTest extends TestCase {
fCProject.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
}
@Override
protected void tearDown () throws Exception {
if (fCProject != null)
CProjectHelper.delete(fCProject);
@ -64,7 +69,7 @@ public class FormatActionTest extends TestCase {
}
}
private static final Class THIS= FormatActionTest.class;
private static final Class<?> THIS= FormatActionTest.class;
public static Test suite() {
return new FormatTestSetup(new TestSuite(THIS));
}
@ -76,6 +81,7 @@ public class FormatActionTest extends TestCase {
/*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
String filename= createFileName("Before");
fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(filename), true);
@ -86,6 +92,7 @@ public class FormatActionTest extends TestCase {
/*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
EditorTestHelper.closeEditor(fEditor);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CElementHyperlinkDetector;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2010 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
@ -25,6 +25,9 @@ import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.Accessor;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CSourceViewerDecorationSupport;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* Copyright (c) 2005, 2010 IBM Corporation 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
@ -25,6 +25,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.actions.IndentAction;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -36,6 +38,7 @@ public class IndentActionTest extends TestCase {
private static final String PROJECT= "IndentTests";
private static final class EmptyBundle extends ListResourceBundle {
@Override
protected Object[][] getContents() {
return new Object[0][];
}
@ -49,6 +52,7 @@ public class IndentActionTest extends TestCase {
super(test);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -56,6 +60,7 @@ public class IndentActionTest extends TestCase {
fCProject.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
}
@Override
protected void tearDown () throws Exception {
if (fCProject != null)
CProjectHelper.delete(fCProject);
@ -75,6 +80,7 @@ public class IndentActionTest extends TestCase {
/*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
String filename= createFileName("Before");
fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(filename), true);
@ -85,6 +91,7 @@ public class IndentActionTest extends TestCase {
/*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
EditorTestHelper.closeEditor(fEditor);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 IBM Corporation and others.
* Copyright (c) 2000, 2010 IBM Corporation 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
@ -49,6 +49,8 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.DisplayHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -85,10 +87,12 @@ public class MarkOccurrenceTest extends BaseUITestCase {
public MarkOccurrenceTestSetup(Test test) {
super(test);
}
@Override
protected void setUp() throws Exception {
super.setUp();
fCProject= EditorTestHelper.createCProject(PROJECT, "resources/ceditor", false, true);
}
@Override
protected void tearDown() throws Exception {
if (fCProject != null)
CProjectHelper.delete(fCProject);
@ -105,6 +109,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
return setUpTest(new TestSuite(MarkOccurrenceTest.class));
}
@Override
protected void setUp() throws Exception {
if (!ResourcesPlugin.getWorkspace().getRoot().exists(new Path(PROJECT))) {
fProjectSetup= new MarkOccurrenceTestSetup(this);
@ -146,6 +151,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
/*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
SelectionListenerWithASTManager.getDefault().removeListener(fEditor, fSelWASTListener);
EditorTestHelper.closeAllEditors();
@ -549,6 +555,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
private void assertOccurrences(final int expected) {
DisplayHelper helper= new DisplayHelper() {
@Override
protected boolean condition() {
return fOccurrences == expected;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2010 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
@ -20,6 +20,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.AddBlockCommentTest.LinePosition;

View file

@ -1,157 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
import java.io.File;
import java.io.InputStream;
import org.eclipse.core.filebuffers.manipulation.ContainerCreator;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
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.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
/**
* Copied from org.eclipse.core.filebuffers.tests.
*
* @since 4.0
*/
public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR= new NullProgressMonitor();
private static final int MAX_RETRY= 5;
public static IProject createProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName);
if (!project.exists())
project.create(NULL_MONITOR);
else
project.refreshLocal(IResource.DEPTH_INFINITE, null);
if (!project.isOpen())
project.open(NULL_MONITOR);
return project;
}
public static void deleteProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName);
if (project.exists())
delete(project);
}
public static void delete(final IProject project) throws CoreException {
delete(project, true);
}
public static void delete(final IProject project, boolean deleteContent) throws CoreException {
for (int i= 0; i < MAX_RETRY; i++) {
try {
project.delete(deleteContent, true, NULL_MONITOR);
i= MAX_RETRY;
} catch (CoreException x) {
if (i == MAX_RETRY - 1) {
CTestPlugin.getDefault().getLog().log(x.getStatus());
// throw x;
}
try {
Thread.sleep(1000); // sleep a second
} catch (InterruptedException e) {
}
}
}
}
public static IFolder createFolder(String portableFolderPath) throws CoreException {
ContainerCreator creator= new ContainerCreator(ResourcesPlugin.getWorkspace(), new Path(portableFolderPath));
IContainer container= creator.createContainer(NULL_MONITOR);
if (container instanceof IFolder)
return (IFolder) container;
return null;
}
public static IFile createFile(IFolder folder, String name, String contents) throws CoreException {
return createFile(folder.getFile(name), name, contents);
}
public static IFile createFile(IProject project, String name, String contents) throws CoreException {
return createFile(project.getFile(name), name, contents);
}
private static IFile createFile(IFile file, String name, String contents) throws CoreException {
if (contents == null)
contents= "";
InputStream inputStream= new java.io.StringBufferInputStream(contents);
file.create(inputStream, true, NULL_MONITOR);
return file;
}
public static IFile createLinkedFile(IContainer container, IPath linkPath, File linkedFileTarget) throws CoreException {
IFile iFile= container.getFile(linkPath);
iFile.createLink(new Path(linkedFileTarget.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return iFile;
}
public static IFile createLinkedFile(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFileTargetPath) throws CoreException {
File file= FileTool.getFileInPlugin(plugin, linkedFileTargetPath);
IFile iFile= container.getFile(linkPath);
iFile.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return iFile;
}
public static IFolder createLinkedFolder(IContainer container, IPath linkPath, File linkedFolderTarget) throws CoreException {
IFolder folder= container.getFolder(linkPath);
folder.createLink(new Path(linkedFolderTarget.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return folder;
}
public static IFolder createLinkedFolder(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFolderTargetPath) throws CoreException {
File file= FileTool.getFileInPlugin(plugin, linkedFolderTargetPath);
IFolder iFolder= container.getFolder(linkPath);
iFolder.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return iFolder;
}
public static IProject createLinkedProject(String projectName, Plugin plugin, IPath linkPath) throws CoreException {
IWorkspace workspace= ResourcesPlugin.getWorkspace();
IProject project= workspace.getRoot().getProject(projectName);
IProjectDescription desc= workspace.newProjectDescription(projectName);
File file= FileTool.getFileInPlugin(plugin, linkPath);
IPath projectLocation= new Path(file.getAbsolutePath());
if (Platform.getLocation().equals(projectLocation))
projectLocation= null;
desc.setLocation(projectLocation);
project.create(desc, NULL_MONITOR);
if (!project.isOpen())
project.open(NULL_MONITOR);
return project;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2008, 2010 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
@ -27,6 +27,8 @@ import org.eclipse.ui.texteditor.ShiftAction;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 IBM Corporation 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
@ -35,8 +35,8 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.ui.text.ICPartitions;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Symbian Software Systems and others.
* Copyright (c) 2008, 2010 Symbian Software Systems 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
@ -38,10 +38,10 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.Accessor;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.Accessor;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.ui.tests.text.ResourceTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;

View file

@ -51,8 +51,8 @@ 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.core.testplugin.FileManager;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.core.parser.ParserException;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 IBM Corporation 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
@ -55,8 +55,8 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 IBM Corporation 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
@ -49,8 +49,8 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2010 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
@ -35,8 +35,8 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.typehierarchy.THViewPart;