Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorangelozerr2017-11-27 08:42:18 -0500
committerAlexander Kurtakov2017-11-28 06:54:38 -0500
commita4cb7c81445b00a02adfd21d141035f7a8c9520b (patch)
treeea13e82a2da81b388e18d0b0b24eb87f3f6d19df /tests
parentacb38af86ff1fb3900530a51d7d182dc984938e3 (diff)
downloadeclipse.platform.swt-a4cb7c81445b00a02adfd21d141035f7a8c9520b.tar.gz
eclipse.platform.swt-a4cb7c81445b00a02adfd21d141035f7a8c9520b.tar.xz
eclipse.platform.swt-a4cb7c81445b00a02adfd21d141035f7a8c9520b.zip
Bug 522020 - [API] Customize different line spacing of StyledText with
LineSpacingProvider Change-Id: I5c622f791b6561c1af080cc455343b15c0fba784 Signed-off-by: angelozerr <angelo.zerr@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java4
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java86
2 files changed, 88 insertions, 2 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java
index 0999110976..7b01385b8b 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java
@@ -41,8 +41,8 @@ import org.junit.runners.Suite;
Test_org_eclipse_swt_custom_StyleRange.class, Test_org_eclipse_swt_custom_CCombo.class,
Test_org_eclipse_swt_custom_TableTreeItem.class, Test_org_eclipse_swt_custom_CLabel.class,
Test_org_eclipse_swt_custom_CTabItem.class, Test_org_eclipse_swt_custom_StyledText.class,
- Test_org_eclipse_swt_custom_CTabFolder.class, Test_org_eclipse_swt_widgets_Spinner.class,
- Test_org_eclipse_swt_widgets_ScrolledComposite.class})
+ Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.class, Test_org_eclipse_swt_custom_CTabFolder.class,
+ Test_org_eclipse_swt_widgets_Spinner.class, Test_org_eclipse_swt_widgets_ScrolledComposite.class})
public class AllWidgetTests {
public static void main(String[] args) {
JUnitCore.main(AllWidgetTests.class.getName());
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java
new file mode 100644
index 0000000000..10816387f4
--- /dev/null
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ * 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:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
+ */
+package org.eclipse.swt.tests.junit;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.StyledTextLineSpacingProvider;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Automated Test Suite for class
+ * org.eclipse.swt.custom.StyledTextLineSpacingProvider
+ *
+ * @see org.eclipse.swt.custom.StyledTextLineSpacingProvider
+ */
+public class Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider {
+
+ class IntegerLineSpacingProvider implements StyledTextLineSpacingProvider {
+
+ @Override
+ public Integer getLineSpacing(int lineIndex) {
+ try {
+ String text = styledText.getLine(lineIndex);
+ return Integer.parseInt(text);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ };
+
+ Shell shell;
+ StyledText styledText;
+
+ @Before
+ public void setUp() {
+ shell = new Shell();
+ styledText = new StyledText(shell, SWT.NULL);
+ }
+
+ @Test
+ public void test_setLineSpacingProvider() {
+ styledText.setText("a\n45\nc\n57");
+ // Tests with none line spacing provider
+ assertLineSpacingEquals(0, 0, 0, 0, 0);
+ // Tests with integer line spacing provider
+ styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ // Tests with reset line spacing provider
+ styledText.setLineSpacingProvider(null);
+ assertLineSpacingEquals(0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void test_replaceTextRange() {
+ styledText.setText("a\n45\nc\n57");
+ styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ // Replace 45 with b
+ styledText.replaceTextRange(2, 2, "b");
+ assertLineSpacingEquals(0, 0, 0, 0, 57);
+ // Replace b with 45
+ styledText.replaceTextRange(2, 1, "45");
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ }
+
+ private void assertLineSpacingEquals(int... expecteds) {
+ int lineHeight = styledText.getLineHeight();
+ int[] actuals = new int[expecteds.length];
+ for (int i = 0; i < expecteds.length; i++) {
+ actuals[i] = styledText.getLinePixel(i) - ((i > 0) ? styledText.getLinePixel(i - 1) + lineHeight : 0);
+ }
+ assertArrayEquals(expecteds, actuals);
+ }
+}

Back to the top