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.NGArc;
  29 import com.sun.javafx.sg.prism.NGNode;
  30 import javafx.scene.NodeTest;
  31 
  32 import org.junit.Test;
  33 import static org.junit.Assert.*;
  34 
  35 public class ArcTest {
  36 
  37     @Test public void testPropertyPropagation_visible() throws Exception {
  38         final Arc node = new StubArc();
  39         NodeTest.testBooleanPropertyPropagation(node, "visible", false, true);
  40     }
  41 
  42     @Test public void testPropertyPropagation_centerX() throws Exception {
  43         final Arc node = new StubArc();
  44         NodeTest.testDoublePropertyPropagation(node, "centerX", 100, 200);
  45     }
  46 
  47     @Test public void testPropertyPropagation_centerY() throws Exception {
  48         final Arc node = new StubArc();
  49         NodeTest.testDoublePropertyPropagation(node, "centerY", 100, 200);
  50     }
  51 
  52     @Test public void testPropertyPropagation_radiusX() throws Exception {
  53         final Arc node = new StubArc();
  54         NodeTest.testDoublePropertyPropagation(node, "radiusX", 100, 200);
  55     }
  56 
  57     @Test public void testPropertyPropagation_radiusY() throws Exception {
  58         final Arc node = new StubArc();
  59         NodeTest.testDoublePropertyPropagation(node, "radiusY", 100, 200);
  60     }
  61 
  62     @Test public void testPropertyPropagation_startAngle() throws Exception {
  63         final Arc node = new StubArc();
  64         NodeTest.testDoublePropertyPropagation(node, "startAngle", "angleStart", 30, 60);
  65     }
  66 
  67     @Test public void testPropertyPropagation_length() throws Exception {
  68         final Arc node = new StubArc();
  69         NodeTest.testDoublePropertyPropagation(node, "length", "angleExtent", 30, 45);
  70     }
  71 
  72     @Test public void testBoundPropertySync_length() throws Exception {
  73         NodeTest.assertDoublePropertySynced(
  74                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
  75                 "length", "angleExtent", 100.0);
  76     }
  77 
  78     @Test public void testBoundProperySync_startAngle() throws Exception {
  79         NodeTest.assertDoublePropertySynced(
  80                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
  81                 "startAngle", "angleStart", 270.0);
  82     }
  83 
  84     @Test public void testBoundPropertySync_radiusY() throws Exception {
  85         NodeTest.assertDoublePropertySynced(
  86                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
  87                 "radiusY", "radiusY", 200.0);
  88     }
  89 
  90     @Test public void testBoundPropertySync_radiusX() throws Exception {
  91         NodeTest.assertDoublePropertySynced(
  92                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
  93                 "radiusX", "radiusX", 150.0);
  94     }
  95 
  96     @Test public void testBoundPropertySync_centerY() throws Exception {
  97         NodeTest.assertDoublePropertySynced(
  98                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
  99                 "centerY", "centerY", 250.0);
 100     }
 101 
 102     @Test public void testBoundPropertySync_centerX() throws Exception {
 103         NodeTest.assertDoublePropertySynced(
 104                 new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0),
 105                 "centerX", "centerX", 350.0);
 106     }
 107 
 108     @Test public void toStringShouldReturnNonEmptyString() {
 109         String s = new StubArc().toString();
 110         assertNotNull(s);
 111         assertFalse(s.isEmpty());
 112     }
 113 
 114     @Test public void testNullType() {
 115         // null type should not throw NPE
 116         Arc arc = new StubArc(10.0, 10.0, 100.0, 100.0, 0.0, 0.0);
 117         arc.setType(null);
 118         assertNull(arc.getType());
 119         assertNull(arc.typeProperty().get());
 120     }
 121 
 122     public final class StubArc extends Arc {
 123         public StubArc() {
 124             super();
 125         }
 126 
 127         public StubArc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length) {
 128             super(centerX, centerY, radiusX, radiusY, startAngle, length);
 129         }
 130 
 131         @Override
 132         protected NGNode impl_createPeer() {
 133             return new StubNGArc();
 134         }
 135     }
 136 
 137     public final class StubNGArc extends NGArc {
 138         private float cx, cy, rx, ry, start, extent;
 139         private ArcType type;
 140 
 141         @Override
 142         public void updateArc(float cx, float cy, float rx, float ry, float start, float extent, ArcType type) {
 143             super.updateArc(cx, cy, rx, ry, start, extent, type);
 144             this.cx = cx;
 145             this.cy = cy;
 146             this.rx = rx;
 147             this.ry = ry;
 148             this.start = start;
 149             this.extent = extent;
 150             this.type = type;
 151         }
 152 
 153         // all called via reflection
 154         public float getAngleExtent() {return extent;}
 155         public float getAngleStart() {return start;}
 156         public float getCenterX() {return cx;}
 157         public float getCenterY() {return cy;}
 158         public float getRadiusX() {return rx;}
 159         public float getRadiusY() {return ry;}
 160         public ArcType getArcType() { return type;}
 161     }
 162 }