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 javafx.scene.shape; 27 28 import com.sun.javafx.FXUnit; 29 import com.sun.javafx.sg.prism.NGNode; 30 import com.sun.javafx.sg.prism.NGQuadCurve; 31 import javafx.scene.NodeTest; 32 import org.junit.Rule; 33 import org.junit.Test; 34 35 import static org.junit.Assert.assertFalse; 36 import static org.junit.Assert.assertNotNull; 37 38 39 public class QuadCurveTest { 40 41 @Rule 42 public FXUnit fx = new FXUnit(); 43 44 @Test public void testSetGetStartX() throws Exception { 45 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "startX", 123.2, 0.0); 46 } 47 48 @Test public void testSetGetStartY() throws Exception { 49 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "startY", 123.2, 0.0); 50 } 51 52 @Test public void testSetGetEndX() throws Exception { 53 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "endX", 123.2, 0.0); 54 } 55 56 @Test public void testSetGetEndY() throws Exception { 57 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "endY", 123.2, 0.0); 58 } 59 60 @Test public void testSetGetControlX() throws Exception { 61 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "controlX", 123.2, 0.0); 62 } 63 64 @Test public void testSetGetControlY() throws Exception { 65 TestUtils.testDoublePropertyGetterSetter(new StubQuadCurve(), "controlY", 123.2, 0.0); 66 } 67 68 @Test public void testPropertyPropagation_visible() throws Exception { 69 NodeTest.testBooleanPropertyPropagation(new StubQuadCurve(), "visible", false, true); 70 } 71 72 @Test public void testBoundPropertySync_startX() throws Exception { 73 NodeTest.assertDoublePropertySynced( 74 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 75 "startX", "x1", 30.0); 76 } 77 78 @Test public void testBoundPropertySync_startY() throws Exception { 79 NodeTest.assertDoublePropertySynced( 80 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 81 "startY", "y1", 30.0); 82 } 83 84 @Test public void testBoundPropertySync_controlX() throws Exception { 85 NodeTest.assertDoublePropertySynced( 86 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 87 "controlX", "ctrlX", 50.0); 88 } 89 90 @Test public void testBoundPropertySync_controlY() throws Exception { 91 NodeTest.assertDoublePropertySynced( 92 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 93 "controlY", "ctrlY", 50.0); 94 } 95 96 @Test public void testBoundPropertySync_endX() throws Exception { 97 NodeTest.assertDoublePropertySynced( 98 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 99 "endX", "x2", 300.0); 100 } 101 102 @Test public void testBoundPropertySync_endY() throws Exception { 103 NodeTest.assertDoublePropertySynced( 104 new StubQuadCurve(0.0 ,0.0, 10.0, 10.0, 100.0, 100.0), 105 "endY", "y2", 50.0); 106 } 107 108 @Test public void toStringShouldReturnNonEmptyString() { 109 String s = new StubQuadCurve().toString(); 110 assertNotNull(s); 111 assertFalse(s.isEmpty()); 112 } 113 114 public class StubQuadCurve extends QuadCurve { 115 public StubQuadCurve() { 116 super(); 117 } 118 119 public StubQuadCurve(double startX, double startY, double controlX, double controlY, double endX, double endY) { 120 super(startX, startY, controlX, controlY, endX, endY); 121 } 122 123 @Override 124 protected NGNode impl_createPeer() { 125 return new StubNGQuadCurve(); 126 } 127 } 128 129 public class StubNGQuadCurve extends NGQuadCurve { 130 private float x1, y1, x2, y2, ctrlX, ctrlY; 131 132 public float getCtrlX() { return ctrlX; } 133 public float getCtrlY() { return ctrlY; } 134 public float getX1() { return x1; } 135 public float getX2() { return x2; } 136 public float getY1() { return y1; } 137 public float getY2() { return y2; } 138 139 @Override 140 public void updateQuadCurve(float x1, float y1, float x2, float y2, float ctrlx, float ctrly) { 141 this.x1 = x1; 142 this.y1 = y1; 143 this.x2 = x2; 144 this.y2 = y2; 145 this.ctrlX = ctrlx; 146 this.ctrlY = ctrly; 147 } 148 149 public void setX1(float x1) {this.x1 = x1; } 150 public void setY1(float y1) {this.y1 = y1;} 151 public void setX2(float x2) {this.x2 = x2; } 152 public void setY2(float y2) {this.y2 = y2; } 153 public void setCtrlX(float ctrlx) {this.ctrlX = ctrlx; } 154 public void setCtrlY(float ctrly) {this.ctrlY = ctrly; } 155 } 156 157 }