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.geom.Path2D; 29 import com.sun.javafx.geom.PathIterator; 30 import com.sun.javafx.sg.prism.NGPath; 31 import javafx.beans.property.DoubleProperty; 32 import javafx.beans.property.SimpleDoubleProperty; 33 import javafx.scene.Group; 34 import test.javafx.scene.NodeTest; 35 import javafx.scene.Scene; 36 import org.junit.Test; 37 38 import java.lang.reflect.Method; 39 import javafx.scene.shape.ArcTo; 40 import javafx.scene.shape.MoveTo; 41 import javafx.scene.shape.Path; 42 43 import static org.junit.Assert.*; 44 45 public class ArcToTest { 46 47 @Test public void testSetGetX() throws Exception { 48 TestUtils.testDoublePropertyGetterSetter(new ArcTo(), "x", 123.2, 0.0); 49 } 50 51 @Test public void testSetGetY() throws Exception { 52 TestUtils.testDoublePropertyGetterSetter(new ArcTo(), "y", 123.2, 0.0); 53 } 54 55 @Test public void testSetGetRadiusX() throws Exception { 56 TestUtils.testDoublePropertyGetterSetter(new ArcTo(), "radiusX", 123.2, 0.0); 57 } 58 59 @Test public void testSetGetRadiusY() throws Exception { 60 TestUtils.testDoublePropertyGetterSetter(new ArcTo(), "radiusY", 123.2, 0.0); 61 } 62 63 64 @Test public void testSetGetXAxisRotation() throws Exception { 65 TestUtils.testDoublePropertyGetterSetter(new ArcTo(), "xAxisRotation", 123.2, 0.0); 66 } 67 68 @Test public void testSetGetLargeArcFlag() throws Exception { 69 TestUtils.testBooleanPropertyGetterSetter(new ArcTo(), "largeArcFlag"); 70 } 71 72 @Test public void testSetGetSweepFlag() throws Exception { 73 TestUtils.testBooleanPropertyGetterSetter(new ArcTo(), "sweepFlag"); 74 } 75 76 //TODO test addTo 77 78 @Test public void testDoublePropertySynced_X() throws Exception { 79 checkSyncedProperty("x", Coords.X, 200.0); 80 } 81 82 @Test public void testDoublePropertySynced_Y() throws Exception { 83 checkSyncedProperty("y", Coords.Y, 200.0); 84 } 85 86 @Test public void toStringShouldReturnNonEmptyString() { 87 String s = new ArcTo().toString(); 88 assertNotNull(s); 89 assertFalse(s.isEmpty()); 90 } 91 92 private void checkSyncedProperty(String propertyName, Coords coord, double expected) 93 throws Exception { 94 95 ArcTo arcTo = new ArcTo(); 96 arcTo.setRadiusX(40.0);arcTo.setRadiusY(50.0); 97 arcTo.setX(100.0); arcTo.setY(90.0); 98 DoubleProperty v = new SimpleDoubleProperty(100.0); 99 Method m = ArcTo.class.getMethod(propertyName + "Property", new Class[] {}); 100 ((DoubleProperty)m.invoke(arcTo)).bind(v); 101 102 Path path = new Path(); 103 path.getElements().addAll(new MoveTo(1.0, 1.0), arcTo); 104 ((Group)new Scene(new Group()).getRoot()).getChildren().add(path); 105 106 v.set(expected); 107 NodeTest.syncNode(path); 108 109 //check 110 NGPath pgPath = path.impl_getPeer(); 111 Path2D geometry = pgPath.getGeometry(); 112 float[] coords = new float[6]; 113 PathIterator it = (PathIterator)geometry.getPathIterator(null); 114 it.next(); it.next(); //path contains [MoveTo], [CubicTo], [CubicTo], [MoveTo] 115 int segType = it.currentSegment(coords); 116 assertEquals(PathIterator.SEG_CUBICTO, segType); 117 assertEquals(expected, coords[coord.ordinal()], 0.001); 118 } 119 120 static enum Coords { 121 CONTROL_X1, 122 CONTROL_Y1, 123 CONTROL_X2, 124 CONTROL_Y2, 125 X, 126 Y 127 } 128 }