update
diff --git a/org.eclipse.jdt.text.tests/plugin.xml b/org.eclipse.jdt.text.tests/plugin.xml
index b6e6ef8..e79ac5d 100644
--- a/org.eclipse.jdt.text.tests/plugin.xml
+++ b/org.eclipse.jdt.text.tests/plugin.xml
@@ -28,6 +28,8 @@
<import plugin="org.eclipse.ui.ide"/>
<import plugin="org.eclipse.test.performance"/>
<import plugin="org.eclipse.text.tests"/>
+ <import plugin="org.eclipse.debug.core"/>
+ <import plugin="org.eclipse.jdt.debug"/>
</requires>
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JdtTextTestPlugin.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JdtTextTestPlugin.java
index 23139eb..ceb8153 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JdtTextTestPlugin.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JdtTextTestPlugin.java
@@ -23,6 +23,11 @@
* The main plugin class to be used in the desktop.
*/
public class JdtTextTestPlugin extends AbstractUIPlugin {
+ /**
+ * The plug-in id
+ * @since 3.1
+ */
+ public static final String PLUGIN_ID= "org.eclipse.jdt.text.tests";
//The shared instance.
private static JdtTextTestPlugin plugin;
//Resource bundle.
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/AllPerformanceTestSuite.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/AllPerformanceTestSuite.java
index 8774cd9..f8576d7 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/AllPerformanceTestSuite.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/AllPerformanceTestSuite.java
@@ -25,8 +25,10 @@
public AllPerformanceTestSuite() {
addTest(PerformanceTestSuite.suite());
- addTest(OpenJavaEditorTest.suite());
- addTest(OpenTextEditorTest.suite());
- addTest(EventDrivenTestSuite.suite());
+ addTest(PerformanceTestSuite2.suite());
+ addTest(PerformanceTestSuite3.suite());
+ addTest(PerformanceTestSuite4.suite());
+ addTest(PerformanceTestSuite5.suite());
+ addTest(DebuggingPerformanceTestSuite.suite()); // run separately in debug mode for testing the InvocationCountPerformanceMeter
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EditorTestHelper.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EditorTestHelper.java
index 9770461..37f55f0 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EditorTestHelper.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EditorTestHelper.java
@@ -11,46 +11,83 @@
package org.eclipse.jdt.text.tests.performance;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.Assert;
+
+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.IResource;
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.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.core.filebuffers.tests.FileTool;
+import org.eclipse.core.filebuffers.tests.ResourceHelper;
+
import org.eclipse.text.tests.Accessor;
+import org.eclipse.jface.preference.IPreferenceStore;
+
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IWidgetTokenKeeper;
+import org.eclipse.jface.text.IWidgetTokenOwner;
import org.eclipse.jface.text.reconciler.AbstractReconciler;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.ITypeNameRequestor;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.testplugin.JavaProjectHelper;
+import org.eclipse.jdt.text.tests.JdtTextTestPlugin;
+
+import org.eclipse.jdt.ui.PreferenceConstants;
+
import org.eclipse.jdt.internal.corext.util.AllTypesCache;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
import org.eclipse.jdt.internal.ui.text.JavaReconciler;
@@ -58,7 +95,12 @@
* @since 3.1
*/
public class EditorTestHelper {
-
+
+ private static class ImportOverwriteQuery implements IOverwriteQuery {
+ public String queryOverwrite(String file) {
+ return ALL;
+ }
+ }
private static class Requestor implements ITypeNameRequestor {
public void acceptClass(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
}
@@ -66,26 +108,51 @@
}
}
+ public static final String TEXT_EDITOR_ID= "org.eclipse.ui.DefaultTextEditor";
+
+ public static final String COMPILATION_UNIT_EDITOR_ID= "org.eclipse.jdt.ui.CompilationUnitEditor";
+
+ public static final String RESOURCE_PERSPECTIVE_ID= "org.eclipse.ui.resourcePerspective";
+
+ public static final String JAVA_PERSPECTIVE_ID= "org.eclipse.jdt.ui.JavaPerspective";
+
+ public static final String OUTLINE_VIEW_ID= "org.eclipse.ui.views.ContentOutline";
+
+ public static final String PACKAGE_EXPLORER_VIEW_ID= "org.eclipse.jdt.ui.PackageExplorer";
+
+ public static final String NAVIGATOR_VIEW_ID= "org.eclipse.ui.views.ResourceNavigator";
+
+ public static final String INTRO_VIEW_ID= "org.eclipse.ui.internal.introview";
+
public static IEditorPart openInEditor(IFile file, boolean runEventLoop) throws PartInitException {
IEditorPart part= IDE.openEditor(getActivePage(), file);
if (runEventLoop)
runEventQueue(part);
return part;
}
-
+
public static IEditorPart openInEditor(IFile file, String editorId, boolean runEventLoop) throws PartInitException {
IEditorPart part= IDE.openEditor(getActivePage(), file, editorId);
if (runEventLoop)
runEventQueue(part);
return part;
}
-
+
+ public static AbstractTextEditor[] openInEditor(IFile[] files, String editorId) throws PartInitException {
+ AbstractTextEditor editors[]= new AbstractTextEditor[files.length];
+ for (int i= 0; i < files.length; i++) {
+ editors[i]= (AbstractTextEditor) openInEditor(files[i], editorId, true);
+ joinReconciler(getSourceViewer(editors[i]), 100, 10000, 100);
+ }
+ return editors;
+ }
+
public static IDocument getDocument(ITextEditor editor) {
IDocumentProvider provider= editor.getDocumentProvider();
IEditorInput input= editor.getEditorInput();
return provider.getDocument(input);
}
-
+
public static void revertEditor(ITextEditor editor, boolean runEventQueue) {
editor.doRevertToSaved();
if (runEventQueue)
@@ -115,7 +182,9 @@
}
public static void runEventQueue(Shell shell) {
- while (shell.getDisplay().readAndDispatch());
+ while (shell.getDisplay().readAndDispatch()) {
+ // do nothing
+ }
}
public static void runEventQueue(long minTime) {
@@ -129,20 +198,24 @@
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
-
+
public static IWorkbenchPage getActivePage() {
IWorkbenchWindow window= getActiveWorkbenchWindow();
return window != null ? window.getActivePage() : null;
}
-
+
public static Display getActiveDisplay() {
IWorkbenchWindow window= getActiveWorkbenchWindow();
return window != null ? window.getShell().getDisplay() : null;
}
-
+
+ public static void joinBackgroundActivities(AbstractTextEditor editor) throws CoreException {
+ joinBackgroundActivities(getSourceViewer(editor));
+ }
+
public static void joinBackgroundActivities(SourceViewer sourceViewer) throws CoreException {
joinBackgroundActivities();
- joinReconciler(sourceViewer, 0, Long.MAX_VALUE, 500);
+ joinReconciler(sourceViewer, 500, 0, 500);
}
public static void joinBackgroundActivities() throws CoreException {
@@ -158,19 +231,19 @@
}
// Join indexing
new SearchEngine().searchAllTypeNames(
- null,
- null,
- SearchPattern.R_EXACT_MATCH,
- IJavaSearchConstants.CLASS,
- SearchEngine.createJavaSearchScope(new IJavaElement[0]),
- new Requestor(),
- IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
- null);
+ null,
+ null,
+ SearchPattern.R_EXACT_MATCH,
+ IJavaSearchConstants.CLASS,
+ SearchEngine.createJavaSearchScope(new IJavaElement[0]),
+ new Requestor(),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ null);
// Join all types cache
AllTypesCache.getTypes(SearchEngine.createJavaSearchScope(new IJavaElement[0]),
- IJavaSearchConstants.CLASS, new NullProgressMonitor(), new ArrayList());
+ IJavaSearchConstants.CLASS, new NullProgressMonitor(), new ArrayList());
// Join jobs
- joinJobs(0, Long.MAX_VALUE, 500);
+ joinJobs(0, 0, 500);
}
public static boolean joinJobs(long minTime, long maxTime, long intervalTime) {
@@ -179,16 +252,15 @@
while (System.currentTimeMillis() < startTime)
runEventQueue(intervalTime);
- long endTime= maxTime > 0 ? System.currentTimeMillis() + maxTime : Long.MAX_VALUE;
+ long endTime= maxTime > 0 && maxTime < Long.MAX_VALUE ? System.currentTimeMillis() + maxTime : Long.MAX_VALUE;
boolean calm= allJobsQuiet();
while (!calm && System.currentTimeMillis() < endTime) {
runEventQueue(intervalTime);
calm= allJobsQuiet();
}
-// System.out.println("--------------------------------------------------");
return calm;
}
-
+
public static void sleep(int intervalTime) {
try {
Thread.sleep(intervalTime);
@@ -196,33 +268,35 @@
e.printStackTrace();
}
}
-
+
public static boolean allJobsQuiet() {
IJobManager jobManager= Platform.getJobManager();
Job[] jobs= jobManager.find(null);
for (int i= 0; i < jobs.length; i++) {
Job job= jobs[i];
int state= job.getState();
-// System.out.println(job.getName() + ": " + getStateName(state));
- if (state == Job.RUNNING || state == Job.WAITING) {
-// System.out.println();
+ if (state == Job.RUNNING || state == Job.WAITING)
return false;
- }
}
-// System.out.println();
return true;
}
-
-// private static String getStateName(int state) {
-// switch (state) {
-// case Job.RUNNING: return "RUNNING";
-// case Job.WAITING: return "WAITING";
-// case Job.SLEEPING: return "SLEEPING";
-// case Job.NONE: return "NONE";
-// default: return "unknown " + state;
-// }
-// }
-
+
+ public static boolean isViewShown(String viewId) {
+ return getActivePage().findViewReference(viewId) != null;
+ }
+
+ public static boolean showView(String viewId, boolean show) throws PartInitException {
+ IWorkbenchPage activePage= getActivePage();
+ IViewReference view= activePage.findViewReference(viewId);
+ boolean shown= view != null;
+ if (shown != show)
+ if (show)
+ activePage.showView(viewId);
+ else
+ activePage.hideView(view);
+ return shown;
+ }
+
public static boolean showView(String viewId) throws PartInitException {
IWorkbenchPage activePage= getActivePage();
IViewReference view= activePage.findViewReference(viewId);
@@ -231,7 +305,7 @@
activePage.showView(viewId);
return notShown;
}
-
+
public static boolean hideView(String viewId) {
IWorkbenchPage activePage= getActivePage();
IViewReference view= activePage.findViewReference(viewId);
@@ -240,7 +314,7 @@
activePage.hideView(view);
return shown;
}
-
+
public static void bringToTop() {
getActiveWorkbenchWindow().getShell().forceActive();
}
@@ -254,8 +328,10 @@
if (minTime > 0)
runEventQueue(minTime);
- long endTime= maxTime > 0 ? System.currentTimeMillis() + maxTime : Long.MAX_VALUE;
+ long endTime= maxTime > 0 && maxTime < Long.MAX_VALUE ? System.currentTimeMillis() + maxTime : Long.MAX_VALUE;
AbstractReconciler reconciler= getReconciler(sourceViewer);
+ if (reconciler == null)
+ return true;
Accessor backgroundThreadAccessor= getBackgroundThreadAccessor(reconciler);
Accessor javaReconcilerAccessor= null;
if (reconciler instanceof JavaReconciler)
@@ -267,34 +343,145 @@
}
return !isRunning;
}
-
+
public static AbstractReconciler getReconciler(SourceViewer sourceViewer) {
return (AbstractReconciler) new Accessor(sourceViewer, SourceViewer.class).get("fReconciler");
}
-
+
public static SourceViewer getSourceViewer(AbstractTextEditor editor) {
SourceViewer sourceViewer= (SourceViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
return sourceViewer;
}
-
+
private static Accessor getBackgroundThreadAccessor(AbstractReconciler reconciler) {
Object backgroundThread= new Accessor(reconciler, AbstractReconciler.class).get("fThread");
return new Accessor(backgroundThread, backgroundThread.getClass());
}
-
+
private static boolean isRunning(Accessor javaReconcilerAccessor, Accessor backgroundThreadAccessor) {
return (javaReconcilerAccessor != null ? !isInitialProcessDone(javaReconcilerAccessor) : false) || isDirty(backgroundThreadAccessor) || isActive(backgroundThreadAccessor);
}
-
+
private static boolean isInitialProcessDone(Accessor javaReconcilerAccessor) {
return ((Boolean) javaReconcilerAccessor.get("fIninitalProcessDone")).booleanValue();
}
-
+
private static boolean isDirty(Accessor backgroundThreadAccessor) {
return ((Boolean) backgroundThreadAccessor.invoke("isDirty", new Object[0])).booleanValue();
}
-
+
private static boolean isActive(Accessor backgroundThreadAccessor) {
return ((Boolean) backgroundThreadAccessor.invoke("isActive", new Object[0])).booleanValue();
}
+
+ public static String showPerspective(String perspective) throws WorkbenchException {
+ String shownPerspective= getActivePage().getPerspective().getId();
+ if (!perspective.equals(shownPerspective)) {
+ IWorkbench workbench= PlatformUI.getWorkbench();
+ IWorkbenchWindow activeWindow= workbench.getActiveWorkbenchWindow();
+ workbench.showPerspective(perspective, activeWindow);
+ }
+ return shownPerspective;
+ }
+
+ public static void closeAllPopUps(SourceViewer sourceViewer) {
+ IWidgetTokenKeeper tokenKeeper= new IWidgetTokenKeeper() {
+ public boolean requestWidgetToken(IWidgetTokenOwner owner) {
+ return true;
+ }
+ };
+ sourceViewer.requestWidgetToken(tokenKeeper, Integer.MAX_VALUE);
+ sourceViewer.releaseWidgetToken(tokenKeeper);
+ }
+
+ public static void resetFolding() {
+ JavaPlugin.getDefault().getPreferenceStore().setToDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED);
+ }
+
+ public static boolean enableFolding(boolean value) {
+ IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
+ boolean oldValue= preferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
+ if (value != oldValue)
+ preferenceStore.setValue(PreferenceConstants.EDITOR_FOLDING_ENABLED, value);
+ return oldValue;
+ }
+
+ public static IJavaProject createJavaProject(String project, String externalSourceFolder) throws CoreException, JavaModelException {
+ return createJavaProject(project, externalSourceFolder, false);
+ }
+
+ public static IJavaProject createJavaProject(String project, String externalSourceFolder, boolean linkSourceFolder) throws CoreException, JavaModelException {
+ IJavaProject javaProject= JavaProjectHelper.createJavaProject(project, "bin");
+ Assert.assertNotNull("JRE is null", JavaProjectHelper.addRTJar(javaProject));
+ IFolder folder;
+ if (linkSourceFolder)
+ folder= ResourceHelper.createLinkedFolder((IProject) javaProject.getUnderlyingResource(), new Path("src"), JdtTextTestPlugin.getDefault(), new Path(externalSourceFolder));
+ else {
+ folder= ((IProject) javaProject.getUnderlyingResource()).getFolder("src");
+ importFilesFromDirectory(FileTool.getFileInPlugin(JdtTextTestPlugin.getDefault(), new Path(externalSourceFolder)), folder.getFullPath(), null);
+ }
+ Assert.assertNotNull(folder);
+ Assert.assertTrue(folder.exists());
+ JavaProjectHelper.addSourceContainer(javaProject, "src");
+ return javaProject;
+ }
+
+ public static IFile[] findFiles(IResource resource) throws CoreException {
+ List files= new ArrayList();
+ findFiles(resource, files);
+ return (IFile[]) files.toArray(new IFile[files.size()]);
+ }
+
+ private static void findFiles(IResource resource, List files) throws CoreException {
+ if (resource instanceof IFile) {
+ files.add(resource);
+ return;
+ }
+ if (resource instanceof IContainer) {
+ IResource[] resources= ((IContainer) resource).members();
+ for (int i= 0; i < resources.length; i++)
+ findFiles(resources[i], files);
+ }
+ }
+
+ public static boolean setDialogEnabled(String id, boolean enabled) {
+ boolean wasEnabled= OptionalMessageDialog.isDialogEnabled(id);
+ if (wasEnabled != enabled)
+ OptionalMessageDialog.setDialogEnabled(id, enabled);
+ return wasEnabled;
+ }
+
+ public static void importFilesFromDirectory(File rootDir, IPath destPath, IProgressMonitor monitor) throws CoreException {
+ try {
+ IImportStructureProvider structureProvider = FileSystemStructureProvider.INSTANCE;
+ List files = new ArrayList(100);
+ addJavaFiles(rootDir, files);
+ ImportOperation op= new ImportOperation(destPath, rootDir, structureProvider, new ImportOverwriteQuery(), files);
+ op.setCreateContainerStructure(false);
+ op.run(monitor);
+ } catch (Exception x) {
+ throw newCoreException(x);
+ }
+ }
+
+ private static CoreException newCoreException(Throwable x) {
+ return new CoreException(new Status(IStatus.ERROR, JdtTextTestPlugin.PLUGIN_ID, -1, "", x));
+ }
+
+ private static void addJavaFiles(File dir, List collection) throws IOException {
+ File[] files = dir.listFiles();
+ List subDirs = new ArrayList(2);
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isFile()) {
+ collection.add(files[i]);
+ } else if (files[i].isDirectory()) {
+ subDirs.add(files[i]);
+ }
+ }
+ Iterator iter = subDirs.iterator();
+ while (iter.hasNext()) {
+ File subDir = (File)iter.next();
+ addJavaFiles(subDir, collection);
+ }
+ }
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EventDrivenTestSuite.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EventDrivenTestSuite.java
index aa91811..14417e7 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EventDrivenTestSuite.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/EventDrivenTestSuite.java
@@ -24,7 +24,7 @@
public class EventDrivenTestSuite extends TestSuite {
public static Test suite() {
- return new CloseWorkbenchDecorator(new PerformanceTestSetup(new EventDrivenTestSuite()));
+ return new PerformanceTestSetup(new EventDrivenTestSuite());
}
public EventDrivenTestSuite() {
@@ -35,6 +35,10 @@
addTest(TextNonInitialTypingTest.suite());
addTest(OpenPreferencePageTest.suite());
addTest(ScrollAnnotatedJavaEditorTest.suite());
+ addTest(JavaDocIndentStrategyTest.suite());
+ addTest(TextMoveLineTest.suite());
+ addTest(JavaMoveLineTest.suite());
+ addTest(JavaReplaceAllTest.suite());
// TODO: enable when Bug 72244: "Posting mouse events locks up event handling" is fixed
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=72244
// addTest(MouseScrollJavaEditorTest.suite());
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaIndenterTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaIndenterTest.java
index b0aab44..272c3aa 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaIndenterTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaIndenterTest.java
@@ -17,7 +17,6 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
import org.eclipse.jface.action.IAction;
@@ -41,8 +40,6 @@
private static final int[] CTRL_END= new int[] { SWT.CTRL, SWT.END };
- private PerformanceMeter fPerformanceMeter;
-
private ITextEditor fEditor;
public static Test suite() {
@@ -50,9 +47,8 @@
}
protected void setUp() throws Exception {
+ super.setUp();
EditorTestHelper.runEventQueue();
- Performance performance= Performance.getDefault();
- fPerformanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
EditorTestHelper.bringToTop();
fEditor= (ITextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(FILE), true);
@@ -66,37 +62,31 @@
}
protected void tearDown() throws Exception {
+ super.tearDown();
EditorTestHelper.closeAllEditors();
- fPerformanceMeter.dispose();
}
public void testJavaIndenter2() {
- // cold run
- measureJavaIndenter(getWarmUpRuns(), false);
- // warm run
- measureJavaIndenter(getMeasuredRuns(), true);
+ measureJavaIndenter(getNullPerformanceMeter(), getWarmUpRuns());
+ measureJavaIndenter(createPerformanceMeter(), getMeasuredRuns());
+ commitAllMeasurements();
+ assertAllPerformance();
}
- private void measureJavaIndenter(int runs, boolean measure) {
+ private void measureJavaIndenter(PerformanceMeter performanceMeter, int runs) {
IDocument document= ((JavaEditor) fEditor).getViewer().getDocument();
Display display= EditorTestHelper.getActiveDisplay();
IAction undo= fEditor.getAction(ITextEditorActionConstants.UNDO);
int originalNumberOfLines= document.getNumberOfLines();
for (int i= 0; i < runs; i++) {
- if (measure)
- fPerformanceMeter.start();
+ performanceMeter.start();
SWTEventHelper.pressKeyCode(display, SWT.CR);
- if (measure)
- fPerformanceMeter.stop();
+ performanceMeter.stop();
assertEquals(originalNumberOfLines + 1, document.getNumberOfLines());
runAction(undo);
assertEquals(originalNumberOfLines, document.getNumberOfLines());
sleep(2000); // NOTE: runnables posted from other threads, while the main thread waits here, are executed and measured only in the next iteration
}
- if (measure) {
- fPerformanceMeter.commit();
- Performance.getDefault().assertPerformance(fPerformanceMeter);
- }
}
private void runAction(IAction action) {
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/KeyboardProbe.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/KeyboardProbe.java
index d150ca2..d741880 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/KeyboardProbe.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/KeyboardProbe.java
@@ -52,6 +52,14 @@
* index into the array.
*/
public synchronized char[][] getKeycodes() {
+ initialize();
+ return fCodes;
+ }
+
+ /**
+ * Initializes this keyboard probe.
+ */
+ public void initialize() {
if (fCodes == null) {
try {
probe();
@@ -67,9 +75,8 @@
fShell= null;
}
}
- return fCodes;
}
-
+
/**
* Returns the character resulting from pressing the character 'key' with
* or without shift being pressed.
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MouseScrollEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MouseScrollEditorTest.java
index 895118d..17106b2 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MouseScrollEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MouseScrollEditorTest.java
@@ -131,12 +131,14 @@
};
protected void setUp() throws Exception {
+ super.setUp();
Performance performance= Performance.getDefault();
fPerformanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
EditorTestHelper.bringToTop();
}
protected void tearDown() throws Exception {
+ super.tearDown();
fPerformanceMeter.dispose();
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java
index d13b5d7..be45707 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java
@@ -25,12 +25,14 @@
import org.eclipse.ui.texteditor.ITextEditor;
/**
- * Measures the time to type in one single method into a large file. Abstract implementation.
+ * Measures the time to type in one single method into a large file. Abstract
+ * implementation.
+ *
* @since 3.1
*/
public abstract class NonInitialTypingTest extends TextPerformanceTestCase {
- private static final String FILE= "org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
+ private static final String FILE= PerformanceTestSetup.STYLED_TEXT;
private static final char[] METHOD= ("public int foobar(int iParam, Object oParam) {\r" +
"return 42;\r" +
@@ -44,13 +46,11 @@
protected PerformanceMeter fMeter;
- private KeyboardProbe fKeyboardProbe;
-
protected void setUp() throws Exception {
+ super.setUp();
EditorTestHelper.runEventQueue();
fEditor= (ITextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(FILE), getEditorId(), true);
// dirty editor to avoid initial dirtying / validate edit costs
- fKeyboardProbe= new KeyboardProbe();
dirtyEditor();
Performance performance= Performance.getDefault();
fMeter= performance.createPerformanceMeter(getScenarioId());
@@ -77,19 +77,25 @@
sleep(1000);
Display display= EditorTestHelper.getActiveDisplay();
- fKeyboardProbe.pressChar('{', display);
+ getKeyboardProbe().pressChar('{', display);
EditorTestHelper.runEventQueue();
SWTEventHelper.pressKeyCode(display, SWT.BS);
sleep(1000);
}
protected void tearDown() throws Exception {
+ super.tearDown();
sleep(1000);
fMeter.dispose();
EditorTestHelper.revertEditor(fEditor, true);
EditorTestHelper.closeAllEditors();
}
+ /**
+ * Measures the time to type in one single method into a large file.
+ *
+ * @throws BadLocationException
+ */
public void testTypeAMethod() throws BadLocationException {
Display display= EditorTestHelper.getActiveDisplay();
int offset= getInsertPosition();
@@ -100,10 +106,11 @@
fEditor.getSelectionProvider().setSelection(new TextSelection(offset, 0));
EditorTestHelper.runEventQueue(1000);
+ KeyboardProbe keyboardProbe= getKeyboardProbe();
if (i >= warmUpRuns)
fMeter.start();
for (int j= 0; j < METHOD.length; j++) {
- fKeyboardProbe.pressChar(METHOD[j], display);
+ keyboardProbe.pressChar(METHOD[j], display);
EditorTestHelper.runEventQueue();
}
if (i >= warmUpRuns)
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenEditorTest.java
index a1e4980..40d6eb4 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenEditorTest.java
@@ -11,15 +11,24 @@
package org.eclipse.jdt.text.tests.performance;
+import java.util.Arrays;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
public abstract class OpenEditorTest extends TextPerformanceTestCase {
+ private static final Class THIS= OpenEditorTest.class;
+
public OpenEditorTest() {
super();
}
@@ -28,25 +37,36 @@
super(name);
}
- protected void measureOpenInEditor(IFile[] files, PerformanceMeter performanceMeter, boolean closeAll) throws PartInitException {
- try {
- for (int i= 0, n= files.length; i < n; i++) {
- if (performanceMeter != null)
- performanceMeter.start();
- EditorTestHelper.openInEditor(files[i], true);
- if (performanceMeter != null)
- performanceMeter.stop();
- EditorTestHelper.runEventQueue(2000);
+ public static Test suite() {
+ TestSuite suite= new TestSuite(THIS.getName());
+ suite.addTest(OpenJavaEditorTest.suite());
+ suite.addTest(OpenTextEditorTest.suite());
+ return suite;
+ }
+
+ protected void measureOpenInEditor(IFile[] files, PerformanceMeter performanceMeter, boolean closeEach) throws PartInitException {
+ for (int i= 0, n= files.length; i < n; i++) {
+ performanceMeter.start();
+ AbstractTextEditor editor= (AbstractTextEditor) EditorTestHelper.openInEditor(files[i], true);
+ performanceMeter.stop();
+ EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 10000, 100);
+ if (closeEach) {
+ EditorTestHelper.closeEditor(editor);
+ EditorTestHelper.runEventQueue(100);
}
- if (performanceMeter != null) {
- performanceMeter.commit();
- Performance.getDefault().assertPerformance(performanceMeter);
- }
- } finally {
- if (performanceMeter != null)
- performanceMeter.dispose();
- if (closeAll)
- EditorTestHelper.closeAllEditors();
}
+ performanceMeter.commit();
+ assertPerformance(performanceMeter);
+ }
+
+ protected void measureOpenInEditor(String file, PerformanceMeter performanceMeter) throws PartInitException {
+ measureOpenInEditor(arrayOf(file, getWarmUpRuns()), Performance.getDefault().getNullPerformanceMeter(), true);
+ measureOpenInEditor(arrayOf(file, getMeasuredRuns()), performanceMeter, true);
+ }
+
+ private IFile[] arrayOf(String file, int n) {
+ IFile[] files= new IFile[n];
+ Arrays.fill(files, ResourceTestHelper.findFile(file));
+ return files;
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTest.java
index 857e0e3..15b780a 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTest.java
@@ -11,44 +11,74 @@
package org.eclipse.jdt.text.tests.performance;
+
+import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile;
+
+import org.eclipse.ui.PartInitException;
+
+
+
+
+
+
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
-import org.eclipse.ui.PartInitException;
-
/**
- * Opens 20 instances of org.eclipse.swt.graphics.TextLayout leaving
- * each of them open and then closes all together them (close all).
- * Then repeats above scenario.
- * <p>
- * This tests a mid-size file.
- * </p>
- *
* @since 3.1
*/
public class OpenJavaEditorTest extends OpenEditorTest {
+ public static class Setup extends TestSetup {
+
+ private boolean fTearDown;
+
+ public Setup(Test test) {
+ this(test, true);
+ }
+
+ public Setup(Test test, boolean tearDown) {
+ super(test);
+ fTearDown= tearDown;
+ }
+
+ protected void setUp() throws Exception {
+ ResourceTestHelper.replicate(PREFIX + FILE_SUFFIX, PREFIX, FILE_SUFFIX, WARM_UP_RUNS + MEASURED_RUNS, FILE_PREFIX, FILE_PREFIX, ResourceTestHelper.SKIP_IF_EXISTS);
+ }
+
+ protected void tearDown() throws Exception {
+ if (fTearDown)
+ ResourceTestHelper.delete(PREFIX, FILE_SUFFIX, WARM_UP_RUNS + MEASURED_RUNS);
+ }
+ }
+
private static final Class THIS= OpenJavaEditorTest.class;
private static final String SHORT_NAME_FIRST_RUN= "Open Java editor (first in session)";
private static final String SHORT_NAME_WARM_RUN= "Open Java editor (reopen)";
- public static final int WARM_UP_RUNS= 10;
+ private static final String SHORT_NAME_WARM_RUN_FIRST= "Open Java editor (reopen first)";
- public static final int MEASURED_RUNS= 5;
+ private static final int WARM_UP_RUNS= 10;
- public static final String PATH= "/Eclipse SWT/win32/org/eclipse/swt/graphics/";
+ private static final int MEASURED_RUNS= 5;
- public static final String FILE_PREFIX= "TextLayout";
+ private static final String PATH= "/Eclipse SWT/win32/org/eclipse/swt/graphics/";
- public static final String FILE_SUFFIX= ".java";
+ private static final String FILE_PREFIX= "TextLayout";
+
+ private static final String PREFIX= "/" + PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX;
+
+ private static final String FILE_SUFFIX= ".java";
+
+ private static final String LARGE_FILE= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
public OpenJavaEditorTest() {
super();
@@ -64,34 +94,77 @@
suite.addTest(new OpenJavaEditorTest("testOpenFirstEditor"));
suite.addTest(new OpenJavaEditorTest("testOpenJavaEditor1"));
suite.addTest(new OpenJavaEditorTest("testOpenJavaEditor2"));
- return new CloseWorkbenchDecorator(new PerformanceTestSetup(new OpenJavaEditorTestSetup(suite)));
+ suite.addTest(new OpenJavaEditorTest("testOpenEditor3"));
+ suite.addTest(new OpenJavaEditorTest("testOpenEditor4"));
+ suite.addTest(new OpenJavaEditorTest("testOpenEditor5"));
+ suite.addTest(new OpenJavaEditorTest("testOpenEditor6"));
+ return new PerformanceTestSetup(new Setup(suite));
}
- protected void setUp() {
+ /*
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
EditorTestHelper.runEventQueue();
setWarmUpRuns(WARM_UP_RUNS);
setMeasuredRuns(MEASURED_RUNS);
}
+
+ /*
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ EditorTestHelper.closeAllEditors();
+ }
- public void testOpenFirstEditor() throws PartInitException {
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- performance.tagAsSummary(performanceMeter, SHORT_NAME_FIRST_RUN, Dimension.ELAPSED_PROCESS);
- measureOpenInEditor(new IFile[] { ResourceTestHelper.findFile(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX + FILE_SUFFIX) }, performanceMeter, true);
+ public void testOpenFirstEditor() throws Exception {
+ PerformanceMeter performanceMeter= createPerformanceMeterForSummary(SHORT_NAME_FIRST_RUN, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(new IFile[] { ResourceTestHelper.findFile(PREFIX + FILE_SUFFIX) }, performanceMeter, false);
}
- public void testOpenJavaEditor1() throws PartInitException {
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), null, false);
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, true);
+ public void testOpenJavaEditor1() throws Exception {
+ measureOpenInEditor(ResourceTestHelper.findFiles(PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), Performance.getDefault().getNullPerformanceMeter(), false);
+ measureOpenInEditor(ResourceTestHelper.findFiles(PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), createPerformanceMeter(), false);
}
- public void testOpenJavaEditor2() throws PartInitException {
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), null, false);
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- performance.tagAsGlobalSummary(performanceMeter, SHORT_NAME_WARM_RUN, Dimension.ELAPSED_PROCESS);
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, true);
+ public void testOpenJavaEditor2() throws Exception {
+ measureOpenInEditor(ResourceTestHelper.findFiles(PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), Performance.getDefault().getNullPerformanceMeter(), false);
+ PerformanceMeter performanceMeter= createPerformanceMeterForGlobalSummary(SHORT_NAME_WARM_RUN, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(ResourceTestHelper.findFiles(PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, false);
+ }
+
+ public void testOpenEditor3() throws Exception {
+ PerformanceMeter performanceMeter= createPerformanceMeterForSummary(SHORT_NAME_WARM_RUN_FIRST, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(LARGE_FILE, true, true, performanceMeter);
+ }
+
+ public void testOpenEditor4() throws Exception {
+ measureOpenInEditor(LARGE_FILE, false, true, createPerformanceMeter());
+ }
+
+ public void testOpenEditor5() throws Exception {
+ measureOpenInEditor(LARGE_FILE, true, false, createPerformanceMeter());
+ }
+
+ public void testOpenEditor6() throws Exception {
+ measureOpenInEditor(LARGE_FILE, false, false, createPerformanceMeter());
+ }
+
+ protected void measureOpenInEditor(String file, boolean enableFolding, boolean showOutline, PerformanceMeter performanceMeter) throws PartInitException {
+ boolean shown= EditorTestHelper.isViewShown(EditorTestHelper.OUTLINE_VIEW_ID);
+ try {
+ EditorTestHelper.enableFolding(enableFolding);
+ showOutline(showOutline);
+ measureOpenInEditor(file, performanceMeter);
+ } finally {
+ EditorTestHelper.resetFolding();
+ showOutline(shown);
+ }
+ }
+
+ private boolean showOutline(boolean show) throws PartInitException {
+ return EditorTestHelper.showView(EditorTestHelper.OUTLINE_VIEW_ID, show);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTestSetup.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTestSetup.java
deleted file mode 100644
index ae8ae9e..0000000
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenJavaEditorTestSetup.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.jdt.text.tests.performance;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
-public class OpenJavaEditorTestSetup extends TestSetup {
-
- public OpenJavaEditorTestSetup(Test test) {
- super(test);
- }
-
- protected void setUp() throws Exception {
- String src= "/" + PerformanceTestSetup.PROJECT + OpenJavaEditorTest.PATH + OpenJavaEditorTest.FILE_PREFIX + OpenJavaEditorTest.FILE_SUFFIX;
- String destPrefix= "/" + PerformanceTestSetup.PROJECT + OpenJavaEditorTest.PATH + OpenJavaEditorTest.FILE_PREFIX;
- String destSuffix= OpenJavaEditorTest.FILE_SUFFIX;
- String name= OpenJavaEditorTest.FILE_PREFIX;
- ResourceTestHelper.replicate(src, destPrefix, destSuffix, OpenJavaEditorTest.WARM_UP_RUNS + OpenJavaEditorTest.MEASURED_RUNS, name, name, ResourceTestHelper.SKIP_IF_EXISTS);
- }
-
- protected void tearDown() throws Exception {
- // do nothing, the actual test runs in its own workbench
- }
-}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenQuickOutlineTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenQuickOutlineTest.java
index 90151a9..ae04e0f 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenQuickOutlineTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenQuickOutlineTest.java
@@ -11,44 +11,26 @@
package org.eclipse.jdt.text.tests.performance;
-import java.io.IOException;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.runtime.CoreException;
-
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.test.performance.Performance;
+import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.PerformanceMeter;
import org.eclipse.jface.action.IAction;
-import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds;
-public class OpenQuickOutlineTest extends TextPerformanceTestCase {
+public class OpenQuickOutlineTest extends OpenQuickControlTest {
private static final Class THIS= OpenQuickOutlineTest.class;
- private static final String PATH= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/";
+ private static final String SHORT_NAME_COLD= "Open Quick Outline (first time)";
- private static final String ORIG_NAME= "StyledText";
-
- private static final String ORIG_FILE= PATH + ORIG_NAME + ".java";
-
- private static final int WARM_UP_RUNS= 10;
-
- private static final int MEASURED_RUNS= 10;
-
- private PerformanceMeter fFirstMeter;
-
- private PerformanceMeter fSecondMeter;
-
- private static final String OUTLINE_VIEW= "org.eclipse.ui.views.ContentOutline";
-
private boolean fWasOutlineViewShown;
public static Test suite() {
@@ -56,55 +38,22 @@
}
protected void setUp() throws Exception {
- setWarmUpRuns(WARM_UP_RUNS);
- setMeasuredRuns(MEASURED_RUNS);
- Performance performance= Performance.getDefault();
- fFirstMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this, "cold"));
- fSecondMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this, "warm"));
- fWasOutlineViewShown= EditorTestHelper.hideView(OUTLINE_VIEW); // TODO: find solution to hide view in other perspectives too
- ResourceTestHelper.replicate(ORIG_FILE, PATH + ORIG_NAME, ".java", getWarmUpRuns() + getMeasuredRuns(), ORIG_NAME, ORIG_NAME, ResourceTestHelper.FAIL_IF_EXISTS);
- ResourceTestHelper.incrementalBuild();
- EditorTestHelper.bringToTop();
- EditorTestHelper.joinJobs(1000, 10000, 100);
+ super.setUp();
+ fWasOutlineViewShown= EditorTestHelper.hideView(EditorTestHelper.OUTLINE_VIEW_ID);
}
protected void tearDown() throws Exception {
- for (int i= 0, n= getWarmUpRuns() + getMeasuredRuns(); i < n; i++)
- ResourceTestHelper.delete(PATH + ORIG_NAME + i + ".java");
+ super.tearDown();
if (fWasOutlineViewShown)
- EditorTestHelper.showView(OUTLINE_VIEW);
- fFirstMeter.dispose();
- fSecondMeter.dispose();
+ EditorTestHelper.showView(EditorTestHelper.OUTLINE_VIEW_ID);
}
- public void testOpenQuickOutline1() throws IOException, CoreException {
- int warmUpRuns= getWarmUpRuns();
- int measuredRuns= getMeasuredRuns();
- for (int i= 0; i < warmUpRuns + measuredRuns; i++) {
- String name= ORIG_NAME + i;
- String file= PATH + name + ".java";
- ITextEditor editor= (ITextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
- EditorTestHelper.joinJobs(5000, 10000, 100);
-
- measureOpenQuickOutline(editor, i < warmUpRuns ? null : fFirstMeter);
- measureOpenQuickOutline(editor, i < warmUpRuns ? null : fSecondMeter);
-
- EditorTestHelper.closeAllEditors();
- }
- fFirstMeter.commit();
- fSecondMeter.commit();
- Performance.getDefault().assertPerformance(fFirstMeter);
- Performance.getDefault().assertPerformance(fSecondMeter);
+ protected IAction setUpMeasurement(AbstractTextEditor editor) throws Exception {
+ EditorTestHelper.runEventQueue(100);
+ return editor.getAction(IJavaEditorActionDefinitionIds.SHOW_OUTLINE);
}
- private void measureOpenQuickOutline(ITextEditor editor, PerformanceMeter performanceMeter) {
- IAction showOutline= editor.getAction(IJavaEditorActionDefinitionIds.SHOW_OUTLINE);
- EditorTestHelper.joinJobs(500, 1000, 100);
- if (performanceMeter != null)
- performanceMeter.start();
- runAction(showOutline);
- if (performanceMeter != null)
- performanceMeter.stop();
+ protected void tearDownMeasurement(AbstractTextEditor editor) throws Exception {
Shell shell= EditorTestHelper.getActiveDisplay().getActiveShell();
assertEquals("", shell.getText());
shell.dispose();
@@ -112,8 +61,9 @@
assertFalse("".equals(shell.getText()));
}
- private void runAction(IAction action) {
- action.run();
- EditorTestHelper.runEventQueue();
+ public void testOpenQuickOutline1() throws Exception {
+ PerformanceMeter coldMeter= createPerformanceMeterForSummary("-cold", SHORT_NAME_COLD, Dimension.ELAPSED_PROCESS);
+ PerformanceMeter warmMeter= createPerformanceMeter("-warm");
+ measureOpenQuickControl(coldMeter, warmMeter);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTest.java
index a7c2bda..127fb1d 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTest.java
@@ -11,14 +11,13 @@
package org.eclipse.jdt.text.tests.performance;
+import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
-import org.eclipse.ui.PartInitException;
-
/**
* Opens 20 instances of org.eclipse.swt.graphics.TextLayout leaving
* each of them open and then closes all together them (close all).
@@ -31,23 +30,61 @@
*/
public class OpenTextEditorTest extends OpenEditorTest {
+ public static class Setup extends TestSetup {
+
+ private boolean fTearDown;
+
+ public Setup(Test test) {
+ this(test, true);
+ }
+
+ public Setup(Test test, boolean tearDown) {
+ super(test);
+ fTearDown= tearDown;
+ }
+
+ protected void setUp() throws Exception {
+ ResourceTestHelper.replicate("/" + PerformanceTestSetup.PROJECT + ORIG_FILE, PREFIX, FILE_SUFFIX, WARM_UP_RUNS + MEASURED_RUNS, ResourceTestHelper.SKIP_IF_EXISTS);
+ ResourceTestHelper.copy(ORIG_LARGE_FILE, LARGE_FILE, ResourceTestHelper.SKIP_IF_EXISTS);
+ EditorTestHelper.showPerspective(EditorTestHelper.RESOURCE_PERSPECTIVE_ID);
+ }
+
+ protected void tearDown() throws Exception {
+ if (fTearDown) {
+ EditorTestHelper.showPerspective(EditorTestHelper.JAVA_PERSPECTIVE_ID);
+ ResourceTestHelper.delete(PREFIX, FILE_SUFFIX, WARM_UP_RUNS + MEASURED_RUNS);
+ ResourceTestHelper.delete(LARGE_FILE);
+ }
+ }
+ }
+
private static final Class THIS= OpenTextEditorTest.class;
private static final String SHORT_NAME_FIRST_RUN= "Open text editor (first in session)";
private static final String SHORT_NAME_WARM_RUN= "Open text editor (reopen)";
- public static final int WARM_UP_RUNS= 10;
+ private static final String SHORT_NAME_WARM_RUN_FIRST= "Open text editor (reopen first)";
+
+ private static final int WARM_UP_RUNS= 10;
- public static final int MEASURED_RUNS= 5;
+ private static final int MEASURED_RUNS= 5;
- public static final String PATH= "/Eclipse SWT/win32/org/eclipse/swt/graphics/";
+ private static final String PATH= "/Eclipse SWT/win32/org/eclipse/swt/graphics/";
- public static final String FILE_PREFIX= "TextLayout";
+ private static final String FILE_PREFIX= "TextLayout";
- public static final String FILE_SUFFIX= ".txt";
+ private static final String FILE_SUFFIX= ".txt";
- public static final String ORIG_FILE= PATH + FILE_PREFIX + ".java";
+ private static final String ORIG_FILE= PATH + FILE_PREFIX + ".java";
+
+ private static final String PREFIX= "/" + PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX;
+
+ private static final String LARGE_FILE_PREFIX= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText";
+
+ private static final String ORIG_LARGE_FILE= LARGE_FILE_PREFIX + ".java";
+
+ private static final String LARGE_FILE= LARGE_FILE_PREFIX + ".txt";
public OpenTextEditorTest() {
super();
@@ -63,34 +100,46 @@
suite.addTest(new OpenTextEditorTest("testOpenFirstEditor"));
suite.addTest(new OpenTextEditorTest("testOpenTextEditor1"));
suite.addTest(new OpenTextEditorTest("testOpenTextEditor2"));
- return new CloseWorkbenchDecorator(new PerformanceTestSetup(new OpenTextEditorTestSetup(suite)));
+ suite.addTest(new OpenTextEditorTest("testOpenEditor3"));
+ return new PerformanceTestSetup(new Setup(suite), false);
}
- protected void setUp() {
+ /*
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
EditorTestHelper.runEventQueue();
setWarmUpRuns(WARM_UP_RUNS);
setMeasuredRuns(MEASURED_RUNS);
}
-
- public void testOpenFirstEditor() throws PartInitException {
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- performance.tagAsSummary(performanceMeter, SHORT_NAME_FIRST_RUN, Dimension.ELAPSED_PROCESS);
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, 1), performanceMeter, true);
+
+ /*
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ EditorTestHelper.closeAllEditors();
}
- public void testOpenTextEditor1() throws PartInitException {
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), null, false);
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, true);
+ public void testOpenFirstEditor() throws Exception {
+ PerformanceMeter performanceMeter= createPerformanceMeterForSummary(SHORT_NAME_FIRST_RUN, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, 1), performanceMeter, false);
}
- public void testOpenTextEditor2() throws PartInitException {
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), null, false);
- Performance performance= Performance.getDefault();
- PerformanceMeter performanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
- performance.tagAsGlobalSummary(performanceMeter, SHORT_NAME_WARM_RUN, Dimension.ELAPSED_PROCESS);
- measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, true);
+ public void testOpenTextEditor1() throws Exception {
+ measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), Performance.getDefault().getNullPerformanceMeter(), false);
+ measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), createPerformanceMeter(), false);
+ }
+
+ public void testOpenTextEditor2() throws Exception {
+ measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, 0, getWarmUpRuns()), Performance.getDefault().getNullPerformanceMeter(), false);
+ PerformanceMeter performanceMeter= createPerformanceMeterForGlobalSummary(SHORT_NAME_WARM_RUN, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(ResourceTestHelper.findFiles(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX, FILE_SUFFIX, getWarmUpRuns(), getMeasuredRuns()), performanceMeter, false);
+ }
+
+ public void testOpenEditor3() throws Exception {
+ PerformanceMeter performanceMeter= createPerformanceMeterForSummary(SHORT_NAME_WARM_RUN_FIRST, Dimension.ELAPSED_PROCESS);
+ measureOpenInEditor(LARGE_FILE, performanceMeter);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTestSetup.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTestSetup.java
deleted file mode 100644
index 3bbd22c..0000000
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/OpenTextEditorTestSetup.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.jdt.text.tests.performance;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
-public class OpenTextEditorTestSetup extends TestSetup {
-
- public OpenTextEditorTestSetup(Test test) {
- super(test);
- }
-
- protected void setUp() throws Exception {
- ResourceTestHelper.replicate("/" + PerformanceTestSetup.PROJECT + OpenTextEditorTest.ORIG_FILE, "/" + PerformanceTestSetup.PROJECT + OpenTextEditorTest.PATH + OpenTextEditorTest.FILE_PREFIX, OpenTextEditorTest.FILE_SUFFIX, OpenTextEditorTest.WARM_UP_RUNS + OpenTextEditorTest.MEASURED_RUNS, ResourceTestHelper.SKIP_IF_EXISTS);
- }
-
- protected void tearDown() {
- // do nothing, the actual test runs in its own workbench
- }
-}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSetup.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSetup.java
index 93348bf..f59aceb 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSetup.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSetup.java
@@ -11,20 +11,14 @@
package org.eclipse.jdt.text.tests.performance;
-import java.io.File;
import java.io.IOException;
import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
import junit.extensions.TestSetup;
import junit.framework.Test;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbench;
@@ -38,16 +32,23 @@
public class PerformanceTestSetup extends TestSetup {
- private static final String PERSPECTIVE= "org.eclipse.jdt.ui.JavaPerspective";
-
public static final String PROJECT= "org.eclipse.swt";
+ public static final String TEXT_LAYOUT= "/" + PerformanceTestSetup.PROJECT + "/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java";
+
+ public static final String STYLED_TEXT= "/" + PerformanceTestSetup.PROJECT + "/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
+
private static final String PROJECT_ZIP= "/testResources/org.eclipse.swt-R3_0.zip";
- private static final String INTRO_VIEW= "org.eclipse.ui.internal.introview";
+ private boolean fSetPerspective;
public PerformanceTestSetup(Test test) {
+ this(test, true);
+ }
+
+ public PerformanceTestSetup(Test test, boolean setPerspective) {
super(test);
+ fSetPerspective= setPerspective;
}
/*
@@ -58,20 +59,21 @@
IWorkbenchWindow activeWindow= workbench.getActiveWorkbenchWindow();
IWorkbenchPage activePage= activeWindow.getActivePage();
- IViewReference viewReference= activePage.findViewReference(INTRO_VIEW);
+ IViewReference viewReference= activePage.findViewReference(EditorTestHelper.INTRO_VIEW_ID);
if (viewReference != null)
activePage.hideView(viewReference);
- workbench.showPerspective(PERSPECTIVE, activeWindow);
+ if (fSetPerspective)
+ EditorTestHelper.showPerspective(EditorTestHelper.JAVA_PERSPECTIVE_ID);
- if (!projectExists(PROJECT)) {
+ if (!ResourceTestHelper.projectExists(PROJECT)) {
boolean wasAutobuilding= ResourceTestHelper.disableAutoBuilding();
setUpProject();
ResourceTestHelper.fullBuild();
- if (wasAutobuilding) {
+ if (wasAutobuilding)
ResourceTestHelper.enableAutoBuilding();
- EditorTestHelper.joinJobs(2000, 30000, 1000);
- }
+
+ EditorTestHelper.joinBackgroundActivities();
}
}
@@ -79,35 +81,12 @@
* @see junit.extensions.TestSetup#tearDown()
*/
protected void tearDown() throws Exception {
- // do nothing, the set up workspace will be used by the open editor tests
+ // do nothing, the set up workspace will be used by other tests (see test.xml)
}
- private void setUpProject() throws IOException, ZipException, CoreException {
- String workspacePath= ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/";
- FileTool.unzip(new ZipFile(FileTool.getFileInPlugin(JdtTextTestPlugin.getDefault(), new Path(PROJECT_ZIP))), new File(workspacePath));
- File oldFile= new File(workspacePath + PROJECT + "/.classpath_win32");
- File newFile= new File(workspacePath + PROJECT + "/.classpath");
- assertTrue(oldFile.renameTo(newFile));
-
- IProject project= createExistingProject(PROJECT);
+ private static void setUpProject() throws IOException, ZipException, CoreException {
+ IProject project= ResourceTestHelper.createProjectFromZip(JdtTextTestPlugin.getDefault(), PROJECT_ZIP, PROJECT);
+ ResourceTestHelper.copy("/" + PROJECT + "/.classpath_win32", "/" + PROJECT + "/.classpath");
assertTrue(JavaCore.create(project).exists());
}
-
- private IProject createExistingProject(String projectName) throws CoreException {
-
- IWorkspace workspace= ResourcesPlugin.getWorkspace();
- IProject project= workspace.getRoot().getProject(projectName);
- IProjectDescription description= workspace.newProjectDescription(projectName);
- description.setLocation(null);
-
- project.create(description, null);
- project.open(null);
- return project;
- }
-
- private boolean projectExists(String projectName) {
- IWorkspace workspace= ResourcesPlugin.getWorkspace();
- IProject project= workspace.getRoot().getProject(projectName);
- return project.exists();
- }
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSuite.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSuite.java
index 6d53ce3..90c5afb 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSuite.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/PerformanceTestSuite.java
@@ -24,14 +24,23 @@
}
public PerformanceTestSuite() {
- addTest(new OpenJavaEditorTestSetup(EmptyTestCase.suite())); // the actual test runs in its own workbench (see test.xml)
- addTest(new OpenTextEditorTestSetup(EmptyTestCase.suite())); // the actual test runs in its own workbench (see test.xml)
addTest(RevertTextEditorTest.suite());
addTest(RevertJavaEditorTest.suite());
addTest(ToggleCommentTest.suite());
- addTest(UndoJavaEditorTest.suite());
addTest(UndoTextEditorTest.suite());
+ addTest(UndoJavaEditorTest.suite());
addTest(OpenQuickOutlineTest.suite());
+ addTest(OpenJavaContentAssistTest.suite());
addTest(OpenJavaEditorStressTest.suite());
+ addTest(JavaSmartPasteTest.suite());
+ addTest(ActivateTextEditorTest.suite());
+ addTest(ActivateJavaEditorTest.suite());
+ addTest(SaveTextEditorTest.suite());
+ addTest(SaveJavaEditorTest.suite());
+ addTest(JavaFormatterTest.suite());
+ addTest(JavaExpandSelectionTest.suite());
+ addTest(JavaFormatterProjectTest.suite());
+ addTest(EventDrivenTestSuite.suite());
+ addTest(new OpenJavaEditorTest.Setup(EmptyTestCase.suite(), false)); // the actual test runs in its own workbench (see test.xml)
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/QuickDiffInvocationCountTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/QuickDiffInvocationCountTest.java
index d7b9f03..cef175b 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/QuickDiffInvocationCountTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/QuickDiffInvocationCountTest.java
@@ -16,10 +16,7 @@
import junit.framework.TestSuite;
import org.eclipse.test.performance.PerformanceMeter;
-import org.eclipse.jface.text.DocumentRewriteSession;
-import org.eclipse.jface.text.DocumentRewriteSessionType;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension4;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -54,18 +51,13 @@
fEditor.showChangeInformation(false);
ISourceViewer viewer= EditorTestHelper.getSourceViewer(fEditor);
IDocument document= EditorTestHelper.getDocument(fEditor);
- DocumentRewriteSession rewriteSession= null;
try {
if (viewer instanceof ITextViewerExtension)
((ITextViewerExtension) viewer).getRewriteTarget().beginCompoundChange();
- if (document instanceof IDocumentExtension4)
- rewriteSession= ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.STRICTLY_SEQUENTIAL);
for (int i= 0; i < document.getNumberOfLines(); i += 2) {
document.replace(document.getLineOffset(i), 0, " ");
}
} finally {
- if (document instanceof IDocumentExtension4)
- ((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
if (viewer instanceof ITextViewerExtension)
((ITextViewerExtension) viewer).getRewriteTarget().endCompoundChange();
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ResourceTestHelper.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ResourceTestHelper.java
index 9806e6c..efa6d2f 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ResourceTestHelper.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ResourceTestHelper.java
@@ -11,6 +11,7 @@
package org.eclipse.jdt.text.tests.performance;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -19,16 +20,22 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
import junit.framework.Assert;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Preferences;
public class ResourceTestHelper {
@@ -80,6 +87,11 @@
getFile(file).delete(true, null);
}
+ public static void delete(String prefix, String suffix, int n) throws CoreException {
+ for (int i= 0; i < n; i++)
+ delete(prefix + i + suffix);
+ }
+
public static IFile findFile(String pathStr) {
IFile file= getFile(pathStr);
Assert.assertTrue(file != null && file.exists());
@@ -123,11 +135,13 @@
}
}
- public static void copy(String src, String dest, String srcName, String destName) throws IOException, CoreException {
- StringBuffer buf= read(src);
- List positions= identifierPositions(buf, srcName);
- replacePositions(buf, srcName.length(), destName, positions);
- write(dest, buf.toString());
+ public static void copy(String src, String dest, String srcName, String destName, int ifExists) throws IOException, CoreException {
+ if (handleExisting(dest, ifExists)) {
+ StringBuffer buf= read(src);
+ List positions= identifierPositions(buf, srcName);
+ replacePositions(buf, srcName.length(), destName, positions);
+ write(dest, buf.toString());
+ }
}
private static void replacePositions(StringBuffer c, int origLength, String string, List positions) {
@@ -159,14 +173,6 @@
return ResourcesPlugin.getWorkspace().getRoot();
}
- public static boolean enableAutoBuilding() {
- IWorkspaceDescription description= ResourcesPlugin.getWorkspace().getDescription();
- boolean wasOff= !description.isAutoBuilding();
- if (wasOff)
- description.setAutoBuilding(true);
- return wasOff;
- }
-
public static void incrementalBuild() throws CoreException {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
}
@@ -176,10 +182,44 @@
}
public static boolean disableAutoBuilding() {
- IWorkspaceDescription description= ResourcesPlugin.getWorkspace().getDescription();
- boolean wasOn= description.isAutoBuilding();
- if (wasOn)
- description.setAutoBuilding(false);
- return wasOn;
+ return setAutoBuilding(false);
+ }
+
+ public static boolean enableAutoBuilding() {
+ return setAutoBuilding(true);
+ }
+
+ public static boolean setAutoBuilding(boolean value) {
+ Preferences preferences= ResourcesPlugin.getPlugin().getPluginPreferences();
+ boolean oldValue= preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING);
+ if (value != oldValue)
+ preferences.setValue(ResourcesPlugin.PREF_AUTO_BUILDING, value);
+ return oldValue;
+ }
+
+ public static IProject createExistingProject(String projectName) throws CoreException {
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ IProject project= workspace.getRoot().getProject(projectName);
+ IProjectDescription description= workspace.newProjectDescription(projectName);
+ description.setLocation(null);
+
+ project.create(description, null);
+ project.open(null);
+ return project;
+ }
+
+ public static IProject createProjectFromZip(Plugin installationPlugin, String projectZip, String projectName) throws IOException, ZipException, CoreException {
+ String workspacePath= ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/";
+ FileTool.unzip(new ZipFile(FileTool.getFileInPlugin(installationPlugin, new Path(projectZip))), new File(workspacePath));
+ return createExistingProject(projectName);
+ }
+
+ public static IProject getProject(String projectName) {
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ return workspace.getRoot().getProject(projectName);
+ }
+
+ public static boolean projectExists(String projectName) {
+ return getProject(projectName).exists();
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertEditorTest.java
index dcec913..a8af828 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertEditorTest.java
@@ -33,6 +33,7 @@
private PerformanceMeter fPerformanceMeter;
protected void setUp() throws Exception {
+ super.setUp();
Performance performance= Performance.getDefault();
fPerformanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
setWarmUpRuns(WARM_UP_RUNS);
@@ -59,6 +60,7 @@
}
protected void tearDown() throws Exception {
+ super.tearDown();
fPerformanceMeter.dispose();
EditorTestHelper.closeAllEditors();
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertJavaEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertJavaEditorTest.java
index 5902862..39de43f 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertJavaEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/RevertJavaEditorTest.java
@@ -13,10 +13,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.jface.text.BadLocationException;
-
-import org.eclipse.ui.PartInitException;
-
/**
* @since 3.1
@@ -25,11 +21,7 @@
private static final Class THIS= RevertJavaEditorTest.class;
- private static final String PATH= "/Eclipse SWT/win32/org/eclipse/swt/graphics/";
-
- private static final String FILE_PREFIX= "TextLayout";
-
- private static final String FILE_SUFFIX= ".java";
+ private static final String FILE= PerformanceTestSetup.PROJECT + "/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java";
public static Test suite() {
return new PerformanceTestSetup(new TestSuite(THIS));
@@ -40,8 +32,21 @@
EditorTestHelper.runEventQueue();
}
- public void testRevertJavaEditor() throws PartInitException, BadLocationException {
- measureRevert(ResourceTestHelper.findFile(PerformanceTestSetup.PROJECT + PATH + FILE_PREFIX + FILE_SUFFIX));
+ public void testRevertJavaEditor() throws Exception {
+ try {
+ EditorTestHelper.enableFolding(true);
+ measureRevert(ResourceTestHelper.findFile(FILE));
+ } finally {
+ EditorTestHelper.resetFolding();
+ }
}
+ public void test2() throws Exception {
+ try {
+ EditorTestHelper.enableFolding(false);
+ measureRevert(ResourceTestHelper.findFile(FILE));
+ } finally {
+ EditorTestHelper.resetFolding();
+ }
+ }
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SWTEventHelper.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SWTEventHelper.java
index 98e7a19..0ceefc8 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SWTEventHelper.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SWTEventHelper.java
@@ -42,16 +42,16 @@
keyCodeUp(display, keyCodes[i], runEventQueue);
}
- private static void keyCodeDown(Display display, int keyCode, boolean runEventQueue) {
+ public static void keyCodeDown(Display display, int keyCode, boolean runEventQueue) {
keyCodeEvent(display, SWT.KeyDown, keyCode, runEventQueue);
}
- private static void keyCodeUp(Display display, int keyCode, boolean runEventQueue) {
+ public static void keyCodeUp(Display display, int keyCode, boolean runEventQueue) {
keyCodeEvent(display, SWT.KeyUp, keyCode, runEventQueue);
}
private static Event sfKeyCodeEvent= new Event();
- private static void keyCodeEvent(Display display, int type, int keyCode, boolean runEventQueue) {
+ public static void keyCodeEvent(Display display, int type, int keyCode, boolean runEventQueue) {
sfKeyCodeEvent.type= type;
sfKeyCodeEvent.keyCode= keyCode;
@@ -60,6 +60,44 @@
EditorTestHelper.runEventQueue();
}
+ public static void pressKeyChar(Display display, char keyChar) {
+ pressKeyChar(display, keyChar, true);
+ }
+
+ public static void pressKeyChar(Display display, char keyChar, boolean runEventQueue) {
+ keyCharDown(display, keyChar, runEventQueue);
+ keyCharUp(display, keyChar, runEventQueue);
+ }
+
+ public static void pressKeyCharCombination(Display display, char[] keyChars) {
+ pressKeyCharCombination(display, keyChars, true);
+ }
+
+ public static void pressKeyCharCombination(Display display, char[] keyChars, boolean runEventQueue) {
+ for (int i= 0; i < keyChars.length; i++)
+ keyCharDown(display, keyChars[i], runEventQueue);
+ for (int i= keyChars.length - 1; i >= 0; i--)
+ keyCharUp(display, keyChars[i], runEventQueue);
+ }
+
+ public static void keyCharDown(Display display, char keyChar, boolean runEventQueue) {
+ keyCharEvent(display, SWT.KeyDown, keyChar, runEventQueue);
+ }
+
+ public static void keyCharUp(Display display, char keyChar, boolean runEventQueue) {
+ keyCharEvent(display, SWT.KeyUp, keyChar, runEventQueue);
+ }
+
+ private static Event sfKeyCharEvent= new Event();
+ public static void keyCharEvent(Display display, int type, char keyChar, boolean runEventQueue) {
+ sfKeyCharEvent.type= type;
+ sfKeyCharEvent.character= keyChar;
+
+ display.post(sfKeyCharEvent);
+ if (runEventQueue)
+ EditorTestHelper.runEventQueue();
+ }
+
private static Event sfMouseMoveEvent= new Event();
public static void mouseMoveEvent(Display display, int x, int y, boolean runEventQueue) {
sfMouseMoveEvent.type= SWT.MouseMove;
@@ -80,7 +118,7 @@
}
private static Event sfMouseButtonEvent= new Event();
- private static void mouseButtonEvent(Display display, int type, int button, boolean runEventQueue) {
+ public static void mouseButtonEvent(Display display, int type, int button, boolean runEventQueue) {
sfMouseButtonEvent.type= type;
sfMouseButtonEvent.button= button;
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollAnnotatedJavaEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollAnnotatedJavaEditorTest.java
index a1475ef..de73a62 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollAnnotatedJavaEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollAnnotatedJavaEditorTest.java
@@ -14,112 +14,56 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-
-import org.eclipse.jdt.internal.ui.JavaPlugin;
-import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
-
-public class ScrollAnnotatedJavaEditorTest extends ScrollEditorTest {
+/**
+ * Measure the time spent while scrolling with error annotations in the Java editor.
+ *
+ * @since 3.1
+ */
+public class ScrollAnnotatedJavaEditorTest extends AbstractScrollAnnotatedJavaEditorTest {
private static final Class THIS= ScrollAnnotatedJavaEditorTest.class;
- private static final String PAGE_SCROLLING_FILE= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
-
- private static final String LINE_SCROLLING_FILE= "/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java";
-
- private static final int WARM_UP_RUNS= 3;
-
- private static final int MEASURED_RUNS= 3;
-
public static Test suite() {
return new PerformanceTestSetup(new TestSuite(THIS));
}
- protected void setUp(IEditorPart editor) throws Exception {
- super.setUp(editor);
- createAnnotations(editor);
- EditorTestHelper.joinJobs(1000, 20000, 100);
- setWarmUpRuns(WARM_UP_RUNS);
- setMeasuredRuns(MEASURED_RUNS);
- }
-
- private void createAnnotations(IEditorPart editor) throws BadLocationException, JavaModelException {
- // produce a lot of annotations: rename all declarations
- ITextViewerExtension extension= null;
- JavaEditor javaEditor= (JavaEditor) editor;
- ISourceViewer viewer= javaEditor.getViewer();
- if (viewer instanceof ITextViewerExtension) {
- extension= (ITextViewerExtension) viewer;
- extension.getRewriteTarget().beginCompoundChange();
- }
- try {
- IDocument document= EditorTestHelper.getDocument((ITextEditor) editor);
- ICompilationUnit unit= JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(javaEditor.getEditorInput());
- IType[] allTypes= unit.getAllTypes();
- for (int i= 0; i < allTypes.length; i++) {
- IType type= allTypes[i];
- renameMemberDecls(document, type.getMethods());
- renameMemberDecls(document, type.getFields());
- }
- } finally {
- if (extension != null)
- extension.getRewriteTarget().endCompoundChange();
- }
-
- }
-
- private void renameMemberDecls(IDocument document, IMember[] members) throws JavaModelException, BadLocationException {
- for (int j= 0; j < members.length; j++) {
- IMember member= members[j];
- ISourceRange range= member.getNameRange();
- if (range != null)
- document.replace(range.getOffset(), 2, "XX");
- }
- }
-
- protected void tearDown(IEditorPart editor) throws Exception {
- super.tearDown(editor);
- if (editor instanceof ITextEditor)
- EditorTestHelper.revertEditor((ITextEditor) editor, true);
- }
-
- public void testScrollJavaEditorLineWise1() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_NO_CARET_MOVE, false);
- }
-
+ /**
+ * Measure the time spent while scrolling page wise with error
+ * annotations in the Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorPageWise() throws Exception {
- measureScrolling(PAGE_SCROLLING_FILE, PAGE_WISE, false);
+ measure(PAGE_WISE);
}
- public void testScrollJavaEditorLineWisePreloaded1() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_NO_CARET_MOVE, true);
- }
-
- public void testScrollJavaEditorPageWisePreloaded1() throws Exception {
- measureScrolling(PAGE_SCROLLING_FILE, PAGE_WISE, true);
- }
-
+ /**
+ * Measure the time spent while scrolling line wise with error
+ * annotations in the Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorLineWiseMoveCaret1() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE, false);
+ measure(LINE_WISE);
}
- public void testScrollJavaEditorLineWiseMoveCaretPreloaded1() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE, true);
- }
-
+ /**
+ * Measure the time spent while scrolling and selecting line wise with
+ * error annotations in the Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorLineWiseSelect1() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_SELECT, false);
+ measure(LINE_WISE_SELECT);
+ }
+
+ /**
+ * Measure the time spent while scrolling line wise without moving the
+ * caret with error annotations in the Java editor.
+ *
+ * @throws Exception
+ */
+ public void testScrollJavaEditorLineWise1() throws Exception {
+ measure(LINE_WISE_NO_CARET_MOVE);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java
index 95f9d6e..51921b4 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java
@@ -16,13 +16,21 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
-import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
public abstract class ScrollEditorTest extends TextPerformanceTestCase {
+ private static final int WARM_UP_RUNS= 3;
+
+ private static final int MEASURED_RUNS= 3;
+
+ private static final String PAGE_SCROLLING_FILE= PerformanceTestSetup.STYLED_TEXT;
+
+ private static final String LINE_SCROLLING_FILE= PerformanceTestSetup.TEXT_LAYOUT;
+
private static final int[] CTRL_HOME= new int[] { SWT.CTRL, SWT.HOME };
private static final int[] CTRL_DOWN= new int[] { SWT.CTRL, SWT.ARROW_DOWN };
private static final int[] PG_DOWN= new int[] { SWT.PAGE_DOWN };
@@ -32,109 +40,108 @@
private static final int[] PG_UP= new int[] { SWT.PAGE_UP };
protected abstract static class ScrollingMode {
- ScrollingMode(int[] scroll_combo, int[] home_combo) {
+ public ScrollingMode(int[] scroll_combo, int[] home_combo) {
super();
SCROLL_COMBO= scroll_combo;
HOME_COMBO= home_combo;
}
- final int[] SCROLL_COMBO;
- final int[] HOME_COMBO;
- abstract int computeOperations(int numberOfLines, int visibleLines);
+ public final int[] SCROLL_COMBO;
+ public final int[] HOME_COMBO;
+ public abstract int computeOperations(int numberOfLines, int visibleLines);
+ public abstract String getFile();
}
- public static final ScrollingMode PAGE_WISE= new ScrollingMode(PG_DOWN, CTRL_HOME) {
- int computeOperations(int numberOfLines, int visibleLines) {
+ protected static final ScrollingMode PAGE_WISE= new ScrollingMode(PG_DOWN, CTRL_HOME) {
+ public int computeOperations(int numberOfLines, int visibleLines) {
return numberOfLines / visibleLines;
}
- };
- public static final ScrollingMode PAGE_WISE_SELECT= new ScrollingMode(SHIFT_PG_DOWN, CTRL_HOME) {
- int computeOperations(int numberOfLines, int visibleLines) {
- return numberOfLines / visibleLines;
+ public String getFile() {
+ return PAGE_SCROLLING_FILE;
}
};
- public static final ScrollingMode LINE_WISE_NO_CARET_MOVE= new ScrollingMode(CTRL_DOWN, PG_UP) {
- int computeOperations(int numberOfLines, int visibleLines) {
+ protected static final ScrollingMode PAGE_WISE_SELECT= new ScrollingMode(SHIFT_PG_DOWN, CTRL_HOME) {
+ public int computeOperations(int numberOfLines, int visibleLines) {
+ return numberOfLines / visibleLines;
+ }
+ public String getFile() {
+ return PAGE_SCROLLING_FILE;
+ }
+ };
+ protected static final ScrollingMode LINE_WISE_NO_CARET_MOVE= new ScrollingMode(CTRL_DOWN, PG_UP) {
+ public int computeOperations(int numberOfLines, int visibleLines) {
return numberOfLines - visibleLines;
}
- };
- public static final ScrollingMode LINE_WISE= new ScrollingMode(DOWN, CTRL_HOME) {
- int computeOperations(int numberOfLines, int visibleLines) {
- return numberOfLines - 1;
+ public String getFile() {
+ return LINE_SCROLLING_FILE;
}
};
- public static final ScrollingMode LINE_WISE_SELECT= new ScrollingMode(SHIFT_DOWN, CTRL_HOME) {
- int computeOperations(int numberOfLines, int visibleLines) {
+ protected static final ScrollingMode LINE_WISE= new ScrollingMode(DOWN, CTRL_HOME) {
+ public int computeOperations(int numberOfLines, int visibleLines) {
return numberOfLines - 1;
}
+ public String getFile() {
+ return LINE_SCROLLING_FILE;
+ }
};
-
- private PerformanceMeter fPerformanceMeter;
+ protected static final ScrollingMode LINE_WISE_SELECT= new ScrollingMode(SHIFT_DOWN, CTRL_HOME) {
+ public int computeOperations(int numberOfLines, int visibleLines) {
+ return numberOfLines - 1;
+ }
+ public String getFile() {
+ return LINE_SCROLLING_FILE;
+ }
+ };
protected void setUp() throws Exception {
- Performance performance= Performance.getDefault();
- fPerformanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
+ super.setUp();
EditorTestHelper.bringToTop();
+ setWarmUpRuns(WARM_UP_RUNS);
+ setMeasuredRuns(MEASURED_RUNS);
}
+
+ protected void setUp(AbstractTextEditor editor) throws Exception { }
- protected void tearDown() throws Exception {
- fPerformanceMeter.dispose();
+ protected void measure(ScrollingMode mode) throws Exception {
+ measure(mode, createPerformanceMeter(), getWarmUpRuns(), getMeasuredRuns());
}
-
- protected void measureScrolling(String file, ScrollingMode mode, boolean preload) throws Exception {
- IEditorPart editor= null;
+
+ protected void measure(ScrollingMode mode, PerformanceMeter performanceMeter, int warmUpRuns, int measuredRuns) throws Exception {
+ AbstractTextEditor editor= null;
try {
- editor= EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
- EditorTestHelper.joinJobs(3000, 10000, 100);
-
+ editor= (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(mode.getFile()), getEditor(), true);
setUp(editor);
-
- Display display= EditorTestHelper.getActiveDisplay();
+ EditorTestHelper.joinBackgroundActivities(editor);
StyledText text= (StyledText) editor.getAdapter(Control.class);
- int numberOfLines= text.getLineCount();
- int visibleLinesInViewport= text.getClientArea().height / text.getLineHeight();
- int operations= mode.computeOperations(numberOfLines, visibleLinesInViewport);
-
- int warmUpRuns= getWarmUpRuns();
- int measuredRuns= getMeasuredRuns();
- for (int i= 0; i < warmUpRuns + measuredRuns; i++) {
- if (preload) {
- for (int j= 0; j < operations; j++) {
- // avoid overhead: assertTrue(text.getTopIndex() + visibleLinesInViewport < numberOfLines - 1);
- SWTEventHelper.pressKeyCodeCombination(display, mode.SCROLL_COMBO, false);
- }
- if (i >= warmUpRuns)
- fPerformanceMeter.start();
- EditorTestHelper.runEventQueue(100);
- if (i >= warmUpRuns)
- fPerformanceMeter.stop();
- } else {
- if (i >= warmUpRuns)
- fPerformanceMeter.start();
- for (int j= 0; j < operations; j++) {
- // avoid overhead: assertTrue(text.getTopIndex() + visibleLinesInViewport < numberOfLines - 1);
- SWTEventHelper.pressKeyCodeCombination(display, mode.SCROLL_COMBO);
- }
- if (i >= warmUpRuns)
- fPerformanceMeter.stop();
- EditorTestHelper.runEventQueue(100);
- }
- assertTrue("TopIndex: "+text.getTopIndex() + " visibleLines: " + visibleLinesInViewport + " totalLines: " + numberOfLines + " operations: " + operations, text.getTopIndex() + visibleLinesInViewport >= numberOfLines - 1);
- SWTEventHelper.pressKeyCodeCombination(display, mode.HOME_COMBO);
- EditorTestHelper.runEventQueue(100);
- assertEquals(0, text.getTopIndex());
- }
- fPerformanceMeter.commit();
- Performance.getDefault().assertPerformance(fPerformanceMeter);
+ measure(text, mode, getNullPerformanceMeter(), warmUpRuns);
+ measure(text, mode, performanceMeter, measuredRuns);
+ commitAllMeasurements();
+ assertAllPerformance();
} finally {
- tearDown(editor);
EditorTestHelper.closeAllEditors();
}
}
- protected void setUp(IEditorPart editor) throws Exception {
- }
+ protected abstract String getEditor();
- protected void tearDown(IEditorPart editor) throws Exception {
+ private void measure(StyledText text, ScrollingMode mode, PerformanceMeter performanceMeter, int runs) {
+ Display display= EditorTestHelper.getActiveDisplay();
+ int numberOfLines= text.getLineCount();
+ int visibleLinesInViewport= text.getClientArea().height / text.getLineHeight();
+ int operations= mode.computeOperations(numberOfLines, visibleLinesInViewport);
+
+ for (int i= 0; i < runs; i++) {
+ performanceMeter.start();
+ for (int j= 0; j < operations; j++) {
+ // avoid overhead: assertTrue(text.getTopIndex() + visibleLinesInViewport < numberOfLines - 1);
+ SWTEventHelper.pressKeyCodeCombination(display, mode.SCROLL_COMBO);
+ }
+ performanceMeter.stop();
+ EditorTestHelper.runEventQueue(100);
+ assertTrue("TopIndex: " + text.getTopIndex() + " visibleLines: " + visibleLinesInViewport + " totalLines: " + numberOfLines + " operations: " + operations, text.getTopIndex() + visibleLinesInViewport >= numberOfLines - 1);
+ SWTEventHelper.pressKeyCodeCombination(display, mode.HOME_COMBO);
+ EditorTestHelper.runEventQueue(100);
+ assertEquals(0, text.getTopIndex());
+ }
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollJavaEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollJavaEditorTest.java
index 8f1ec5d..23d7351 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollJavaEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollJavaEditorTest.java
@@ -14,53 +14,58 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+/**
+ * Measure the time spent while scrolling in the Java editor.
+ *
+ * @since 3.1
+ */
public class ScrollJavaEditorTest extends ScrollEditorTest {
private static final Class THIS= ScrollJavaEditorTest.class;
- private static final String PAGE_SCROLLING_FILE= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
-
- private static final String LINE_SCROLLING_FILE= "/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java";
-
- private static final int WARM_UP_RUNS= 3;
-
- private static final int MEASURED_RUNS= 3;
-
public static Test suite() {
return new PerformanceTestSetup(new TestSuite(THIS));
}
- protected void setUp() throws Exception {
- super.setUp();
- setWarmUpRuns(WARM_UP_RUNS);
- setMeasuredRuns(MEASURED_RUNS);
+ protected String getEditor() {
+ return EditorTestHelper.COMPILATION_UNIT_EDITOR_ID;
}
- public void testScrollJavaEditorLineWise2() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_NO_CARET_MOVE, false);
- }
-
+ /**
+ * Measure the time spent while scrolling page wise in the Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorPageWise() throws Exception {
- measureScrolling(PAGE_SCROLLING_FILE, PAGE_WISE, false);
+ measure(PAGE_WISE);
}
- public void testScrollJavaEditorLineWisePreloaded2() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_NO_CARET_MOVE, true);
- }
-
- public void testScrollJavaEditorPageWisePreloaded2() throws Exception {
- measureScrolling(PAGE_SCROLLING_FILE, PAGE_WISE, true);
- }
-
+ /**
+ * Measure the time spent while scrolling line wise in the Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorLineWiseMoveCaret2() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE, false);
+ measure(LINE_WISE);
}
- public void testScrollJavaEditorLineWiseMoveCaretPreloaded2() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE, true);
- }
-
+ /**
+ * Measure the time spent while scrolling and selecting line wise in the
+ * Java editor.
+ *
+ * @throws Exception
+ */
public void testScrollJavaEditorLineWiseSelect2() throws Exception {
- measureScrolling(LINE_SCROLLING_FILE, LINE_WISE_SELECT, false);
+ measure(LINE_WISE_SELECT);
+ }
+
+ /**
+ * Measure the time spent while scrolling line wise without moving the
+ * caret in the Java editor.
+ *
+ * @throws Exception
+ */
+ public void testScrollJavaEditorLineWise2() throws Exception {
+ measure(LINE_WISE_NO_CARET_MOVE);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollTextEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollTextEditorTest.java
index dccc08c..eabcc0a 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollTextEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollTextEditorTest.java
@@ -14,97 +14,58 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-
+/**
+ * Measure the time spent while scrolling in the text editor.
+ *
+ * @since 3.1
+ */
public class ScrollTextEditorTest extends ScrollEditorTest {
private static final Class THIS= ScrollTextEditorTest.class;
- private static final String PAGE_FILE_PREFIX= "/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText";
-
- private static final String ORIG_PAGE_FILE= PAGE_FILE_PREFIX + ".java";
-
- private static final String PAGE_FILE= PAGE_FILE_PREFIX + ".txt";
-
- private static final String LINE_FILE_PREFIX= "/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout";
-
- private static final String ORIG_LINE_FILE= LINE_FILE_PREFIX + ".java";
-
- private static final String LINE_FILE= LINE_FILE_PREFIX + ".txt";
-
- private static final int WARM_UP_RUNS= 3;
-
- private static final int MEASURED_RUNS= 3;
-
public static Test suite() {
return new PerformanceTestSetup(new TestSuite(THIS));
}
-
- protected void setUp() throws Exception {
- super.setUp();
- setWarmUpRuns(WARM_UP_RUNS);
- setMeasuredRuns(MEASURED_RUNS);
- }
- public void testScrollTextEditorLineWise2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_LINE_FILE, LINE_FILE);
- measureScrolling(LINE_FILE, LINE_WISE_NO_CARET_MOVE, false);
- } finally {
- ResourceTestHelper.delete(LINE_FILE);
- }
+ protected String getEditor() {
+ return EditorTestHelper.TEXT_EDITOR_ID;
}
+ /**
+ * Measure the time spent while scrolling page wise in the text editor.
+ *
+ * @throws Exception
+ */
public void testScrollTextEditorPageWise() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_PAGE_FILE, PAGE_FILE);
- measureScrolling(PAGE_FILE, PAGE_WISE, false);
- } finally {
- ResourceTestHelper.delete(PAGE_FILE);
- }
+ measure(PAGE_WISE);
}
- public void testScrollTextEditorLineWisePreloaded2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_LINE_FILE, LINE_FILE);
- measureScrolling(LINE_FILE, LINE_WISE_NO_CARET_MOVE, true);
- } finally {
- ResourceTestHelper.delete(LINE_FILE);
- }
- }
-
- public void testScrollTextEditorPageWisePreloaded2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_PAGE_FILE, PAGE_FILE);
- measureScrolling(PAGE_FILE, PAGE_WISE, true);
- } finally {
- ResourceTestHelper.delete(PAGE_FILE);
- }
- }
-
+ /**
+ * Measure the time spent while scrolling line wise in the text editor.
+ *
+ * @throws Exception
+ */
public void testScrollTextEditorLineWiseMoveCaret2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_LINE_FILE, LINE_FILE);
- measureScrolling(LINE_FILE, LINE_WISE, false);
- } finally {
- ResourceTestHelper.delete(LINE_FILE);
- }
+ measure(LINE_WISE);
}
- public void testScrollTextEditorLineWiseMoveCaretPreloaded2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_LINE_FILE, LINE_FILE);
- measureScrolling(LINE_FILE, LINE_WISE, true);
- } finally {
- ResourceTestHelper.delete(LINE_FILE);
- }
- }
-
+ /**
+ * Measure the time spent while scrolling and selecting line wise in the
+ * text editor.
+ *
+ * @throws Exception
+ */
public void testScrollTextEditorLineWiseSelect2() throws Exception {
- try {
- ResourceTestHelper.copy(ORIG_LINE_FILE, LINE_FILE);
- measureScrolling(LINE_FILE, LINE_WISE_SELECT, false);
- } finally {
- ResourceTestHelper.delete(LINE_FILE);
- }
+ measure(LINE_WISE_SELECT);
+ }
+
+ /**
+ * Measure the time spent while scrolling line wise without moving the
+ * caret in the text editor.
+ *
+ * @throws Exception
+ */
+ public void testScrollTextEditorLineWise2() throws Exception {
+ measure(LINE_WISE_NO_CARET_MOVE);
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java
index cc09a2a..bb52809 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java
@@ -11,6 +11,20 @@
package org.eclipse.jdt.text.tests.performance;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+
+import org.eclipse.test.performance.Dimension;
+import org.eclipse.test.performance.Performance;
+import org.eclipse.test.performance.PerformanceMeter;
+
+import org.eclipse.jdt.text.tests.JdtTextTestPlugin;
+
import junit.framework.TestCase;
/**
@@ -20,21 +34,42 @@
*/
public class TextPerformanceTestCase extends TestCase {
- /** <code>true</code> iff the default number of runs should be used */
- private static final boolean USE_DEFAULT_RUNS= false;
+ /** containing plug-in id */
+ private static final String PLUGIN_ID= JdtTextTestPlugin.PLUGIN_ID;
- /** default number of warm-up runs */
- private static final int DEFAULT_WARM_UP_RUNS= 1;
+ /** boolean option, a value of <code>"true"</code> enables overriding of the number of runs */
+ private static final String OVERRIDE_RUNS_OPTION= "/debug/performance/OverrideRuns";
+
+ /** integer option, its value overrides the number of warm-up runs */
+ private static final String OVERRIDE_WARM_UP_RUNS_OPTION= "/debug/performance/OverrideWarmUpRuns";
+
+ /** integer option, its value overrides the number of measured runs */
+ private static final String OVERRIDE_MEASURED_RUNS_OPTION= "/debug/performance/OverrideMeasuredRuns";
+
+ /** <code>true</code> iff the number of runs should be overridden */
+ private static final boolean OVERRIDE_RUNS= Boolean.toString(true).equals(Platform.getDebugOption(PLUGIN_ID + OVERRIDE_RUNS_OPTION));
- /** default number of measured runs */
- private static final int DEFAULT_MEASURED_RUNS= 2;
+ /** overridden number of warm-up runs */
+ private static final int OVERRIDE_WARM_UP_RUNS= intValueOf(Platform.getDebugOption(PLUGIN_ID + OVERRIDE_WARM_UP_RUNS_OPTION), 2);
+
+ /** overridden number of measured runs */
+ private static final int OVERRIDE_MEASURED_RUNS= intValueOf(Platform.getDebugOption(PLUGIN_ID + OVERRIDE_MEASURED_RUNS_OPTION), 2);
/** custom number of warm-up runs */
private int fCustomWarmUpRuns= -1;
/** custom number of measured runs */
private int fCustomMeasuredRuns= -1;
+
+ /** created performance meters */
+ private List fPerformanceMeters;
+ /** {@link KeyboardProbe} singleton */
+ private static KeyboardProbe fgKeyboardProbe;
+
+ /** base scenario id */
+ private String fBaseScenarioId;
+
/*
* @see TestCase#TestCase()
*/
@@ -49,18 +84,28 @@
super(name);
}
+ /*
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (fPerformanceMeters != null)
+ for (Iterator iter= fPerformanceMeters.iterator(); iter.hasNext();)
+ ((PerformanceMeter) iter.next()).dispose();
+ }
+
/**
* @return number of warm-up runs, must have been set before
*/
protected final int getWarmUpRuns() {
assertTrue(fCustomWarmUpRuns >= 0);
- if (USE_DEFAULT_RUNS)
- return DEFAULT_WARM_UP_RUNS;
+ if (OVERRIDE_RUNS)
+ return OVERRIDE_WARM_UP_RUNS;
return fCustomWarmUpRuns;
}
/**
- * Sets the number of warm-up runs. Can be overruled.
+ * Sets the number of warm-up runs. Can be overridden.
*
* @param runs number of warm-up runs
*/
@@ -73,17 +118,291 @@
*/
protected final int getMeasuredRuns() {
assertTrue(fCustomMeasuredRuns >= 0);
- if (USE_DEFAULT_RUNS)
- return DEFAULT_MEASURED_RUNS;
+ if (OVERRIDE_RUNS)
+ return OVERRIDE_MEASURED_RUNS;
return fCustomMeasuredRuns;
}
/**
- * Sets the number of measured runs. Can be overruled.
+ * Sets the number of measured runs. Can be overridden.
*
* @param runs number of measured runs
*/
protected final void setMeasuredRuns(int runs) {
fCustomMeasuredRuns= runs;
}
+
+ /**
+ * @return the default scenario id for this test
+ */
+ protected final String getDefaultScenarioId() {
+ return Performance.getDefault().getDefaultScenarioId(this);
+ }
+
+ /**
+ * Returns the base scenario id for this test which has the default
+ * scenario id as its default.
+ *
+ * @return the base scenario id
+ */
+ protected final String getBaseScenarioId() {
+ if (fBaseScenarioId == null)
+ fBaseScenarioId= Performance.getDefault().getDefaultScenarioId(this);
+ return fBaseScenarioId;
+ }
+
+ /**
+ * Sets the base scenario id for this test.
+ *
+ * @param baseScenarioId the base scenario id
+ */
+ protected final void setBaseScenarioId(String baseScenarioId) {
+ fBaseScenarioId= baseScenarioId;
+ }
+
+ /**
+ * Create a performance meter with the base scenario id. The
+ * performance meter will be disposed on {@link #tearDown()}.
+ *
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeter() {
+ return createPerformanceMeter("");
+ }
+
+ /**
+ * Create a performance meter with the given sub-scenario id. The
+ * performance meter will be disposed on {@link #tearDown()}.
+ *
+ * @param subScenarioId the sub-scenario id
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeter(String subScenarioId) {
+ return internalCreatePerformanceMeter(getBaseScenarioId() + subScenarioId);
+ }
+
+ /**
+ * Create a performance meter with the base scenario id and mark the
+ * scenario to be included into the component performance summary. The
+ * summary shows the given dimension of the scenario and labels the
+ * scenario with the short name. The performance meter will be disposed
+ * on {@link #tearDown()}.
+ *
+ * @param shortName a short (shorter than 40 characters) descriptive
+ * name of the scenario
+ * @param dimension the dimension to show in the summary
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeterForSummary(String shortName, Dimension dimension) {
+ return createPerformanceMeterForSummary("", shortName, dimension);
+ }
+
+ /**
+ * Create a performance meter with the given sub-scenario id and mark
+ * the scenario to be included into the component performance summary.
+ * The summary shows the given dimension of the scenario and labels the
+ * scenario with the short name. The performance meter will be disposed
+ * on {@link #tearDown()}.
+ *
+ * @param subScenarioId the sub-scenario id
+ * @param shortName a short (shorter than 40 characters) descriptive
+ * name of the scenario
+ * @param dimension the dimension to show in the summary
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeterForSummary(String subScenarioId, String shortName, Dimension dimension) {
+ PerformanceMeter performanceMeter= createPerformanceMeter(subScenarioId);
+ Performance.getDefault().tagAsSummary(performanceMeter, shortName, dimension);
+ return performanceMeter;
+ }
+
+ /**
+ * Create a performance meter with the base scenario id and mark the
+ * scenario to be included into the global performance summary. The
+ * summary shows the given dimension of the scenario and labels the
+ * scenario with the short name. The performance meter will be disposed
+ * on {@link #tearDown()}.
+ *
+ * @param shortName a short (shorter than 40 characters) descriptive
+ * name of the scenario
+ * @param dimension the dimension to show in the summary
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeterForGlobalSummary(String shortName, Dimension dimension) {
+ return createPerformanceMeterForGlobalSummary("", shortName, dimension);
+ }
+
+ /**
+ * Create a performance meter with the given sub-scenario id and mark
+ * the scenario to be included into the global performance summary. The
+ * summary shows the given dimension of the scenario and labels the
+ * scenario with the short name. The performance meter will be disposed
+ * on {@link #tearDown()}.
+ *
+ * @param subScenarioId the sub-scenario id
+ * @param shortName a short (shorter than 40 characters) descriptive
+ * name of the scenario
+ * @param dimension the dimension to show in the summary
+ * @return the created performance meter
+ */
+ protected final PerformanceMeter createPerformanceMeterForGlobalSummary(String subScenarioId, String shortName, Dimension dimension) {
+ PerformanceMeter performanceMeter= createPerformanceMeter(subScenarioId);
+ Performance.getDefault().tagAsGlobalSummary(performanceMeter, shortName, dimension);
+ return performanceMeter;
+ }
+
+ /**
+ * Create an invocation counting performance meter that will count the
+ * number of invocations of the given methods. The performance meter
+ * will be disposed on {@link #tearDown()}.
+ *
+ * @param methods the methods whose invocations will be counted
+ * @return the created performance meter
+ */
+ protected final InvocationCountPerformanceMeter createInvocationCountPerformanceMeter(Method[] methods) {
+ return createInvocationCountPerformanceMeter("", methods);
+ }
+
+ /**
+ * Create an invocation counting performance meter with the given
+ * sub-scenario id. The performance meter will count the number of
+ * invocations of the given methods. The performance meter will be
+ * disposed on {@link #tearDown()}.
+ *
+ * @param subScenarioId the sub-scenario id
+ * @param methods the methods whose invocations will be counted
+ * @return the created performance meter
+ */
+ protected final InvocationCountPerformanceMeter createInvocationCountPerformanceMeter(String subScenarioId, Method[] methods) {
+ InvocationCountPerformanceMeter performanceMeter= new InvocationCountPerformanceMeter(getBaseScenarioId() + subScenarioId, methods);
+ addPerformanceMeter(performanceMeter);
+ return performanceMeter;
+ }
+
+ /**
+ * Create an invocation counting performance meter that will count the
+ * number of invocations of the given constructors. The performance meter
+ * will be disposed on {@link #tearDown()}.
+ *
+ * @param constructors the constructors whose invocations will be counted
+ * @return the created performance meter
+ */
+ protected final InvocationCountPerformanceMeter createInvocationCountPerformanceMeter(Constructor[] constructors) {
+ return createInvocationCountPerformanceMeter("", constructors);
+ }
+
+ /**
+ * Create an invocation counting performance meter with the given
+ * sub-scenario id. The performance meter will count the number of
+ * invocations of the given constructors. The performance meter will be
+ * disposed on {@link #tearDown()}.
+ *
+ * @param subScenarioId the sub-scenario id
+ * @param constructors the constructors whose invocations will be counted
+ * @return the created performance meter
+ */
+ protected final InvocationCountPerformanceMeter createInvocationCountPerformanceMeter(String subScenarioId, Constructor[] constructors) {
+ InvocationCountPerformanceMeter performanceMeter= new InvocationCountPerformanceMeter(getBaseScenarioId() + subScenarioId, constructors);
+ addPerformanceMeter(performanceMeter);
+ return performanceMeter;
+ }
+
+ /**
+ * Commits the measurements captured by all performance meters created
+ * through one of this class' factory methods.
+ */
+ protected final void commitAllMeasurements() {
+ if (fPerformanceMeters != null)
+ for (Iterator iter= fPerformanceMeters.iterator(); iter.hasNext();)
+ ((PerformanceMeter) iter.next()).commit();
+ }
+
+ /**
+ * Asserts default properties of the measurements captured by the given
+ * performance meter.
+ *
+ * @param performanceMeter the performance meter
+ * @throws RuntimeException if the properties do not hold
+ */
+ protected final void assertPerformance(PerformanceMeter performanceMeter) {
+ Performance.getDefault().assertPerformance(performanceMeter);
+ }
+
+ /**
+ * Asserts default properties of the measurements captured by all
+ * performance meters created through one of this class' factory
+ * methods.
+ *
+ * @throws RuntimeException if the properties do not hold
+ */
+ protected final void assertAllPerformance() {
+ if (fPerformanceMeters != null)
+ for (Iterator iter= fPerformanceMeters.iterator(); iter.hasNext();)
+ assertPerformance((PerformanceMeter) iter.next());
+ }
+
+ /**
+ * Returns the null performance meter singleton.
+ *
+ * @return the null performance meter singleton
+ */
+ protected static final PerformanceMeter getNullPerformanceMeter() {
+ return Performance.getDefault().getNullPerformanceMeter();
+ }
+
+ /**
+ * Returns the keyboard probe singleton.
+ *
+ * @return the keyboard probe singleton.
+ */
+ protected static final KeyboardProbe getKeyboardProbe() {
+ if (fgKeyboardProbe == null) {
+ fgKeyboardProbe= new KeyboardProbe();
+ fgKeyboardProbe.initialize();
+ }
+ return fgKeyboardProbe;
+ }
+
+ /**
+ * Create a performance meter with the given scenario id. The
+ * performance meter will be disposed on {@link #tearDown()}.
+ *
+ * @param scenarioId the scenario id
+ * @return the created performance meter
+ */
+ private PerformanceMeter internalCreatePerformanceMeter(String scenarioId) {
+ PerformanceMeter performanceMeter= Performance.getDefault().createPerformanceMeter(scenarioId);
+ addPerformanceMeter(performanceMeter);
+ return performanceMeter;
+ }
+
+ /**
+ * Add the given performance meter to the managed performance meters.
+ *
+ * @param performanceMeter the performance meter
+ */
+ private void addPerformanceMeter(PerformanceMeter performanceMeter) {
+ if (fPerformanceMeters == null)
+ fPerformanceMeters= new ArrayList();
+ fPerformanceMeters.add(performanceMeter);
+ }
+
+ /**
+ * Returns the integer value of the given string unless the string
+ * cannot be interpreted as such, in this case the given default is
+ * returned.
+ *
+ * @param stringValue the string to be interpreted as integer
+ * @param defaultValue the default integer value
+ * @return the integer value
+ */
+ private static int intValueOf(String stringValue, int defaultValue) {
+ try {
+ if (stringValue != null)
+ return Integer.valueOf(stringValue).intValue();
+ } catch (NumberFormatException e) {
+ // use default
+ }
+ return defaultValue;
+ }
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ToggleCommentTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ToggleCommentTest.java
index ed5e3aa..61ce8c8 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ToggleCommentTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ToggleCommentTest.java
@@ -13,29 +13,28 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
import org.eclipse.jface.action.IAction;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+/**
+ * Measures the time to comment/uncomment a large compilation unit.
+ *
+ * @since 3.1
+ */
public class ToggleCommentTest extends TextPerformanceTestCase {
private static final Class THIS= ToggleCommentTest.class;
- private static final String FILE= "org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java";
+ private static final String FILE= PerformanceTestSetup.STYLED_TEXT;
private static final int WARM_UP_RUNS= 3;
private static final int MEASURED_RUNS= 3;
- private PerformanceMeter fCommentMeter;
-
- private PerformanceMeter fUncommentMeter;
-
private ITextEditor fEditor;
public static Test suite() {
@@ -43,9 +42,7 @@
}
protected void setUp() throws Exception {
- Performance performance= Performance.getDefault();
- fCommentMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this, "comment"));
- fUncommentMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this, "uncomment"));
+ super.setUp();
fEditor= (ITextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(FILE), true);
runAction(fEditor.getAction(ITextEditorActionConstants.SELECT_ALL));
setWarmUpRuns(WARM_UP_RUNS);
@@ -53,38 +50,34 @@
}
protected void tearDown() throws Exception {
+ super.tearDown();
EditorTestHelper.closeAllEditors();
- fCommentMeter.dispose();
- fUncommentMeter.dispose();
}
- public void testToggleComment2() throws PartInitException {
- // warm run
- measureToggleComment();
+ /**
+ * Measures the time to comment/uncomment a large compilation unit.
+ */
+ public void testToggleComment2() {
+ measureToggleComment(getNullPerformanceMeter(), getNullPerformanceMeter(), getWarmUpRuns());
+ PerformanceMeter commentMeter= createPerformanceMeter("-comment");
+ PerformanceMeter uncommentMeter= createPerformanceMeter("-uncomment");
+ measureToggleComment(commentMeter, uncommentMeter, getMeasuredRuns());
+ commitAllMeasurements();
+ assertAllPerformance();
}
- private void measureToggleComment() throws PartInitException {
+ private void measureToggleComment(PerformanceMeter commentMeter, PerformanceMeter uncommentMeter, int runs) {
IAction toggleComment= fEditor.getAction("ToggleComment");
- int warmUpRuns= getWarmUpRuns();
- int measuredRuns= getMeasuredRuns();
- for (int i= 0; i < warmUpRuns + measuredRuns; i++) {
- if (i >= warmUpRuns)
- fCommentMeter.start();
+ for (int i= 0; i < runs; i++) {
+ commentMeter.start();
runAction(toggleComment);
- if (i >= warmUpRuns)
- fCommentMeter.stop();
+ commentMeter.stop();
EditorTestHelper.runEventQueue(5000);
- if (i >= warmUpRuns)
- fUncommentMeter.start();
+ uncommentMeter.start();
runAction(toggleComment);
- if (i >= warmUpRuns)
- fUncommentMeter.stop();
+ uncommentMeter.stop();
EditorTestHelper.runEventQueue(5000);
}
- fCommentMeter.commit();
- fUncommentMeter.commit();
- Performance.getDefault().assertPerformance(fCommentMeter);
- Performance.getDefault().assertPerformance(fUncommentMeter);
}
private void runAction(IAction action) {
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TypingInvocationCountTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TypingInvocationCountTest.java
index b24a5a4..7b2bf11 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TypingInvocationCountTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TypingInvocationCountTest.java
@@ -31,7 +31,6 @@
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.AnnotationPreference;
-import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
@@ -88,11 +87,12 @@
fJavaProject= JavaCore.create(ResourceTestHelper.getProject(PROJECT));
fWasSearchViewShown= EditorTestHelper.isViewShown(SEARCH_VIEW);
- ITextEditor editor= (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(getFile()), true);
+ AbstractTextEditor editor= (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(getFile()), true);
FindAction action= new FindReferencesAction(editor.getSite());
ICompilationUnit unit= JavaCore.createCompilationUnitFrom(ResourceTestHelper.findFile(getFile()));
IMethod method= unit.getType("Test").getMethod("test", new String[] { });
action.run(method);
+ EditorTestHelper.joinBackgroundActivities(editor);
EditorTestHelper.closeAllEditors();
super.setUp();
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/UndoEditorTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/UndoEditorTest.java
index fb86cd5..88ed034 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/UndoEditorTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/UndoEditorTest.java
@@ -27,12 +27,14 @@
private PerformanceMeter fPerformanceMeter;
protected void setUp() throws Exception {
+ super.setUp();
Performance performance= Performance.getDefault();
fPerformanceMeter= performance.createPerformanceMeter(performance.getDefaultScenarioId(this));
EditorTestHelper.runEventQueue();
}
protected void tearDown() throws Exception {
+ super.tearDown();
EditorTestHelper.closeAllEditors();
fPerformanceMeter.dispose();
}
diff --git a/org.eclipse.jdt.text.tests/test.xml b/org.eclipse.jdt.text.tests/test.xml
index a4dbdbc..91479e9 100644
--- a/org.eclipse.jdt.text.tests/test.xml
+++ b/org.eclipse.jdt.text.tests/test.xml
@@ -35,34 +35,50 @@
<!-- This target defines the performance tests that need to be run. -->
<target name="performance-suite">
- <property name="jdt-text-performance-folder"
- value="${eclipse-home}/jdt_text_performance_folder"/>
+ <property name="jdt-text-performance-folder" value="${eclipse-home}/jdt_text_performance_folder"/>
<delete dir="${jdt-text-performance-folder}" quiet="true"/>
+
<ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="timeout" value="5400000"/>
<property name="vmargs" value="-Xms250M -Xmx250M"/>
<property name="data-dir" value="${jdt-text-performance-folder}"/>
<property name="plugin-name" value="${plugin-name}"/>
- <property name="classname"
- value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite"/>
</ant>
+
<ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
<property name="vmargs" value="-Xms250M -Xmx250M"/>
<property name="data-dir" value="${jdt-text-performance-folder}"/>
<property name="plugin-name" value="${plugin-name}"/>
- <property name="classname" value="org.eclipse.jdt.text.tests.performance.OpenJavaEditorTest"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite2"/>
</ant>
+
<ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
<property name="vmargs" value="-Xms250M -Xmx250M"/>
<property name="data-dir" value="${jdt-text-performance-folder}"/>
<property name="plugin-name" value="${plugin-name}"/>
- <property name="classname" value="org.eclipse.jdt.text.tests.performance.OpenTextEditorTest"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite3"/>
</ant>
+
<ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
<property name="vmargs" value="-Xms250M -Xmx250M"/>
<property name="data-dir" value="${jdt-text-performance-folder}"/>
<property name="plugin-name" value="${plugin-name}"/>
- <property name="classname"
- value="org.eclipse.jdt.text.tests.performance.EventDrivenTestSuite"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite4"/>
+ </ant>
+
+ <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="vmargs" value="-Xms250M -Xmx250M"/>
+ <property name="data-dir" value="${jdt-text-performance-folder}"/>
+ <property name="plugin-name" value="${plugin-name}"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.PerformanceTestSuite5"/>
+ </ant>
+
+ <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="vmargs" value="-Xms250M -Xmx250M -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=7777,suspend=n,server=y -Declipse.perf.debugPort=7777"/>
+ <property name="data-dir" value="${jdt-text-performance-folder}"/>
+ <property name="plugin-name" value="${plugin-name}"/>
+ <property name="classname" value="org.eclipse.jdt.text.tests.performance.DebuggingPerformanceTestSuite"/>
</ant>
</target>