View | Details | Raw Unified | Return to bug 231863 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/text/tests/performance/ScrollEditorTest.java (-9 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-29 Link Here
11
11
12
package org.eclipse.jdt.text.tests.performance;
12
package org.eclipse.jdt.text.tests.performance;
13
13
14
import org.eclipse.test.performance.Dimension;
14
import org.eclipse.jdt.text.tests.performance.DisplayWaiter.Timeout;
15
import org.eclipse.test.performance.Performance;
16
import org.eclipse.test.performance.PerformanceMeter;
17
18
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.StyledText;
16
import org.eclipse.swt.custom.StyledText;
20
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.swt.widgets.Display;
22
19
import org.eclipse.test.performance.Dimension;
20
import org.eclipse.test.performance.Performance;
21
import org.eclipse.test.performance.PerformanceMeter;
23
import org.eclipse.ui.texteditor.AbstractTextEditor;
22
import org.eclipse.ui.texteditor.AbstractTextEditor;
24
23
25
import org.eclipse.jdt.text.tests.performance.DisplayWaiter.Timeout;
26
27
public abstract class ScrollEditorTest extends TextPerformanceTestCase {
24
public abstract class ScrollEditorTest extends TextPerformanceTestCase {
28
	
25
	
29
	private static final int WARM_UP_RUNS= 3;
26
	private static final int WARM_UP_RUNS= 3;
Lines 134-139 Link Here
134
	}
131
	}
135
132
136
	protected void setUp(AbstractTextEditor editor) throws Exception { }
133
	protected void setUp(AbstractTextEditor editor) throws Exception { }
134
135
	protected void assertEditor(AbstractTextEditor editor) throws Exception { }
137
	
136
	
138
	protected void measure(ScrollingMode mode) throws Exception {
137
	protected void measure(ScrollingMode mode) throws Exception {
139
		measure(mode, createPerformanceMeter(), getWarmUpRuns(), getMeasuredRuns());
138
		measure(mode, createPerformanceMeter(), getWarmUpRuns(), getMeasuredRuns());
Lines 142-151 Link Here
142
	protected void measure(ScrollingMode mode, PerformanceMeter performanceMeter, int warmUpRuns, int measuredRuns) throws Exception {
141
	protected void measure(ScrollingMode mode, PerformanceMeter performanceMeter, int warmUpRuns, int measuredRuns) throws Exception {
143
		AbstractTextEditor editor= null;
142
		AbstractTextEditor editor= null;
144
		try {
143
		try {
145
			editor= (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(mode.getFile()), getEditor(), true);
144
			editor= openEditor(mode);
146
			setUp(editor);
145
			setUp(editor);
147
			StyledText text= (StyledText) editor.getAdapter(Control.class);
146
			StyledText text= (StyledText) editor.getAdapter(Control.class);
148
			EditorTestHelper.joinBackgroundActivities(editor);
147
			EditorTestHelper.joinBackgroundActivities(editor);
148
			assertEditor(editor);
149
			if (mode.isPressAndHoldCombo()) {
149
			if (mode.isPressAndHoldCombo()) {
150
				measureHolding(text, mode, getNullPerformanceMeter(), warmUpRuns);
150
				measureHolding(text, mode, getNullPerformanceMeter(), warmUpRuns);
151
				measureHolding(text, mode, performanceMeter, measuredRuns);
151
				measureHolding(text, mode, performanceMeter, measuredRuns);
Lines 167-172 Link Here
167
		}
167
		}
168
	}
168
	}
169
169
170
	protected AbstractTextEditor openEditor(ScrollingMode mode) throws Exception {
171
		return (AbstractTextEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(mode.getFile()), getEditor(), true);
172
	}
173
170
	protected abstract String getEditor();
174
	protected abstract String getEditor();
171
175
172
	private void measure(final StyledText text, ScrollingMode mode, PerformanceMeter performanceMeter, int runs) {
176
	private void measure(final StyledText text, ScrollingMode mode, PerformanceMeter performanceMeter, int runs) {
(-)src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRulerTest.java (+174 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.text.tests.performance;
12
13
import java.io.InputStream;
14
import java.io.InputStreamReader;
15
import java.util.Iterator;
16
17
import junit.framework.Test;
18
import junit.framework.TestSuite;
19
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
22
import org.eclipse.core.runtime.preferences.InstanceScope;
23
import org.eclipse.jdt.internal.ui.text.spelling.SpellingEngine;
24
import org.eclipse.jdt.ui.JavaUI;
25
import org.eclipse.jface.preference.IPreferenceStore;
26
import org.eclipse.jface.text.Document;
27
import org.eclipse.jface.text.IDocument;
28
import org.eclipse.jface.text.source.IAnnotationModel;
29
import org.eclipse.ui.editors.text.EditorsUI;
30
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
31
import org.eclipse.ui.texteditor.AbstractTextEditor;
32
import org.eclipse.ui.texteditor.AnnotationPreference;
33
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
34
import org.eclipse.ui.texteditor.spelling.SpellingService;
35
36
/**
37
 * @since 3.4
38
 */
39
public abstract class ScrollVerticalRulerTest extends ScrollEditorTest {
40
	
41
	public static Test suite() {
42
		TestSuite result= new TestSuite();
43
		
44
		result.addTest(ScrollVerticalRuler100Test.suite());
45
		result.addTest(ScrollVerticalRuler1000Test.suite());
46
		result.addTest(ScrollVerticalRuler5000Test.suite());
47
		
48
		return result;
49
	}
50
	
51
	protected String getEditor() {
52
		return EditorTestHelper.TEXT_EDITOR_ID;
53
	}
54
	
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#setUp()
57
	 */
58
	protected void setUp() throws Exception {
59
		super.setUp();
60
		
61
		InstanceScope scope= new InstanceScope();
62
		IEclipsePreferences jdtNode= scope.getNode(JavaUI.ID_PLUGIN);
63
		jdtNode.putInt(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD, 100000);
64
		
65
		boolean isInstalled= EditorsUI.getSpellingService().getSpellingEngineDescriptors().length > 0;
66
		assertTrue("No spelling engine installed", isInstalled);
67
		
68
		IPreferenceStore store= EditorsUI.getPreferenceStore();
69
		store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED, true);
70
		
71
		IEclipsePreferences editorsNode= scope.getNode(EditorsUI.PLUGIN_ID);
72
		
73
		MarkerAnnotationPreferences markerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences();
74
		Iterator iterator= markerAnnotationPreferences.getAnnotationPreferences().iterator();
75
		while (iterator.hasNext()) {
76
			AnnotationPreference pref= (AnnotationPreference) iterator.next();
77
			String preferenceKey= pref.getVerticalRulerPreferenceKey();
78
			if ("spellingIndicationInVerticalRuler".equals(preferenceKey)) {
79
				editorsNode.putBoolean(preferenceKey, true);
80
				String textPreferenceKey= pref.getTextPreferenceKey();
81
				editorsNode.putBoolean(textPreferenceKey, false);
82
			}
83
		}
84
	}
85
	
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#tearDown()
88
	 */
89
	protected void tearDown() throws Exception {
90
		InstanceScope scope= new InstanceScope();
91
		IEclipsePreferences jdtNode= scope.getNode(JavaUI.ID_PLUGIN);
92
		jdtNode.putInt(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD, 100);
93
		
94
		IPreferenceStore store= EditorsUI.getPreferenceStore();
95
		store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED, false);
96
		
97
		IEclipsePreferences editorsNode= scope.getNode(EditorsUI.PLUGIN_ID);
98
		
99
		MarkerAnnotationPreferences markerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences();
100
		Iterator iterator= markerAnnotationPreferences.getAnnotationPreferences().iterator();
101
		while (iterator.hasNext()) {
102
			AnnotationPreference pref= (AnnotationPreference) iterator.next();
103
			String preferenceKey= pref.getVerticalRulerPreferenceKey();
104
			if ("spellingIndicationInVerticalRuler".equals(preferenceKey)) {
105
				editorsNode.putBoolean(preferenceKey, false);
106
				String textPreferenceKey= pref.getTextPreferenceKey();
107
				editorsNode.putBoolean(textPreferenceKey, true);
108
			}
109
		}
110
		
111
		
112
		super.tearDown();
113
	}
114
	
115
	/* (non-Javadoc)
116
	 * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#openEditor(org.eclipse.jdt.text.tests.performance.ScrollEditorTest.ScrollingMode)
117
	 */
118
	protected AbstractTextEditor openEditor(ScrollingMode mode) throws Exception {
119
		IFile file= ResourceTestHelper.getProject(PerformanceTestSetup.PROJECT).getFile("faust.txt");
120
		if (!file.exists()) {
121
			file.create(getFaustInputStream(), true, null);
122
		}
123
		
124
		AbstractTextEditor result= (AbstractTextEditor) EditorTestHelper.openInEditor(file, true);
125
		
126
		IDocument document= EditorTestHelper.getDocument(result);
127
		document.replace(0, document.getLength(), getFaust(getNumberOfAnnotations()));
128
		
129
		result.doSave(null);
130
		
131
		return result;
132
	}
133
	
134
	private String getFaust(int numberOfLines) throws Exception {
135
		String faust= FileTool.read(new InputStreamReader(getFaustInputStream())).toString();
136
		
137
		IDocument document= new Document(faust);
138
		int lineOffset= document.getLineOffset(numberOfLines);
139
		return document.get(0, lineOffset);
140
	}
141
	
142
	private InputStream getFaustInputStream() {
143
		return AbstractDocumentPerformanceTest.class.getResourceAsStream("faust1.txt");
144
	}
145
	
146
	/* 
147
	 * @see org.eclipse.jdt.text.tests.performance.ScrollEditorTest#assertEditor(org.eclipse.ui.texteditor.AbstractTextEditor)
148
	 */
149
	protected void assertEditor(AbstractTextEditor editor) throws Exception {
150
		super.assertEditor(editor);
151
		
152
		IAnnotationModel model= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
153
		int annotationCount= getAnnotationCount(model);
154
		assertTrue("Expected annotation count is: " + getNumberOfAnnotations() + " but was: " + annotationCount, annotationCount >= getNumberOfAnnotations());
155
	}
156
	
157
	private int getAnnotationCount(IAnnotationModel model) {
158
		int result= 0;
159
		
160
		Iterator iterator= model.getAnnotationIterator();
161
		while (iterator.hasNext()) {
162
			iterator.next();
163
			result++;
164
		}
165
		
166
		return result;
167
	}
168
169
	/**
170
	 * @return the number of annotations to show in the vertical ruler
171
	 */
172
	protected abstract int getNumberOfAnnotations();
173
	
174
}
(-)src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler5000Test.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.text.tests.performance;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
17
/**
18
 * @since 3.4
19
 */
20
public class ScrollVerticalRuler5000Test extends ScrollVerticalRulerTest {
21
	
22
	private static final Class THIS= ScrollVerticalRuler5000Test.class;
23
	
24
	public static Test suite() {
25
		return new PerformanceTestSetup(new TestSuite(THIS));
26
	}
27
	
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations()
30
	 */
31
	protected int getNumberOfAnnotations() {
32
		return 5000;
33
	}
34
	
35
	/**
36
	 * Measure the time spent while scrolling page wise in the text editor.
37
	 * 
38
	 * @throws Exception
39
	 */
40
	public void testScrollTextEditorPageWise() throws Exception {
41
		measure(PAGE_WISE);
42
	}
43
	
44
	/**
45
	 * Measure the time spent while scrolling line wise in the text editor.
46
	 * 
47
	 * @throws Exception
48
	 */
49
//	This test is too slow
50
//	public void testScrollTextEditorLineWiseMoveCaret2() throws Exception {
51
//		measure(LINE_WISE);
52
//	}
53
}
(-)src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler1000Test.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.text.tests.performance;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
17
/**
18
 * @since 3.4
19
 */
20
public class ScrollVerticalRuler1000Test extends ScrollVerticalRulerTest {
21
	
22
	private static final Class THIS= ScrollVerticalRuler1000Test.class;
23
	
24
	public static Test suite() {
25
		return new PerformanceTestSetup(new TestSuite(THIS));
26
	}
27
	
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations()
30
	 */
31
	protected int getNumberOfAnnotations() {
32
		return 1000;
33
	}
34
	
35
	/**
36
	 * Measure the time spent while scrolling page wise in the text editor.
37
	 * 
38
	 * @throws Exception
39
	 */
40
	public void testScrollTextEditorPageWise() throws Exception {
41
		measure(PAGE_WISE);
42
	}
43
	
44
	/**
45
	 * Measure the time spent while scrolling line wise in the text editor.
46
	 * 
47
	 * @throws Exception
48
	 */
49
	public void testScrollTextEditorLineWiseMoveCaret2() throws Exception {
50
		measure(LINE_WISE);
51
	}
52
	
53
}
(-)src/org/eclipse/jdt/text/tests/performance/ScrollVerticalRuler100Test.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.text.tests.performance;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
17
/**
18
 * @since 3.4
19
 */
20
public class ScrollVerticalRuler100Test extends ScrollVerticalRulerTest {
21
	
22
	private static final Class THIS= ScrollVerticalRuler100Test.class;
23
	
24
	public static Test suite() {
25
		return new PerformanceTestSetup(new TestSuite(THIS));
26
	}
27
	
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.jdt.text.tests.performance.ScrollVerticalRulerTest#getNumberOfAnnotations()
30
	 */
31
	protected int getNumberOfAnnotations() {
32
		return 100;
33
	}
34
	
35
	/**
36
	 * Measure the time spent while scrolling page wise in the text editor.
37
	 * 
38
	 * @throws Exception
39
	 */
40
	public void testScrollTextEditorPageWise() throws Exception {
41
		measure(PAGE_WISE);
42
	}
43
	
44
	/**
45
	 * Measure the time spent while scrolling line wise in the text editor.
46
	 * 
47
	 * @throws Exception
48
	 */
49
	public void testScrollTextEditorLineWiseMoveCaret2() throws Exception {
50
		measure(LINE_WISE);
51
	}
52
	
53
}

Return to bug 231863