diff options
Diffstat (limited to 'org.eclipse.ui.editors.tests/src')
-rw-r--r-- | org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java | 1 | ||||
-rw-r--r-- | org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java | 97 |
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 8542b65f533..1577fe96d22 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 00000000000..e04a7437d95 --- /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); + } + } +} |