Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-08-25 15:59:23 +0000
committerKai Maetzel2004-08-25 15:59:23 +0000
commit7a69832df245e1e0acbf4be4abfe6a42fc52da0e (patch)
treec73f146d164a3a494b27eadf434ab6e9921e2b9c /org.eclipse.ui.editors.tests/src
parent72363a44382c6651f83e8ebae97a32b5436c2f2d (diff)
downloadeclipse.platform.text-7a69832df245e1e0acbf4be4abfe6a42fc52da0e.tar.gz
eclipse.platform.text-7a69832df245e1e0acbf4be4abfe6a42fc52da0e.tar.xz
eclipse.platform.text-7a69832df245e1e0acbf4be4abfe6a42fc52da0e.zip
#70934, added SegmentedModeTest
Diffstat (limited to 'org.eclipse.ui.editors.tests/src')
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java1
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java97
2 files changed, 98 insertions, 0 deletions
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
index 8542b65f5..1577fe96d 100644
--- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
@@ -24,6 +24,7 @@ public class EditorsTestSuite extends TestSuite {
TestSuite suite = new TestSuite("Test Suite for org.eclipse.ui.editors"); //$NON-NLS-1$
//$JUnit-BEGIN$
suite.addTest(ChainedPreferenceStoreTest.suite());
+ suite.addTest(SegmentedModeTest.suite());
//$JUnit-END$
return suite;
}
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java
new file mode 100644
index 000000000..e04a7437d
--- /dev/null
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 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.ui.editors.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.filebuffers.tests.TestHelper;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+
+public class SegmentedModeTest extends TestCase {
+
+ private static final String ORIGINAL_CONTENT= "this\nis\nthe\ncontent\nof\nthe\nfile";
+
+ public static Test suite() {
+ return new TestSuite(SegmentedModeTest.class);
+ }
+
+ private IFile fFile;
+
+ private String getOriginalContent() {
+ return ORIGINAL_CONTENT;
+ }
+
+ /*
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ IFolder folder= TestHelper.createFolder("project/folderA/folderB/");
+ fFile= TestHelper.createFile(folder, "file.txt", getOriginalContent());
+ }
+
+ /*
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ TestHelper.deleteProject("project");
+ }
+
+ /*
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=70934
+ */
+ public void testSegmentation() {
+ IWorkbench workbench= PlatformUI.getWorkbench();
+ IWorkbenchPage page= workbench.getActiveWorkbenchWindow().getActivePage();
+ try {
+ IEditorPart part= IDE.openEditor(page, fFile);
+
+ try {
+ if (part instanceof ITextEditor) {
+ ITextEditor editor= (ITextEditor) part;
+
+ editor.showHighlightRangeOnly(true);
+ editor.setHighlightRange(5, 0, true);
+
+ Control control= (Control) part.getAdapter(Control.class);
+ if (control instanceof StyledText) {
+ StyledText styledText= (StyledText) control;
+ int caret= styledText.getCaretOffset();
+ styledText.replaceTextRange(caret, 0, "really ");
+
+ StringBuffer buffer= new StringBuffer(getOriginalContent());
+ buffer.insert(5, "really ");
+ IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ assertEquals(buffer.toString(), document.get());
+ }
+ }
+ } finally {
+ page.saveEditor(part, false);
+ }
+
+ } catch (PartInitException e) {
+ assertTrue(false);
+ }
+ }
+}

Back to the top