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