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