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