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