< prev index next >

modules/javafx.graphics/src/test/java/test/javafx/scene/text/TextTest.java

Print this page

  1 /*
  2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package test.javafx.scene.text;
 27 
 28 import static org.junit.Assert.assertEquals;
 29 import static org.junit.Assert.assertFalse;

 30 import static org.junit.Assert.assertNotNull;
 31 import javafx.geometry.VPos;
 32 import test.javafx.scene.NodeTest;
 33 import javafx.scene.text.Font;
 34 import javafx.scene.text.Text;






 35 
 36 import org.junit.Test;
 37 
 38 public class TextTest {
 39 
 40     @Test public void testCtors() {
 41         Text t1 = new Text();
 42         assertEquals("", t1.getText());
 43         Text t2 = new Text("test content");
 44         assertEquals("test content", t2.getText());
 45         Text t3 = new Text(10, 20, "2");
 46         assertEquals(10f, t3.getX(), 0);
 47         assertEquals(20f, t3.getY(), 0);
 48         assertEquals("2", t3.getText());
 49     }
 50 
 51     @Test public void testSettingNullText() {
 52         Text t = new Text();
 53         t.setText(null);
 54         assertEquals("", t.getText());

208 //                 "underline", "underline", true);
209 //     }
210 
211 //     @Test public void testBoundPropertySync_Strikethrough() throws Exception {
212 //         NodeTest.assertBooleanPropertySynced(
213 //                 new Text(1.0, 2.0, "The Text"),
214 //                 "strikethrough", "strikethrough", true);
215 //     }
216 
217 //     @Test public void testBoundPropertySync_TextAlignment() throws Exception {
218 //         NodeTest.assertObjectPropertySynced(
219 //                 new Text(1.0, 2.0, "The Text"),
220 //                 "textAlignment", "textAlignment", TextAlignment.RIGHT);
221 //     }
222 
223     @Test public void toStringShouldReturnNonEmptyString() {
224         String s = new Text().toString();
225         assertNotNull(s);
226         assertFalse(s.isEmpty());
227     }





































228 }

  1 /*
  2  * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package test.javafx.scene.text;
 27 
 28 import static org.junit.Assert.assertEquals;
 29 import static org.junit.Assert.assertFalse;
 30 import static org.junit.Assert.assertTrue;
 31 import static org.junit.Assert.assertNotNull;
 32 import javafx.geometry.VPos;
 33 import test.javafx.scene.NodeTest;
 34 import javafx.scene.text.Font;
 35 import javafx.scene.text.Text;
 36 import javafx.scene.layout.HBox;
 37 import javafx.scene.Scene;
 38 import javafx.stage.Stage;
 39 
 40 import test.com.sun.javafx.pgstub.StubToolkit;
 41 import com.sun.javafx.tk.Toolkit;
 42 
 43 import org.junit.Test;
 44 
 45 public class TextTest {
 46 
 47     @Test public void testCtors() {
 48         Text t1 = new Text();
 49         assertEquals("", t1.getText());
 50         Text t2 = new Text("test content");
 51         assertEquals("test content", t2.getText());
 52         Text t3 = new Text(10, 20, "2");
 53         assertEquals(10f, t3.getX(), 0);
 54         assertEquals(20f, t3.getY(), 0);
 55         assertEquals("2", t3.getText());
 56     }
 57 
 58     @Test public void testSettingNullText() {
 59         Text t = new Text();
 60         t.setText(null);
 61         assertEquals("", t.getText());

215 //                 "underline", "underline", true);
216 //     }
217 
218 //     @Test public void testBoundPropertySync_Strikethrough() throws Exception {
219 //         NodeTest.assertBooleanPropertySynced(
220 //                 new Text(1.0, 2.0, "The Text"),
221 //                 "strikethrough", "strikethrough", true);
222 //     }
223 
224 //     @Test public void testBoundPropertySync_TextAlignment() throws Exception {
225 //         NodeTest.assertObjectPropertySynced(
226 //                 new Text(1.0, 2.0, "The Text"),
227 //                 "textAlignment", "textAlignment", TextAlignment.RIGHT);
228 //     }
229 
230     @Test public void toStringShouldReturnNonEmptyString() {
231         String s = new Text().toString();
232         assertNotNull(s);
233         assertFalse(s.isEmpty());
234     }
235 
236     // Test for JDK-8130738
237     @Test public void testTabSize() {
238         Toolkit tk = (StubToolkit)Toolkit.getToolkit();
239         HBox root = new HBox();
240         Scene scene = new Scene(root);
241         Stage stage = new Stage();
242         stage.setScene(scene);
243         stage.setWidth(300);
244         stage.setHeight(200);
245 
246         try {
247             Text text = new Text("\tHello");
248             root.getChildren().addAll(text);
249             stage.show();
250             tk.firePulse();
251             assertEquals(text.getTabSize(),8);
252             // initial width with default 8-space tab
253             double widthT8 = text.getBoundsInLocal().getWidth();
254             text.setTabSize(1);
255             tk.firePulse();
256             // width with tab at 1 spaces
257             double widthT1 = text.getBoundsInLocal().getWidth();
258             // approximate width of a single space
259             double widthSpace = (widthT8 - widthT1) / 7;
260             assertTrue(widthSpace > 0);
261             text.setTabSize(4);
262             tk.firePulse();
263             // width with tab at 4 spaces
264             double widthT4 = text.getBoundsInLocal().getWidth();
265             double expected = widthT8 - 4 * widthSpace;
266             // should be approximately 4 space-widths shorter
267             assertEquals(expected, widthT4, 0.5);
268         } finally {
269             stage.hide();
270         }
271   }
272 }
< prev index next >