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.effect;
  27 
  28 import static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertNull;
  30 import javafx.scene.paint.Color;
  31 
  32 import org.junit.Before;
  33 import org.junit.Test;
  34 
  35 import com.sun.javafx.geom.RectBounds;
  36 import com.sun.javafx.tk.Toolkit;
  37 
  38 public class ColorInputTest extends EffectsTestBase {
  39     private ColorInput effect;
  40 
  41     @Before
  42     public void setUp() {
  43         effect = new ColorInput();
  44         setupTest(effect);
  45     }
  46 
  47     @Test
  48     public void testSetX() {
  49         // try setting correct value
  50         effect.setX(1.0f);
  51         assertEquals(1.0f, effect.getX(), 1e-100);
  52         pulse();
  53         assertEquals(1.0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinX(), 1e-100);
  54     }
  55 
  56     @Test
  57     public void testDefaultX() {
  58         // default value should be 0
  59         assertEquals(0, effect.getX(), 1e-100);
  60         assertEquals(0, effect.xProperty().get(), 1e-100);
  61         pulse();
  62         assertEquals(0, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinX(), 1e-100);
  63     }
  64 
  65     @Test
  66     public void testSetY() {
  67         // try setting correct value
  68         effect.setY(1.0f);
  69         assertEquals(1.0f, effect.getY(), 1e-100);
  70         pulse();
  71         assertEquals(1.0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinY(), 1e-100);
  72     }
  73 
  74     @Test
  75     public void testDefaultY() {
  76         // default value should be 0
  77         assertEquals(0, effect.getY(), 1e-100);
  78         assertEquals(0, effect.yProperty().get(), 1e-100);
  79         pulse();
  80         assertEquals(0, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinY(), 1e-100);
  81     }
  82 
  83     @Test
  84     public void testSetWidth() {
  85         // try setting correct value
  86         effect.setWidth(1.0f);
  87         assertEquals(1.0f, effect.getWidth(), 1e-100);
  88         pulse();
  89         assertEquals(1.0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getWidth(), 1e-100);
  90     }
  91 
  92     @Test
  93     public void testDefaultWidth() {
  94         // default value should be 0
  95         assertEquals(0, effect.getWidth(), 1e-100);
  96         assertEquals(0, effect.widthProperty().get(), 1e-100);
  97         pulse();
  98         assertEquals(0, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getWidth(), 1e-100);
  99     }
 100 
 101     @Test
 102     public void testSetHeight() {
 103         // try setting correct value
 104         effect.setHeight(1.0f);
 105         assertEquals(1.0f, effect.getHeight(), 1e-100);
 106         pulse();
 107         assertEquals(1.0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getHeight(), 1e-100);
 108     }
 109 
 110     @Test
 111     public void testDefaultHeight() {
 112         // default value should be 0
 113         assertEquals(0, effect.getHeight(), 1e-100);
 114         assertEquals(0, effect.heightProperty().get(), 1e-100);
 115         pulse();
 116         assertEquals(0, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getHeight(), 1e-100);
 117     }
 118      
 119     @Test
 120     public void testSetPaint() {
 121         // try setting correct value
 122         effect.setPaint(Color.BLUE);
 123         assertEquals(Color.BLUE, effect.getPaint());
 124         pulse();
 125         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.BLUE), ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getPaint());
 126     }
 127     
 128     @Test
 129     public void testDefaultPaint() {
 130         // default value should be RED
 131         assertEquals(Color.RED, effect.getPaint());
 132         assertEquals(Color.RED, effect.paintProperty().get());
 133         pulse();
 134         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.RED), ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getPaint());
 135     }
 136 
 137     @Test
 138     public void testNullPaint() {
 139         effect.setPaint(null);
 140         // null value should default to RED in render tree
 141         assertNull(effect.getPaint());
 142         assertNull(effect.paintProperty().get());
 143         pulse();
 144         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.RED), ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getPaint());
 145     }
 146 
 147     @Test
 148     public void testHeightSynced() throws Exception {
 149         RectBounds floodBounds = (RectBounds) getDoublePropertySynced(
 150                 "javafx.scene.effect.ColorInput", "height",
 151                 "com.sun.scenario.effect.Flood", "floodBounds", 10);
 152         assertEquals(10, floodBounds.getHeight(), 1e-100);
 153     }
 154 
 155     @Test
 156     public void testWidthSynced() throws Exception {
 157          RectBounds floodBounds = (RectBounds)  getDoublePropertySynced(
 158                 "javafx.scene.effect.ColorInput", "width",
 159                 "com.sun.scenario.effect.Flood", "floodBounds", 10);
 160          assertEquals(10, floodBounds.getWidth(), 1e-100);
 161     }
 162 
 163     @Test
 164     public void testXSynced() throws Exception {
 165          RectBounds floodBounds = (RectBounds)  getDoublePropertySynced(
 166                 "javafx.scene.effect.ColorInput", "x",
 167                 "com.sun.scenario.effect.Flood", "floodBounds", 10);
 168          assertEquals(10, floodBounds.getMinX(), 1e-100);
 169     }
 170 
 171     @Test
 172     public void testYSynced() throws Exception {
 173          RectBounds floodBounds = (RectBounds)  getDoublePropertySynced(
 174                 "javafx.scene.effect.ColorInput", "y",
 175                 "com.sun.scenario.effect.Flood", "floodBounds", 10);
 176          assertEquals(10, floodBounds.getMinY(), 1e-100);
 177     }
 178 
 179     @Test
 180     public void testPaintSynced() throws Exception {
 181         Object paint = getObjectPropertySynced(
 182                 "javafx.scene.effect.ColorInput", "paint",
 183                 "com.sun.scenario.effect.Flood", "paint",
 184                 Color.RED);
 185         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.RED), paint);
 186     }
 187 
 188     @Test
 189     public void testCreateWithParams() {
 190         effect = new ColorInput(1, 2, 3, 4, Color.BLUE);
 191         setupTest(effect);
 192         assertEquals(1, effect.getX(), 1e-100);
 193         assertEquals(2, effect.getY(), 1e-100);
 194         assertEquals(3, effect.getWidth(), 1e-100);
 195         assertEquals(4, effect.getHeight(), 1e-100);
 196         assertEquals(Color.BLUE, effect.getPaint());
 197         pulse();
 198         assertEquals(1f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinX(), 1e-100);
 199         assertEquals(2f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinY(), 1e-100);
 200         assertEquals(3f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getWidth(), 1e-100);
 201         assertEquals(4f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getHeight(), 1e-100);
 202         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.BLUE), ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getPaint());
 203     }
 204     
 205     @Test
 206     public void testCreateWithDefaultParams() {
 207         effect = new ColorInput(0, 0, 0, 0, Color.RED);
 208         setupTest(effect);
 209         assertEquals(0, effect.getX(), 1e-100);
 210         assertEquals(0, effect.getY(), 1e-100);
 211         assertEquals(0, effect.getWidth(), 1e-100);
 212         assertEquals(0, effect.getHeight(), 1e-100);
 213         assertEquals(Color.RED, effect.getPaint());
 214         pulse();
 215         assertEquals(0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinX(), 1e-100);
 216         assertEquals(0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getMinY(), 1e-100);
 217         assertEquals(0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getWidth(), 1e-100);
 218         assertEquals(0f, ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getFloodBounds().getHeight(), 1e-100);
 219         assertEquals(Toolkit.getPaintAccessor().getPlatformPaint(Color.RED), ((com.sun.scenario.effect.Flood) effect.impl_getImpl()).getPaint());
 220     }
 221 }