### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.text.tests Index: src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java,v retrieving revision 1.34 diff -u -r1.34 ScrollEditorTest.java --- src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java 27 Apr 2005 17:19:01 -0000 1.34 +++ src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java 15 May 2008 08:12:23 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,19 +11,16 @@ package org.eclipse.jdt.text.tests.performance; -import org.eclipse.test.performance.Dimension; -import org.eclipse.test.performance.Performance; -import org.eclipse.test.performance.PerformanceMeter; - +import org.eclipse.jdt.text.tests.performance.DisplayWaiter.Timeout; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; - +import org.eclipse.test.performance.Dimension; +import org.eclipse.test.performance.Performance; +import org.eclipse.test.performance.PerformanceMeter; import org.eclipse.ui.texteditor.AbstractTextEditor; -import org.eclipse.jdt.text.tests.performance.DisplayWaiter.Timeout; - public abstract class ScrollEditorTest extends TextPerformanceTestCase { private static final int WARM_UP_RUNS= 3; @@ -134,6 +131,8 @@ } protected void setUp(AbstractTextEditor editor) throws Exception { } + + protected void assertEditor(AbstractTextEditor editor) throws Exception { } protected void measure(ScrollingMode mode) throws Exception { measure(mode, createPerformanceMeter(), getWarmUpRuns(), getMeasuredRuns()); @@ -142,10 +141,11 @@ protected void measure(ScrollingMode mode, PerformanceMeter performanceMeter, int warmUpRuns, int measuredRuns) throws Exception { AbstractTextEditor editor= null; try { - editor= (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(mode.getFile()), getEditor(), true); + editor= openEditor(mode); setUp(editor); StyledText text= (StyledText) editor.getAdapter(Control.class); EditorTestHelper.joinBackgroundActivities(editor); + assertEditor(editor); if (mode.isPressAndHoldCombo()) { measureHolding(text, mode, getNullPerformanceMeter(), warmUpRuns); measureHolding(text, mode, performanceMeter, measuredRuns); @@ -167,6 +167,10 @@ } } + protected AbstractTextEditor openEditor(ScrollingMode mode) throws Exception { + return (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(mode.getFile()), getEditor(), true); + } + protected abstract String getEditor(); private void measure(final StyledText text, ScrollingMode mode, PerformanceMeter performanceMeter, int runs) { Index: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRulerTest.java =================================================================== RCS file: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRulerTest.java diff -N src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRulerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRulerTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.text.tests.performance; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jdt.internal.ui.text.spelling.SpellingEngine; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.ui.editors.text.EditorsUI; +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.MarkerAnnotationPreferences; +import org.eclipse.ui.texteditor.spelling.SpellingService; + +/** + * @since 3.4 + */ +public abstract class ScrollVerticalRulerTest extends ScrollEditorTest { + + public static Test suite() { + TestSuite result= new TestSuite(); + + result.addTest(ScrollVerticalRuler100Test.suite()); + result.addTest(ScrollVerticalRuler1000Test.suite()); + result.addTest(ScrollVerticalRuler5000Test.suite()); + + return result; + } + + protected String getEditor() { + return EditorTestHelper.TEXT_EDITOR_ID; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + InstanceScope scope= new InstanceScope(); + IEclipsePreferences jdtNode= scope.getNode(JavaUI.ID_PLUGIN); + jdtNode.putInt(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD, 100000); + + boolean isInstalled= EditorsUI.getSpellingService().getSpellingEngineDescriptors().length > 0; + assertTrue("No spelling engine installed", isInstalled); + + IPreferenceStore store= EditorsUI.getPreferenceStore(); + store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED, true); + + IEclipsePreferences editorsNode= scope.getNode(EditorsUI.PLUGIN_ID); + + MarkerAnnotationPreferences markerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); + Iterator iterator= markerAnnotationPreferences.getAnnotationPreferences().iterator(); + while (iterator.hasNext()) { + AnnotationPreference pref= (AnnotationPreference) iterator.next(); + String preferenceKey= pref.getVerticalRulerPreferenceKey(); + if ("spellingIndicationInVerticalRuler".equals(preferenceKey)) { + editorsNode.putBoolean(preferenceKey, true); + String textPreferenceKey= pref.getTextPreferenceKey(); + editorsNode.putBoolean(textPreferenceKey, false); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#tearDown() + */ + protected void tearDown() throws Exception { + InstanceScope scope= new InstanceScope(); + IEclipsePreferences jdtNode= scope.getNode(JavaUI.ID_PLUGIN); + jdtNode.putInt(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD, 100); + + IPreferenceStore store= EditorsUI.getPreferenceStore(); + store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED, false); + + IEclipsePreferences editorsNode= scope.getNode(EditorsUI.PLUGIN_ID); + + MarkerAnnotationPreferences markerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); + Iterator iterator= markerAnnotationPreferences.getAnnotationPreferences().iterator(); + while (iterator.hasNext()) { + AnnotationPreference pref= (AnnotationPreference) iterator.next(); + String preferenceKey= pref.getVerticalRulerPreferenceKey(); + if ("spellingIndicationInVerticalRuler".equals(preferenceKey)) { + editorsNode.putBoolean(preferenceKey, false); + String textPreferenceKey= pref.getTextPreferenceKey(); + editorsNode.putBoolean(textPreferenceKey, true); + } + } + + + super.tearDown(); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#openEditor(org.eclipse.jdt.text.tests.performance.ScrollEditorTest.ScrollingMode) + */ + protected AbstractTextEditor openEditor(ScrollingMode mode) throws Exception { + IFile file= ResourceTestHelper.getProject(PerformanceTestSetup.PROJECT).getFile("faust.txt"); + if (!file.exists()) { + file.create(getFaustInputStream(), true, null); + } + + AbstractTextEditor result= (AbstractTextEditor) EditorTestHelper.openInEditor(file, true); + + IDocument document= EditorTestHelper.getDocument(result); + document.replace(0, document.getLength(), getFaust(getNumberOfAnnotations())); + + result.doSave(null); + + return result; + } + + private String getFaust(int numberOfLines) throws Exception { + String faust= FileTool.read(new InputStreamReader(getFaustInputStream())).toString(); + + IDocument document= new Document(faust); + int lineOffset= document.getLineOffset(numberOfLines); + return document.get(0, lineOffset); + } + + private InputStream getFaustInputStream() { + return AbstractDocumentPerformanceTest.class.getResourceAsStream("faust1.txt"); + } + + /* + * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#assertEditor(org.eclipse.ui.texteditor.AbstractTextEditor) + */ + protected void assertEditor(AbstractTextEditor editor) throws Exception { + super.assertEditor(editor); + + IAnnotationModel model= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); + int annotationCount= getAnnotationCount(model); + assertTrue("Expected annotation count is: " + getNumberOfAnnotations() + " but was: " + annotationCount, annotationCount >= getNumberOfAnnotations()); + } + + private int getAnnotationCount(IAnnotationModel model) { + int result= 0; + + Iterator iterator= model.getAnnotationIterator(); + while (iterator.hasNext()) { + iterator.next(); + result++; + } + + return result; + } + + /** + * @return the number of annotations to show in the vertical ruler + */ + protected abstract int getNumberOfAnnotations(); + +} Index: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler5000Test.java =================================================================== RCS file: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler5000Test.java diff -N src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler5000Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler5000Test.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.text.tests.performance; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * @since 3.4 + */ +public class ScrollVerticalRuler5000Test extends ScrollVerticalRulerTest { + + private static final Class THIS= ScrollVerticalRuler5000Test.class; + + public static Test suite() { + return new PerformanceTestSetup(new TestSuite(THIS)); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations() + */ + protected int getNumberOfAnnotations() { + return 5000; + } + + /** + * Measure the time spent while scrolling page wise in the text editor. + * + * @throws Exception + */ + public void testScrollTextEditorPageWise() throws Exception { + measure(PAGE_WISE); + } + + /** + * Measure the time spent while scrolling line wise in the text editor. + * + * @throws Exception + */ +// This test is too slow +// public void testScrollTextEditorLineWiseMoveCaret2() throws Exception { +// measure(LINE_WISE); +// } +} Index: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler1000Test.java =================================================================== RCS file: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler1000Test.java diff -N src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler1000Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler1000Test.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.text.tests.performance; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * @since 3.4 + */ +public class ScrollVerticalRuler1000Test extends ScrollVerticalRulerTest { + + private static final Class THIS= ScrollVerticalRuler1000Test.class; + + public static Test suite() { + return new PerformanceTestSetup(new TestSuite(THIS)); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations() + */ + protected int getNumberOfAnnotations() { + return 1000; + } + + /** + * Measure the time spent while scrolling page wise in the text editor. + * + * @throws Exception + */ + public void testScrollTextEditorPageWise() throws Exception { + measure(PAGE_WISE); + } + + /** + * Measure the time spent while scrolling line wise in the text editor. + * + * @throws Exception + */ + public void testScrollTextEditorLineWiseMoveCaret2() throws Exception { + measure(LINE_WISE); + } + +} Index: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler100Test.java =================================================================== RCS file: src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler100Test.java diff -N src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler100Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler100Test.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.text.tests.performance; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * @since 3.4 + */ +public class ScrollVerticalRuler100Test extends ScrollVerticalRulerTest { + + private static final Class THIS= ScrollVerticalRuler100Test.class; + + public static Test suite() { + return new PerformanceTestSetup(new TestSuite(THIS)); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations() + */ + protected int getNumberOfAnnotations() { + return 100; + } + + /** + * Measure the time spent while scrolling page wise in the text editor. + * + * @throws Exception + */ + public void testScrollTextEditorPageWise() throws Exception { + measure(PAGE_WISE); + } + + /** + * Measure the time spent while scrolling line wise in the text editor. + * + * @throws Exception + */ + public void testScrollTextEditorLineWiseMoveCaret2() throws Exception { + measure(LINE_WISE); + } + +}