1 /* 2 * Copyright (c) 2010, 2013, 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.shape; 27 28 import com.sun.javafx.sg.prism.NGEllipse; 29 import com.sun.javafx.sg.prism.NGNode; 30 import test.com.sun.javafx.test.TestHelper; 31 import javafx.geometry.Bounds; 32 import test.javafx.scene.NodeTest; 33 import javafx.scene.shape.Ellipse; 34 import org.junit.Test; 35 36 import static test.com.sun.javafx.test.TestHelper.assertSimilar; 37 import static org.junit.Assert.assertFalse; 38 import static org.junit.Assert.assertNotNull; 39 40 41 public class EllipseTest { 42 43 @Test public void testPropertyPropagation_visible() throws Exception { 44 final Ellipse node = new StubEllipse(); 45 NodeTest.testBooleanPropertyPropagation(node, "visible", false, true); 46 } 47 48 @Test public void testPropertyPropagation_centerX() throws Exception { 49 final Ellipse node = new StubEllipse(); 50 NodeTest.testDoublePropertyPropagation(node, "centerX", 100, 200); 51 } 52 53 @Test public void testPropertyPropagation_centerY() throws Exception { 54 final Ellipse node = new StubEllipse(); 55 NodeTest.testDoublePropertyPropagation(node, "centerY", 100, 200); 56 } 57 58 @Test public void testPropertyPropagation_radiusX() throws Exception { 59 final Ellipse node = new StubEllipse(); 60 NodeTest.testDoublePropertyPropagation(node, "radiusX", 100, 200); 61 } 62 63 @Test public void testPropertyPropagation_radiusY() throws Exception { 64 final Ellipse node = new StubEllipse(); 65 NodeTest.testDoublePropertyPropagation(node, "radiusY", 100, 200); 66 } 67 68 @Test public void testBoundPropertySync_radiusX() throws Exception { 69 NodeTest.assertDoublePropertySynced( 70 new StubEllipse(300.0, 300.0, 100.0, 100.0), 71 "radiusX", "radiusX", 150.0); 72 } 73 74 @Test public void testBoundPropertySync_radiusY() throws Exception { 75 NodeTest.assertDoublePropertySynced( 76 new StubEllipse(300.0, 300.0, 100.0, 100.0), 77 "radiusY", "radiusY", 150.0); 78 } 79 80 @Test public void testBoundPropertySync_centerX() throws Exception { 81 NodeTest.assertDoublePropertySynced( 82 new StubEllipse(300.0, 300.0, 100.0, 100.0), 83 "centerX", "centerX", 10.0); 84 } 85 86 @Test public void testBoundPropertySync_centerY() throws Exception { 87 NodeTest.assertDoublePropertySynced( 88 new StubEllipse(300.0, 300.0, 100.0, 100.0), 89 "centerY", "centerY", 10.0); 90 } 91 92 @Test 93 public void testTransformedBounds_rotation() { 94 Ellipse e = new StubEllipse(50, 100, 10, 20); 95 Bounds original = e.getBoundsInParent(); 96 e.setRotate(90); 97 assertSimilar(TestHelper.box(30, 90, 98 original.getHeight(), original.getWidth()), e.getBoundsInParent()); 99 } 100 101 @Test public void toStringShouldReturnNonEmptyString() { 102 String s = new StubEllipse().toString(); 103 assertNotNull(s); 104 assertFalse(s.isEmpty()); 105 } 106 107 public class StubEllipse extends Ellipse { 108 public StubEllipse() { 109 super(); 110 } 111 112 public StubEllipse(double radiusX, double radiusY) { 113 super(radiusX, radiusY); 114 } 115 116 public StubEllipse(double centerX, double centerY, double radiusX, double radiusY) { 117 super(centerX, centerY, radiusX, radiusY); 118 } 119 120 @Override 121 protected NGNode impl_createPeer() { 122 return new StubNGEllipse(); 123 } 124 } 125 126 public class StubNGEllipse extends NGEllipse { 127 private float centerX; 128 private float centerY; 129 private float radiusX; 130 private float radiusY; 131 132 public float getCenterX() {return centerX;} 133 public float getCenterY() {return centerY;} 134 public float getRadiusX() {return radiusX;} 135 public float getRadiusY() {return radiusY;} 136 137 @Override 138 public void updateEllipse(float cx, float cy, float rx, float ry) { 139 this.centerX = cx; 140 this.centerY = cy; 141 this.radiusX = rx; 142 this.radiusY = ry; 143 } 144 } 145 146 }