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.Test;
  33 
  34 import com.sun.scenario.effect.Color4f;
  35 
  36 public class PointLightTest extends LightTestBase {
  37     private Light.Point effect;
  38 
  39     @Before
  40     public void setUp() {
  41         effect = new Light.Point();
  42         setupTest(effect);
  43     }
  44 
  45     @Test
  46     public void testSetX() {
  47         // try setting correct value
  48         effect.setX(1.0f);
  49         assertEquals(1.0f, effect.getX(), 1e-100);
  50         pulse();
  51         assertEquals(1.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getX(), 1e-100);
  52     }
  53 
  54     @Test
  55     public void testDefaultX() {
  56         // default value should be 0
  57         assertEquals(0f, effect.getX(), 1e-100);
  58         assertEquals(0f, effect.xProperty().get(), 1e-100);
  59         pulse();
  60         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getX(), 1e-100);
  61     }
  62 
  63     @Test
  64     public void testSetY() {
  65         // try setting correct value
  66         effect.setY(1.0f);
  67         assertEquals(1.0f, effect.getY(), 1e-100);
  68         pulse();
  69         assertEquals(1.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getY(), 1e-100);
  70     }
  71 
  72     @Test
  73     public void testDefaultY() {
  74         // default value should be 0
  75         assertEquals(0f, effect.getY(), 1e-100);
  76         assertEquals(0f, effect.yProperty().get(), 1e-100);
  77         pulse();
  78         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getY(), 1e-100);
  79     }
  80 
  81     @Test
  82     public void testSetZ() {
  83         // try setting correct value
  84         effect.setZ(1.0f);
  85         assertEquals(1.0f, effect.getZ(), 1e-100);
  86         pulse();
  87         assertEquals(1.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getZ(), 1e-100);
  88     }
  89 
  90     @Test
  91     public void testDefaultZ() {
  92         // default value should be 0
  93         assertEquals(0f, effect.getZ(), 1e-100);
  94         assertEquals(0f, effect.zProperty().get(), 1e-100);
  95         pulse();
  96         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getZ(), 1e-100);
  97     }
  98 
  99     @Test
 100     public void testXSynced() throws Exception {
 101         checkDoublePropertySynced(
 102                 effect, effect.impl_getImpl(),
 103                 "javafx.scene.effect.Light$Point", "x",
 104                 "com.sun.scenario.effect.light.PointLight", "x", 0.3);
 105     }
 106 
 107     @Test
 108     public void testYSynced() throws Exception {
 109         checkDoublePropertySynced(
 110                 effect, effect.impl_getImpl(),
 111                 "javafx.scene.effect.Light$Point", "y",
 112                 "com.sun.scenario.effect.light.PointLight", "y", 0.3);
 113     }
 114 
 115     @Test
 116     public void testZSynced() throws Exception {
 117         checkDoublePropertySynced(
 118                 effect, effect.impl_getImpl(),
 119                 "javafx.scene.effect.Light$Point", "z",
 120                 "com.sun.scenario.effect.light.PointLight", "z", 0.3);
 121     }
 122 
 123     @Test
 124     public void testColorSynced() throws Exception {
 125         Color color = Color.RED;
 126         Color4f red = new Color4f((float) color.getRed(), (float) color.getGreen(),
 127                 (float) color.getBlue(), (float) color.getOpacity());
 128         Color4f result = (Color4f) getObjectPropertySynced(
 129                 effect, effect.impl_getImpl(),
 130                 "javafx.scene.effect.Light$Point", "color",
 131                 "com.sun.scenario.effect.light.PointLight", "color",
 132                 Color.RED);
 133         assertColor4fEquals(red, result);
 134     }
 135 
 136     @Test
 137     public void testCreateWithParams() {
 138         effect = new Light.Point(1, 2, 3, Color.RED);
 139         setupTest(effect);
 140         assertEquals(1, effect.getX(), 1e-100);
 141         assertEquals(2, effect.getY(), 1e-100);
 142         assertEquals(3, effect.getZ(), 1e-100);
 143         assertEquals(Color.RED, effect.getColor());
 144         pulse();        
 145         assertEquals(1.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getX(), 1e-100);
 146         assertEquals(2.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getY(), 1e-100);
 147         assertEquals(3.0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getZ(), 1e-100);
 148         Color4f c = ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getColor();
 149         assertEquals(1f, c.getRed(), 1e-5);
 150         assertEquals(0f, c.getGreen(), 1e-5);
 151         assertEquals(0f, c.getBlue(), 1e-5);
 152         assertEquals(1f, c.getAlpha(), 1e-5);
 153     }
 154 
 155     @Test
 156     public void testCreateWithDefaultParams() {
 157         effect = new Light.Point(0, 0, 0, Color.WHITE);
 158         setupTest(effect);
 159         assertEquals(0, effect.getX(), 1e-100);
 160         assertEquals(0, effect.getY(), 1e-100);
 161         assertEquals(0, effect.getZ(), 1e-100);
 162         assertEquals(Color.WHITE, effect.getColor());
 163         pulse();        
 164         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getX(), 1e-100);
 165         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getY(), 1e-100);
 166         assertEquals(0f, ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getZ(), 1e-100);
 167         Color4f c = ((com.sun.scenario.effect.light.PointLight) effect.impl_getImpl()).getColor();
 168         assertEquals(1f, c.getRed(), 1e-5);
 169         assertEquals(1f, c.getGreen(), 1e-5);
 170         assertEquals(1f, c.getBlue(), 1e-5);
 171         assertEquals(1f, c.getAlpha(), 1e-5);
 172     }
 173 }