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 test.javafx.scene.effect.LightTestBase; 29 import static org.junit.Assert.assertEquals; 30 import static org.junit.Assert.assertNull; 31 import javafx.scene.paint.Color; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 36 import com.sun.scenario.effect.Color4f; 37 import javafx.scene.effect.Light; 38 import javafx.scene.effect.LightShim; 39 40 public class DistantLightTest extends LightTestBase { 41 private Light.Distant effect; 42 43 @Before 44 public void setUp() { 45 effect = new Light.Distant(); 46 setupTest(effect); 47 } 48 49 @Test 50 public void testSetAzimuth() { 51 // try setting correct value 52 effect.setAzimuth(1.0f); 53 assertEquals(1.0f, effect.getAzimuth(), 1e-100); 54 pulse(); 55 assertEquals(1.0f, ((com.sun.scenario.effect.light.DistantLight) 56 LightShim.impl_getImpl(effect)).getAzimuth(), 1e-100); 57 } 58 59 @Test 60 public void testDefaultAzimuth() { 61 // default value should be 45 62 assertEquals(45f, effect.getAzimuth(), 1e-100); 63 assertEquals(45f, effect.azimuthProperty().get(), 1e-100); 64 pulse(); 65 assertEquals(45f, ((com.sun.scenario.effect.light.DistantLight) 66 LightShim.impl_getImpl(effect)).getAzimuth(), 1e-100); 67 } 68 69 @Test 70 public void testSetElevation() { 71 // try setting correct value 72 effect.setElevation(1.0f); 73 assertEquals(1.0f, effect.getElevation(), 1e-100); 74 pulse(); 75 assertEquals(1.0f, ((com.sun.scenario.effect.light.DistantLight) 76 LightShim.impl_getImpl(effect)).getElevation(), 1e-100); 77 } 78 79 @Test 80 public void testDefaultElevation() { 81 // default value should be 45 82 assertEquals(45f, effect.getElevation(), 1e-100); 83 assertEquals(45f, effect.elevationProperty().get(), 1e-100); 84 pulse(); 85 assertEquals(45f, ((com.sun.scenario.effect.light.DistantLight) 86 LightShim.impl_getImpl(effect)).getElevation(), 1e-100); 87 } 88 89 @Test 90 public void testSetColor() { 91 // try setting correct value 92 effect.setColor(Color.BLUE); 93 assertEquals(Color.BLUE, effect.getColor()); 94 pulse(); 95 Color4f c = ((com.sun.scenario.effect.light.DistantLight) 96 LightShim.impl_getImpl(effect)).getColor(); 97 assertEquals(0f, c.getRed(), 1e-5); 98 assertEquals(0f, c.getGreen(), 1e-5); 99 assertEquals(1f, c.getBlue(), 1e-5); 100 assertEquals(1f, c.getAlpha(), 1e-5); 101 } 102 103 @Test 104 public void testDefaultColor() { 105 // default value should be RED 106 assertEquals(Color.WHITE, effect.getColor()); 107 assertEquals(Color.WHITE, effect.colorProperty().get()); 108 pulse(); 109 Color4f c = ((com.sun.scenario.effect.light.DistantLight) 110 LightShim.impl_getImpl(effect)).getColor(); 111 assertEquals(1f, c.getRed(), 1e-5); 112 assertEquals(1f, c.getGreen(), 1e-5); 113 assertEquals(1f, c.getBlue(), 1e-5); 114 assertEquals(1f, c.getAlpha(), 1e-5); 115 } 116 117 @Test 118 public void testNullColor() { 119 // null value should default to WHITE in render tree 120 effect.setColor(null); 121 assertNull(effect.getColor()); 122 assertNull(effect.colorProperty().get()); 123 pulse(); 124 Color4f c = ((com.sun.scenario.effect.light.DistantLight) 125 LightShim.impl_getImpl(effect)).getColor(); 126 assertEquals(1f, c.getRed(), 1e-5); 127 assertEquals(1f, c.getGreen(), 1e-5); 128 assertEquals(1f, c.getBlue(), 1e-5); 129 assertEquals(1f, c.getAlpha(), 1e-5); 130 } 131 132 @Test 133 public void testAzimuthSynced() throws Exception { 134 checkDoublePropertySynced( 135 effect, LightShim.impl_getImpl(effect), 136 "javafx.scene.effect.Light$Distant", "azimuth", 137 "com.sun.scenario.effect.light.DistantLight", "azimuth", 0.3); 138 } 139 140 @Test 141 public void testColorSynced() throws Exception { 142 Color color = Color.RED; 143 Color4f red = new Color4f((float) color.getRed(), (float) color.getGreen(), 144 (float) color.getBlue(), (float) color.getOpacity()); 145 Color4f result = (Color4f) getObjectPropertySynced( 146 effect, LightShim.impl_getImpl(effect), 147 "javafx.scene.effect.Light$Distant", "color", 148 "com.sun.scenario.effect.light.DistantLight", "color", 149 Color.RED); 150 assertColor4fEquals(red, result); 151 } 152 153 @Test 154 public void testCreateWithParams() { 155 effect = new Light.Distant(1, 2, Color.BLUE); 156 setupTest(effect); 157 assertEquals(1, effect.getAzimuth(), 1e-100); 158 assertEquals(2, effect.getElevation(), 1e-100); 159 assertEquals(Color.BLUE, effect.getColor()); 160 pulse(); 161 assertEquals(1.0f, ((com.sun.scenario.effect.light.DistantLight) 162 LightShim.impl_getImpl(effect)).getAzimuth(), 1e-100); 163 assertEquals(2.0f, ((com.sun.scenario.effect.light.DistantLight) 164 LightShim.impl_getImpl(effect)).getElevation(), 1e-100); 165 Color4f c = ((com.sun.scenario.effect.light.DistantLight) 166 LightShim.impl_getImpl(effect)).getColor(); 167 assertEquals(0f, c.getRed(), 1e-5); 168 assertEquals(0f, c.getGreen(), 1e-5); 169 assertEquals(1f, c.getBlue(), 1e-5); 170 assertEquals(1f, c.getAlpha(), 1e-5); 171 } 172 173 @Test 174 public void testCreateWithDefaultParams() { 175 effect = new Light.Distant(45, 45, Color.RED); 176 setupTest(effect); 177 assertEquals(45, effect.getAzimuth(), 1e-100); 178 assertEquals(45, effect.getElevation(), 1e-100); 179 assertEquals(Color.RED, effect.getColor()); 180 pulse(); 181 assertEquals(45f, ((com.sun.scenario.effect.light.DistantLight) 182 LightShim.impl_getImpl(effect)).getAzimuth(), 1e-100); 183 assertEquals(45f, ((com.sun.scenario.effect.light.DistantLight) 184 LightShim.impl_getImpl(effect)).getElevation(), 1e-100); 185 Color4f c = ((com.sun.scenario.effect.light.DistantLight) 186 LightShim.impl_getImpl(effect)).getColor(); 187 assertEquals(1f, c.getRed(), 1e-5); 188 assertEquals(0f, c.getGreen(), 1e-5); 189 assertEquals(0f, c.getBlue(), 1e-5); 190 assertEquals(1f, c.getAlpha(), 1e-5); 191 } 192 }