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 javafx.scene.paint.Color; 30 31 import org.junit.Before; 32 import org.junit.Rule; 33 import org.junit.Test; 34 import org.junit.rules.ExpectedException; 35 36 import com.sun.scenario.effect.Color4f; 37 38 public class SpotLightTest extends LightTestBase { 39 40 @Rule 41 public ExpectedException thrown = ExpectedException.none(); 42 private Light.Spot effect; 43 44 @Before 45 public void setUp() { 46 effect = new Light.Spot(); 47 setupTest(effect); 48 } 49 50 @Test 51 public void testSetPointsAtX() { 52 // try setting correct value 53 effect.setPointsAtX(1.0f); 54 assertEquals(1.0f, effect.getPointsAtX(), 1e-100); 55 pulse(); 56 assertEquals(1.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtX(), 1e-100); 57 } 58 59 @Test 60 public void testDefaultPointsAtX() { 61 // default value should be 0 62 assertEquals(0f, effect.getPointsAtX(), 1e-100); 63 assertEquals(0f, effect.pointsAtXProperty().get(), 1e-100); 64 pulse(); 65 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtX(), 1e-100); 66 } 67 68 @Test 69 public void testSetPointsAtY() { 70 // trPointsAtY setting correct value 71 effect.setPointsAtY(1.0f); 72 assertEquals(1.0f, effect.getPointsAtY(), 1e-100); 73 pulse(); 74 assertEquals(1.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtY(), 1e-100); 75 } 76 77 @Test 78 public void testDefaultPointsAtY() { 79 // default value should be 0 80 assertEquals(0f, effect.getPointsAtY(), 1e-100); 81 assertEquals(0f, effect.pointsAtYProperty().get(), 1e-100); 82 pulse(); 83 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtY(), 1e-100); 84 } 85 86 @Test 87 public void testSetPointsAtZ() { 88 // try setting correct value 89 effect.setPointsAtZ(1.0f); 90 assertEquals(1.0f, effect.getPointsAtZ(), 1e-100); 91 pulse(); 92 assertEquals(1.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtZ(), 1e-100); 93 } 94 95 @Test 96 public void testDefaultPointsAtZ() { 97 // default value should be 0 98 assertEquals(0f, effect.getPointsAtZ(), 1e-100); 99 assertEquals(0f, effect.pointsAtZProperty().get(), 1e-100); 100 pulse(); 101 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getPointsAtZ(), 1e-100); 102 } 103 104 @Test 105 public void testSetSpecularExponent() { 106 // try setting correct value 107 effect.setSpecularExponent(1.1f); 108 assertEquals(1.1f, effect.getSpecularExponent(), 1e-100); 109 pulse(); 110 assertEquals(1.1f, ((com.sun.scenario.effect.light.SpotLight)effect.impl_getImpl()).getSpecularExponent(), 1e-100); 111 } 112 113 @Test 114 public void testDefaultSpecularExponent() { 115 // default value should be 1 116 assertEquals(1f, effect.getSpecularExponent(), 1e-100); 117 assertEquals(1f, effect.specularExponentProperty().get(), 1e-100); 118 pulse(); 119 assertEquals(1f, ((com.sun.scenario.effect.light.SpotLight)effect.impl_getImpl()).getSpecularExponent(), 1e-100); 120 } 121 122 @Test 123 public void testMinSpecularExponent() { 124 // 0 should be ok 125 effect.setSpecularExponent(0); 126 // try setting value smaller than minimal 127 effect.setSpecularExponent(-0.1f); 128 assertEquals(-0.1f, effect.getSpecularExponent(), 1e-100); 129 pulse(); 130 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight)effect.impl_getImpl()).getSpecularExponent(), 1e-100); 131 } 132 133 @Test 134 public void testMaxSpecularExponent() { 135 // 4 should be ok 136 effect.setSpecularExponent(4); 137 // try setting value greater than maximal 138 effect.setSpecularExponent(4.1f); 139 assertEquals(4.1f, effect.getSpecularExponent(), 1e-100); 140 pulse(); 141 assertEquals(4f, ((com.sun.scenario.effect.light.SpotLight)effect.impl_getImpl()).getSpecularExponent(), 1e-100); 142 } 143 144 @Test 145 public void testPointsAtXSynced() throws Exception { 146 checkDoublePropertySynced( 147 effect, effect.impl_getImpl(), 148 "javafx.scene.effect.Light$Spot", "pointsAtX", 149 "com.sun.scenario.effect.light.SpotLight", "pointsAtX", 0.3); 150 } 151 152 @Test 153 public void testPointsAtYSynced() throws Exception { 154 checkDoublePropertySynced( 155 effect, effect.impl_getImpl(), 156 "javafx.scene.effect.Light$Spot", "pointsAtY", 157 "com.sun.scenario.effect.light.SpotLight", "pointsAtY", 0.3); 158 } 159 160 @Test 161 public void testSpecularExponentSynced() throws Exception { 162 checkDoublePropertySynced( 163 effect, effect.impl_getImpl(), 164 "javafx.scene.effect.Light$Spot", "specularExponent", 165 "com.sun.scenario.effect.light.SpotLight", "specularExponent", 0.3); 166 } 167 168 @Test 169 public void testPointsAtZSynced() throws Exception { 170 checkDoublePropertySynced( 171 effect, effect.impl_getImpl(), 172 "javafx.scene.effect.Light$Spot", "pointsAtZ", 173 "com.sun.scenario.effect.light.SpotLight", "pointsAtZ", 0.3); 174 } 175 176 @Test 177 public void testColorSynced() throws Exception { 178 Color color = Color.RED; 179 Color4f red = new Color4f((float) color.getRed(), (float) color.getGreen(), 180 (float) color.getBlue(), (float) color.getOpacity()); 181 Color4f result = (Color4f) getObjectPropertySynced( 182 effect, effect.impl_getImpl(), 183 "javafx.scene.effect.Light$Spot", "color", 184 "com.sun.scenario.effect.light.SpotLight", "color", 185 Color.RED); 186 assertColor4fEquals(red, result); 187 } 188 189 @Test 190 public void testCreateWithParams() { 191 effect = new Light.Spot(1, 2, 3, 4, Color.RED); 192 setupTest(effect); 193 assertEquals(1, effect.getX(), 1e-100); 194 assertEquals(2, effect.getY(), 1e-100); 195 assertEquals(3, effect.getZ(), 1e-100); 196 assertEquals(4, effect.getSpecularExponent(), 1e-100); 197 assertEquals(Color.RED, effect.getColor()); 198 pulse(); 199 assertEquals(1.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getX(), 1e-100); 200 assertEquals(2.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getY(), 1e-100); 201 assertEquals(3.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getZ(), 1e-100); 202 assertEquals(4.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getSpecularExponent(), 1e-100); 203 Color4f c = ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getColor(); 204 assertEquals(1f, c.getRed(), 1e-5); 205 assertEquals(0f, c.getGreen(), 1e-5); 206 assertEquals(0f, c.getBlue(), 1e-5); 207 assertEquals(1f, c.getAlpha(), 1e-5); 208 } 209 210 @Test 211 public void testCreateWithDefaultParams() { 212 effect = new Light.Spot(0, 0, 0, 1, Color.WHITE); 213 setupTest(effect); 214 assertEquals(0, effect.getX(), 1e-100); 215 assertEquals(0, effect.getY(), 1e-100); 216 assertEquals(0, effect.getZ(), 1e-100); 217 assertEquals(1, effect.getSpecularExponent(), 1e-100); 218 assertEquals(Color.WHITE, effect.getColor()); 219 pulse(); 220 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getX(), 1e-100); 221 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getY(), 1e-100); 222 assertEquals(0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getZ(), 1e-100); 223 assertEquals(1.0f, ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getSpecularExponent(), 1e-100); 224 Color4f c = ((com.sun.scenario.effect.light.SpotLight) effect.impl_getImpl()).getColor(); 225 assertEquals(1f, c.getRed(), 1e-5); 226 assertEquals(1f, c.getGreen(), 1e-5); 227 assertEquals(1f, c.getBlue(), 1e-5); 228 assertEquals(1f, c.getAlpha(), 1e-5); 229 } 230 }