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