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.NGCubicCurve; 30 import com.sun.javafx.sg.prism.NGNode; 31 import javafx.scene.NodeTest; 32 import org.junit.Rule; 33 import org.junit.Test; 34 35 import static org.junit.Assert.*; 36 37 public class CubicCurveTest { 38 39 @Rule 40 public FXUnit fx = new FXUnit(); 41 42 @Test 43 public void testFullConstructor() { 44 final CubicCurve curve = new StubCubicCurve(1, 2, 3, 4, 5, 6, 7, 8); 45 assertEquals(1, curve.getStartX(), 0.00001); 46 assertEquals(2, curve.getStartY(), 0.00001); 47 assertEquals(3, curve.getControlX1(), 0.00001); 48 assertEquals(4, curve.getControlY1(), 0.00001); 49 assertEquals(5, curve.getControlX2(), 0.00001); 50 assertEquals(6, curve.getControlY2(), 0.00001); 51 assertEquals(7, curve.getEndX(), 0.00001); 52 assertEquals(8, curve.getEndY(), 0.00001); 53 } 54 55 @Test 56 public void testPropertyPropagation_visible() throws Exception { 57 final CubicCurve node = new StubCubicCurve(); 58 NodeTest.testBooleanPropertyPropagation(node, "visible", false, true); 59 } 60 61 @Test 62 public void testPropertyPropagation_startX() throws Exception { 63 final CubicCurve node = new StubCubicCurve(); 64 NodeTest.testDoublePropertyPropagation(node, "startX", "x1", 100, 200); 65 } 66 67 @Test 68 public void testPropertyPropagation_startY() throws Exception { 69 final CubicCurve node = new StubCubicCurve(); 70 NodeTest.testDoublePropertyPropagation(node, "startY", "y1", 100, 200); 71 } 72 73 @Test 74 public void testPropertyPropagation_controlX1() throws Exception { 75 final CubicCurve node = new StubCubicCurve(); 76 NodeTest.testDoublePropertyPropagation(node, "controlX1", "ctrlX1", 100, 200); 77 } 78 79 @Test 80 public void testPropertyPropagation_controlY1() throws Exception { 81 final CubicCurve node = new StubCubicCurve(); 82 NodeTest.testDoublePropertyPropagation(node, "controlY1", "ctrlY1", 100, 200); 83 } 84 85 @Test 86 public void testPropertyPropagation_controlX2() throws Exception { 87 final CubicCurve node = new StubCubicCurve(); 88 NodeTest.testDoublePropertyPropagation(node, "controlX2", "ctrlX2", 100, 200); 89 } 90 91 @Test 92 public void testPropertyPropagation_controlY2() throws Exception { 93 final CubicCurve node = new StubCubicCurve(); 94 NodeTest.testDoublePropertyPropagation(node, "controlY2", "ctrlY2", 100, 200); 95 } 96 97 @Test 98 public void testPropertyPropagation_endX() throws Exception { 99 final CubicCurve node = new StubCubicCurve(); 100 NodeTest.testDoublePropertyPropagation(node, "endX", "x2", 100, 200); 101 } 102 103 @Test 104 public void testPropertyPropagation_endY() throws Exception { 105 final CubicCurve node = new StubCubicCurve(); 106 NodeTest.testDoublePropertyPropagation(node, "endY", "y2", 100, 200); 107 } 108 109 @Test public void testBoundPropertySync_startX() throws Exception { 110 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 111 "startX", "x1", 50.0); 112 } 113 114 @Test public void testBoundPropertySync_startY() throws Exception { 115 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 116 "startY", "y1", 50.0); 117 } 118 119 @Test public void testBoundPropertySync_controlX1() throws Exception { 120 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 121 "controlX1", "ctrlX1", 100.0); 122 } 123 124 @Test public void testBoundPropertySync_controlY1() throws Exception { 125 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 126 "controlY1", "ctrlY1", 100.0); 127 } 128 129 @Test public void testBoundPropertySync_controlX2() throws Exception { 130 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 131 "controlX2", "ctrlX2", 200.0); 132 } 133 134 @Test public void testBoundPropertySync_controlY2() throws Exception { 135 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 136 "controlY2", "ctrlY2", 123.0); 137 } 138 139 @Test public void testBoundPropertySync_endX() throws Exception { 140 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 141 "endX", "x2", 300.0); 142 } 143 144 @Test public void testBoundPropertySync_endY() throws Exception { 145 NodeTest.assertDoublePropertySynced(new StubCubicCurve(), 146 "endY", "y2", 300.0); 147 } 148 149 @Test public void toStringShouldReturnNonEmptyString() { 150 String s = new StubCubicCurve().toString(); 151 assertNotNull(s); 152 assertFalse(s.isEmpty()); 153 } 154 155 public class StubCubicCurve extends CubicCurve { 156 public StubCubicCurve() { 157 super(); 158 } 159 160 public StubCubicCurve(double startX, double startY, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY) { 161 super(startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY); 162 } 163 164 @Override 165 protected NGNode impl_createPeer() { 166 return new StubNGCubicCurve(); 167 } 168 } 169 170 public class StubNGCubicCurve extends NGCubicCurve { 171 private float x1; 172 private float y1; 173 private float x2; 174 private float y2; 175 private float ctrlX1; 176 private float ctrlY1; 177 private float ctrlX2; 178 private float ctrlY2; 179 180 public float getCtrlX1() {return ctrlX1;} 181 public float getCtrlX2() {return ctrlX2;} 182 public float getCtrlY1() {return ctrlY1;} 183 public float getCtrlY2() {return ctrlY2;} 184 public float getX1() {return x1;} 185 public float getX2() {return x2;} 186 public float getY1() {return y1;} 187 public float getY2() {return y2;} 188 189 @Override 190 public void updateCubicCurve(float x1, float y1, float x2, float y2, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2) { 191 this.x1 = x1; 192 this.y1 = y1; 193 this.x2 = x2; 194 this.y2 = y2; 195 this.ctrlX1 = ctrlx1; 196 this.ctrlY1 = ctrly1; 197 this.ctrlX2 = ctrlx2; 198 this.ctrlY2 = ctrly2; 199 } 200 } 201 202 }