modules/graphics/src/test/java/test/javafx/scene/effect/SpotLightTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   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 }


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