Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-01-15 15:29:32 +0000
committerFlorian Thienel2016-01-15 15:29:32 +0000
commitaa3d4efa67143abb46e8220671b86ac2465c39de (patch)
tree87d3c2a8d1971d387ee0136776afd37fbda886c8 /org.eclipse.vex.core.tests
parent910e5013246ad3a3d3ac8a4ac07ac656cac53525 (diff)
downloadorg.eclipse.mylyn.docs.vex-aa3d4efa67143abb46e8220671b86ac2465c39de.tar.gz
org.eclipse.mylyn.docs.vex-aa3d4efa67143abb46e8220671b86ac2465c39de.tar.xz
org.eclipse.mylyn.docs.vex-aa3d4efa67143abb46e8220671b86ac2465c39de.zip
implement support for SWT clipboard
Signed-off-by: Florian Thienel <florian@thienel.org>
Diffstat (limited to 'org.eclipse.vex.core.tests')
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java57
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/swt/SwtClipboardTest.java24
2 files changed, 72 insertions, 9 deletions
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java
index 7883808f..dfb8ae5a 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java
@@ -11,12 +11,15 @@
package org.eclipse.vex.core.internal.widget;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.eclipse.vex.core.internal.io.UniversalTestDocument;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.core.provisional.dom.INode;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -36,12 +39,17 @@ public abstract class BaseClipboardTest {
clipboard = createClipboard();
}
+ @After
+ public void disposeClipboard() {
+ clipboard.dispose();
+ }
+
@Test
public void givenFirstParagraphSelected_cutSelection_shouldRemoveFirstParagraphFromDocument() throws Exception {
final IElement section = document.getSection(0);
final INode firstParagraph = section.children().first();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.cutSelection(editor);
assertNotSame(firstParagraph, section.children().first());
@@ -55,7 +63,7 @@ public abstract class BaseClipboardTest {
final INode secondParagraph = section.children().last();
final String firstParagraphContent = firstParagraph.getText();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.cutSelection(editor);
editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
clipboard.paste(editor);
@@ -71,7 +79,7 @@ public abstract class BaseClipboardTest {
final INode secondParagraph = section.children().last();
final String firstParagraphContent = firstParagraph.getText();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.copySelection(editor);
editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
clipboard.paste(editor);
@@ -87,7 +95,7 @@ public abstract class BaseClipboardTest {
final INode secondParagraph = section.children().last();
final String firstParagraphContent = firstParagraph.getText();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.copySelection(editor);
editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
clipboard.cutSelection(editor);
@@ -104,7 +112,7 @@ public abstract class BaseClipboardTest {
final INode secondParagraph = section.children().last();
final String firstParagraphContent = firstParagraph.getText();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.copySelection(editor);
editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
clipboard.copySelection(editor);
@@ -121,7 +129,7 @@ public abstract class BaseClipboardTest {
final INode secondParagraph = section.children().last();
final String firstParagraphContent = firstParagraph.getText();
- select(firstParagraph);
+ editor.select(firstParagraph);
clipboard.copySelection(editor);
editor.moveTo(secondParagraph.getEndPosition());
clipboard.pasteText(editor);
@@ -130,8 +138,39 @@ public abstract class BaseClipboardTest {
assertEquals(2, section.children().count());
}
- private void select(final INode node) {
- editor.moveTo(node.getStartPosition());
- editor.moveBy(1, true);
+ @Test
+ public void givenFirstParagraphSelected_copySelection_shouldIndicateContentAndTextContentAvailable() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+
+ editor.select(firstParagraph);
+ clipboard.copySelection(editor);
+
+ assertTrue("hasContent", clipboard.hasContent());
+ assertTrue("hasTextContent", clipboard.hasTextContent());
+ }
+
+ @Test
+ public void givenContentOfFirstParagraphSelected_copySelection_shouldIndicateContentAndTextContentAvailable() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+
+ editor.selectContentOf(firstParagraph);
+ clipboard.copySelection(editor);
+
+ assertTrue("hasContent", clipboard.hasContent());
+ assertTrue("hasTextContent", clipboard.hasTextContent());
+ }
+
+ @Test
+ public void givenSecondParagraphSelected_copySelection_shouldIndicateContentButNotTextContentAvailable() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode secondParagraph = section.children().last();
+
+ editor.select(secondParagraph);
+ clipboard.copySelection(editor);
+
+ assertTrue("hasContent", clipboard.hasContent());
+ assertFalse("hasTextContent", clipboard.hasTextContent());
}
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/swt/SwtClipboardTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/swt/SwtClipboardTest.java
new file mode 100644
index 00000000..548a9482
--- /dev/null
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/swt/SwtClipboardTest.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Florian Thienel and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.widget.swt;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.vex.core.internal.widget.BaseClipboardTest;
+import org.eclipse.vex.core.internal.widget.IClipboard;
+
+public class SwtClipboardTest extends BaseClipboardTest {
+
+ @Override
+ protected IClipboard createClipboard() {
+ return new SwtClipboard(Display.getDefault());
+ }
+
+}

Back to the top