Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-01-24 16:37:06 -0500
committerPaul Pazderski2019-03-19 04:45:17 -0400
commita2bd5dd03d3f147f3577f01d5dcc4af083289a4a (patch)
treeb793014845985af04bbb178fb07cacce3c6052b7
parentcc50b4dc1661f9bb249b77b57ff4a362304ff143 (diff)
downloadeclipse.platform.text-a2bd5dd03d3f147f3577f01d5dcc4af083289a4a.tar.gz
eclipse.platform.text-a2bd5dd03d3f147f3577f01d5dcc4af083289a4a.tar.xz
eclipse.platform.text-a2bd5dd03d3f147f3577f01d5dcc4af083289a4a.zip
Bug 545530 - Test for TextViewer's default IDocumentAdapter
Test cases derived from IDocumentAdapter JavaDoc to check if TextViewer's default implementation of IDocumentAdapter adhere to its interface. Change-Id: I03d122e608662b6b65528c479910c797cf2397b1 Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.jface.text.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jface.text.tests/pom.xml2
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java73
3 files changed, 69 insertions, 8 deletions
diff --git a/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF b/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
index d39b0daf6..7194ac38c 100644
--- a/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.jface.text.tests
-Bundle-Version: 3.11.500.qualifier
+Bundle-Version: 3.11.600.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/org.eclipse.jface.text.tests/pom.xml b/org.eclipse.jface.text.tests/pom.xml
index 0e17c22b0..25643b9d0 100644
--- a/org.eclipse.jface.text.tests/pom.xml
+++ b/org.eclipse.jface.text.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.jface</groupId>
<artifactId>org.eclipse.jface.text.tests</artifactId>
- <version>3.11.500-SNAPSHOT</version>
+ <version>3.11.600-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
index 2374ead8d..2b2dd2e68 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014-2019 Google, Inc and others.
+ * Copyright (c) 2014, 2019 Google, Inc and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -9,14 +9,16 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
- * - Sergey Prigogin (Google) - initial API and implementation
- * - Mickael Istria (Red Hat Inc.) - [Bug 544708] Ctrl+Home
+ * Sergey Prigogin (Google) - initial API and implementation
+ * Mickael Istria (Red Hat Inc.) - [Bug 544708] Ctrl+Home
+ * Paul Pazderski - [Bug 545530] Test for TextViewer's default IDocumentAdapter implementation.
*******************************************************************************/
package org.eclipse.jface.text.tests;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeNotNull;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -25,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledTextContent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
@@ -35,6 +38,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.util.Util;
import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocumentAdapter;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
@@ -124,6 +128,65 @@ public class TextViewerTest {
}
}
+ /**
+ * Test if {@link TextViewer}s default {@link IDocumentAdapter} implementation adhere to
+ * {@link IDocumentAdapter}s JavaDoc.
+ */
+ @Test
+ public void testDefaultContentImplementation() {
+ final Shell shell= new Shell();
+ try {
+ final StyledTextContent content;
+ try {
+ final TextViewer textViewer= new TextViewer(shell, SWT.NONE);
+ textViewer.setDocument(new Document());
+ content= textViewer.getTextWidget().getContent();
+ } catch (Exception ex) {
+ fail("Failed to obtain default instance of TextViewers document adapter. " + ex.getMessage());
+ return;
+ }
+ assumeNotNull(content);
+
+ final String line0= "Hello ";
+ final String line1= "";
+ final String line2= "World!";
+ final String text= line0 + "\n" + line1 + "\r\n" + line2;
+ content.setText(text);
+ assertEquals("Get text range failed.", "H", content.getTextRange(0, 1));
+ assertEquals("Get text range failed.", "ll", content.getTextRange(2, 2));
+ assertEquals("Adapter content length wrong.", text.length(), content.getCharCount());
+ assertEquals("Adapter returned wrong content.", line0, content.getLine(0));
+ assertEquals("Adapter returned wrong content.", line1, content.getLine(1));
+ assertEquals("Adapter returned wrong content.", line2, content.getLine(2));
+
+ content.setText("\r\n\r\n");
+ assertEquals("Wrong line for offset.", 0, content.getLineAtOffset(0));
+ assertEquals("Wrong line for offset.", 0, content.getLineAtOffset(1));
+ assertEquals("Wrong line for offset.", 1, content.getLineAtOffset(2));
+ assertEquals("Wrong line for offset.", 1, content.getLineAtOffset(3));
+ assertEquals("Wrong line for offset.", 2, content.getLineAtOffset(4));
+ assertEquals("Wrong line for offset.", content.getLineCount() - 1, content.getLineAtOffset(content.getCharCount()));
+
+ content.setText(null);
+ assertEquals("Adapter returned wrong line count.", 1, content.getLineCount());
+ content.setText("");
+ assertEquals("Adapter returned wrong line count.", 1, content.getLineCount());
+ content.setText("a\n");
+ assertEquals("Adapter returned wrong line count.", 2, content.getLineCount());
+ content.setText("\n\n");
+ assertEquals("Adapter returned wrong line count.", 3, content.getLineCount());
+
+ content.setText("\r\ntest\r\n");
+ assertEquals("Wrong offset for line.", 0, content.getOffsetAtLine(0));
+ assertEquals("Wrong offset for line.", 2, content.getOffsetAtLine(1));
+ assertEquals("Wrong offset for line.", 8, content.getOffsetAtLine(2));
+ content.setText("");
+ assertEquals("Wrong offset for line.", 0, content.getOffsetAtLine(0));
+ } finally {
+ shell.dispose();
+ }
+ }
+
public static void ctrlEnd(ITextViewer viewer) {
postKeyEvent(viewer.getTextWidget(), SWT.END, SWT.CTRL, SWT.KeyDown);
}
@@ -150,7 +213,6 @@ public class TextViewerTest {
DisplayHelper.driveEventQueue(display);
}
-
public static String generate5000Lines() {
StringBuilder b = new StringBuilder("start");
for (int i = 0; i < 5000; i++) {
@@ -159,5 +221,4 @@ public class TextViewerTest {
b.append("end");
return b.toString();
}
-
}

Back to the top