< prev index next > modules/javafx.graphics/src/test/java/test/javafx/scene/text/TextTest.java
Print this page
/*
! * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
/*
! * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
package test.javafx.scene.text;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import javafx.geometry.VPos;
import test.javafx.scene.NodeTest;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
+ import javafx.scene.layout.HBox;
+ import javafx.scene.Scene;
+ import javafx.stage.Stage;
+
+ import test.com.sun.javafx.pgstub.StubToolkit;
+ import com.sun.javafx.tk.Toolkit;
import org.junit.Test;
public class TextTest {
@Test public void toStringShouldReturnNonEmptyString() {
String s = new Text().toString();
assertNotNull(s);
assertFalse(s.isEmpty());
}
+
+ // Test for JDK-8130738
+ @Test public void testTabSize() {
+ Toolkit tk = (StubToolkit)Toolkit.getToolkit();
+ HBox root = new HBox();
+ Scene scene = new Scene(root);
+ Stage stage = new Stage();
+ stage.setScene(scene);
+ stage.setWidth(300);
+ stage.setHeight(200);
+
+ try {
+ Text text = new Text("\tHello");
+ root.getChildren().addAll(text);
+ stage.show();
+ tk.firePulse();
+ assertEquals(text.getTabSize(),8);
+ // initial width with default 8-space tab
+ double widthT8 = text.getBoundsInLocal().getWidth();
+ text.setTabSize(1);
+ tk.firePulse();
+ // width with tab at 1 spaces
+ double widthT1 = text.getBoundsInLocal().getWidth();
+ // approximate width of a single space
+ double widthSpace = (widthT8 - widthT1) / 7;
+ assertTrue(widthSpace > 0);
+ text.setTabSize(4);
+ tk.firePulse();
+ // width with tab at 4 spaces
+ double widthT4 = text.getBoundsInLocal().getWidth();
+ double expected = widthT8 - 4 * widthSpace;
+ // should be approximately 4 space-widths shorter
+ assertEquals(expected, widthT4, 0.5);
+ } finally {
+ stage.hide();
+ }
+ }
}
< prev index next >