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 |
} |