modules/graphics/src/test/java/test/javafx/scene/effect/LightingTest.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 com.sun.javafx.test.TestHelper.box;

  29 import com.sun.scenario.effect.Color4f;
  30 import static org.junit.Assert.assertEquals;
  31 import static org.junit.Assert.assertNotNull;
  32 import static org.junit.Assert.assertNull;
  33 import static org.junit.Assert.assertTrue;
  34 import static org.junit.Assert.fail;
  35 import javafx.beans.property.ObjectProperty;
  36 import javafx.beans.property.SimpleObjectProperty;







  37 import javafx.scene.paint.Color;
  38 
  39 import org.junit.Before;
  40 import org.junit.Test;
  41 
  42 public class LightingTest extends EffectsTestBase {
  43     private Lighting effect;
  44 
  45     @Before
  46     public void setUp() {
  47         effect = new Lighting();
  48         setupTest(effect);
  49     }
  50 
  51     @Test
  52     public void testSetDiffuseConstant() {
  53         // try setting correct value
  54         effect.setDiffuseConstant(1.1f);
  55         assertEquals(1.1f, (float) effect.getDiffuseConstant(), 1e-100);
  56         pulse();
  57         assertEquals(1.1f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getDiffuseConstant(), 1e-100);

  58     }
  59 
  60     @Test
  61     public void testDefaultDiffuseConstant() {
  62         // default value should be 1
  63         assertEquals(1f, (float) effect.getDiffuseConstant(), 1e-100);
  64         assertEquals(1f, (float) effect.diffuseConstantProperty().get(), 1e-100);
  65         pulse();
  66         assertEquals(1f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getDiffuseConstant(), 1e-100);

  67     }
  68 
  69     @Test
  70     public void testMinDiffuseConstant() {
  71         // 0 should be ok
  72         effect.setDiffuseConstant(0);
  73         // try setting value smaller than minimal
  74         effect.setDiffuseConstant(-0.1f);
  75         assertEquals(-0.1f, (float) effect.getDiffuseConstant(), 1e-100);
  76         pulse();
  77         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getDiffuseConstant(), 1e-100);

  78     }
  79 
  80     @Test
  81     public void testMaxDiffuseConstant() {
  82         // 2 should be ok
  83         effect.setDiffuseConstant(2);
  84         // try setting value greater than maximal
  85         effect.setDiffuseConstant(2.1f);
  86         assertEquals(2.1f, (float) effect.getDiffuseConstant(), 1e-100);
  87         pulse();
  88         assertEquals(2f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getDiffuseConstant(), 1e-100);

  89     }
  90 
  91     @Test
  92     public void testSetSpecularConstant() {
  93         // try setting correct value
  94         effect.setSpecularConstant(1.0f);
  95         assertEquals(1.0f, (float) effect.getSpecularConstant(), 1e-100);
  96         pulse();
  97         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularConstant(), 1e-100);

  98     }
  99 
 100     @Test
 101     public void testDefaultSpecularConstant() {
 102         // default value should be 0.3
 103         assertEquals(0.3f, (float) effect.getSpecularConstant(), 1e-100);
 104         assertEquals(0.3f, (float) effect.specularConstantProperty().get(), 1e-100);
 105         pulse();
 106         assertEquals(0.3f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularConstant(), 1e-100);

 107     }
 108     
 109     @Test
 110     public void testMinSpecularConstant() {
 111         // 0 should be ok
 112         effect.setSpecularConstant(0);
 113         // try setting value smaller than minimal
 114         effect.setSpecularConstant(-0.1f);
 115         assertEquals(-0.1f, (float) effect.getSpecularConstant(), 1e-100);
 116         pulse();
 117         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularConstant(), 1e-100);

 118     }
 119 
 120     @Test
 121     public void testMaxSpecularConstant() {
 122         // 2 should be ok
 123         effect.setSpecularConstant(2);
 124         // try setting value greater than maximal
 125         effect.setSpecularConstant(2.1f);
 126         assertEquals(2.1f, (float) effect.getSpecularConstant(), 1e-100);
 127         pulse();
 128         assertEquals(2f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularConstant(), 1e-100);

 129     }
 130 
 131     @Test
 132     public void testSetSpecularExponent() {
 133         // try setting correct value
 134         effect.setSpecularExponent(1.0f);
 135         assertEquals(1.0f, (float) effect.getSpecularExponent(), 1e-100);
 136         pulse();
 137         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularExponent(), 1e-100);

 138     }
 139 
 140     @Test
 141     public void testDefaultSpecularExponent() {
 142         // default value should be 20
 143         assertEquals(20f, (float) effect.getSpecularExponent(), 1e-100);
 144         assertEquals(20f, (float) effect.specularExponentProperty().get(), 1e-100);
 145         pulse();
 146         assertEquals(20f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularExponent(), 1e-100);

 147     }
 148 
 149     @Test
 150     public void testMinSpecularExponent() {
 151         // 0 should be ok
 152         effect.setSpecularExponent(0);
 153         // try setting value smaller than minimal
 154         effect.setSpecularExponent(-0.1f);
 155         assertEquals(-0.1f, (float) effect.getSpecularExponent(), 1e-100);
 156         pulse();
 157         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularExponent(), 1e-100);

 158     }
 159 
 160     @Test
 161     public void testMaxSpecularExponent() {
 162         // 40 should be ok
 163         effect.setSpecularExponent(40);
 164         // try setting value greater than maximal
 165         effect.setSpecularExponent(40.1f);
 166         assertEquals(40.1f, (float) effect.getSpecularExponent(), 1e-100);
 167         pulse();
 168         assertEquals(40f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSpecularExponent(), 1e-100);

 169     }
 170 
 171     @Test
 172     public void testSetSurfaceScale() {
 173         // try setting correct value
 174         effect.setSurfaceScale(1.0f);
 175         assertEquals(1.0f, (float) effect.getSurfaceScale(), 1e-100);
 176         pulse();
 177         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSurfaceScale(), 1e-100);

 178     }
 179 
 180     @Test
 181     public void testDefaultSurfaceScale() {
 182         // default value should be 1.5
 183         assertEquals(1.5f, (float) effect.getSurfaceScale(), 1e-100);
 184         assertEquals(1.5f, (float) effect.surfaceScaleProperty().get(), 1e-100);
 185         pulse();
 186         assertEquals(1.5f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSurfaceScale(), 1e-100);

 187     }
 188 
 189     @Test
 190     public void testMinSurfaceScale() {
 191         // 0 should be ok
 192         effect.setSurfaceScale(0);
 193         // try setting value smaller than minimal
 194         effect.setSurfaceScale(-0.1f);
 195         assertEquals(-0.1f, (float) effect.getSurfaceScale(), 1e-100);
 196         pulse();
 197         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSurfaceScale(), 1e-100);

 198     }
 199 
 200     @Test
 201     public void testMaxSurfaceScale() {
 202         // 10 should be ok
 203         effect.setSurfaceScale(10);
 204         // try setting value greater than maximal
 205         effect.setSurfaceScale(10.1f);
 206         assertEquals(10.1f, (float) effect.getSurfaceScale(), 1e-100);
 207         pulse();
 208         assertEquals(10f, (float) ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getSurfaceScale(), 1e-100);

 209     }
 210     
 211     @Test
 212     public void testBumpInput() {
 213         // default is not null
 214         assertNotNull(effect.getBumpInput());
 215         // default is shadow effect with radius of 10
 216         Effect e = effect.getBumpInput();
 217         assertTrue(e instanceof Shadow);
 218         assertEquals(10f, (float) ((Shadow)e).getRadius(), 1e-100);
 219                 
 220         // try setting input to some other effect
 221         Effect blur = new BoxBlur();
 222         effect.setBumpInput(blur);
 223         assertEquals(blur, effect.getBumpInput());
 224 
 225         // try setting input to null
 226         effect.setBumpInput(null);
 227         assertNull(effect.getBumpInput());
 228     }


 231     public void testContentInput() {
 232         // default is null
 233         assertNull(effect.getContentInput());
 234         // try setting input to some other effect
 235         Effect blur = new BoxBlur();
 236         effect.setContentInput(blur);
 237         assertEquals(blur, effect.getContentInput());
 238 
 239         // try setting input to null
 240         effect.setContentInput(null);
 241         assertNull(effect.getContentInput());
 242     }
 243     
 244     @Test
 245     public void testSetLight() {
 246         // try setting correct value
 247         Light l = new Light.Point();
 248         effect.setLight(l);
 249         assertEquals(l, effect.getLight());
 250         pulse();
 251         assertEquals(l.impl_getImpl(), ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight());

 252     }
 253 
 254     @Test
 255     public void testDefaultLight() {
 256         // default value should be distant light
 257         Light l = effect.getLight();
 258         assertNotNull(l);
 259         assertTrue(l instanceof Light.Distant);
 260         assertEquals(l, effect.lightProperty().get());
 261         pulse();
 262         assertEquals(l.impl_getImpl(), ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight());

 263     }
 264 
 265     @Test
 266     public void testNullLight() {
 267         // nullvalue should default to Distant light
 268         effect.setLight(null);
 269         Light l = effect.getLight();
 270         assertNull(l);
 271         assertNull(effect.lightProperty().get());
 272         pulse();
 273         assertNotNull(((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight());

 274     }
 275 
 276     @Test
 277     public void testDefaultLightNotChangedByOtherLightingEffect() {
 278         // default value should be distant light
 279         Light l = effect.getLight();
 280         assertNotNull(l);
 281         assertTrue(l instanceof Light.Distant);
 282         assertEquals(l, effect.lightProperty().get());
 283 
 284         Lighting lighting = new Lighting();
 285         Light l2 = lighting.getLight();
 286         assertNotNull(l2);
 287         assertTrue(l2 instanceof Light.Distant);
 288         assertEquals(l2, lighting.lightProperty().get());
 289 
 290         l.setColor(Color.AQUA);
 291 
 292         assertEquals(Color.AQUA, l.getColor());
 293         assertEquals(Color.WHITE, l2.getColor());
 294     }
 295 
 296     @Test
 297     public void testDefaultLightNotChangedByThisLightingEffect() {
 298         // default value should be distant light
 299         Light l = effect.getLight();
 300         l.setColor(Color.BEIGE);
 301 
 302         effect.setLight(null);
 303         // null light should default to Distant Light with WHITE color
 304         assertNull(effect.getLight());
 305         pulse();
 306         Color4f c = ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight().getColor();

 307         assertEquals(1f, c.getRed(), 1e-5);
 308         assertEquals(1f, c.getGreen(), 1e-5);
 309         assertEquals(1f, c.getBlue(), 1e-5);
 310         assertEquals(1f, c.getAlpha(), 1e-5);
 311     }
 312 
 313     @Test
 314     public void testChangeLight() {
 315         // try setting correct value
 316         Light.Point l = new Light.Point();
 317         effect.setLight(l);
 318         assertEquals(l, effect.getLight());
 319         pulse();
 320         assertEquals(l.impl_getImpl(), ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight());

 321         l.setX(100);
 322         pulse();
 323         assertEquals(100f, (float) ((com.sun.scenario.effect.light.PointLight) l.impl_getImpl()).getX(), 1e-100);

 324     }
 325 
 326     @Test
 327     public void testCycles() {
 328         // try setting itself as content input
 329         try {
 330             effect.setContentInput(effect);
 331             fail("IllegalArgument should have been thrown.");
 332         } catch (IllegalArgumentException e) {
 333             assertEquals(null, effect.getContentInput());
 334         }
 335 
 336         // try setting itself as bump input
 337         try {
 338             effect.setBumpInput(effect);
 339             fail("IllegalArgument should have been thrown.");
 340         } catch (IllegalArgumentException e) {
 341             Effect efct = effect.getBumpInput();
 342             assertTrue(efct instanceof Shadow);
 343         }


 442     @Test
 443     public void testSpecularExponentSynced() throws Exception {
 444         checkDoublePropertySynced(
 445                 "javafx.scene.effect.Lighting", "specularExponent",
 446                 "com.sun.scenario.effect.PhongLighting", "specularExponent", 10);
 447     }
 448 
 449     @Test
 450     public void testSurfaceScaleSynced() throws Exception {
 451         checkDoublePropertySynced(
 452                 "javafx.scene.effect.Lighting", "surfaceScale",
 453                 "com.sun.scenario.effect.PhongLighting", "surfaceScale", 10);
 454     }
 455 
 456     @Test
 457     public void testLightSynced() throws Exception {
 458         Light l = new Light.Point();
 459         checkObjectPropertySynced(
 460                 "javafx.scene.effect.Lighting", "light",
 461                 "com.sun.scenario.effect.PhongLighting", "light",
 462                 l, l.impl_getImpl(),
 463                 null);
 464     }
 465 
 466     @Test
 467     public void testBumpInputSynced() throws Exception {
 468         BoxBlur blur = new BoxBlur();
 469         checkEffectPropertySynced(
 470                 "javafx.scene.effect.Lighting", "bumpInput",
 471                 "com.sun.scenario.effect.PhongLighting", "bumpInput",
 472                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());

 473     }
 474 
 475     @Test
 476     public void testContentInputSynced() throws Exception {
 477         BoxBlur blur = new BoxBlur();
 478         checkEffectPropertySynced(
 479                 "javafx.scene.effect.Lighting", "contentInput",
 480                 "com.sun.scenario.effect.PhongLighting", "contentInput",
 481                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());

 482     }
 483 
 484     @Test
 485     public void testBounds() {
 486         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 487     }
 488 
 489     @Test
 490     public void testBoundsWidthContentInput() {
 491         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 492         BoxBlur blur = new BoxBlur();
 493         effect.setContentInput(blur);
 494         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 495     }
 496 
 497     @Test
 498     public void testBoundsWidthBumpInput() {
 499         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 500         BoxBlur blur = new BoxBlur();
 501         effect.setBumpInput(blur);
 502         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 503     }
 504 
 505     @Test
 506     public void testBoundsWidthBumpAndContentInput() {
 507         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 508         BoxBlur blur = new BoxBlur();
 509         effect.setContentInput(blur);
 510         effect.setBumpInput(blur);
 511         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 512     }
 513     
 514     @Test
 515     public void testCreateWithParams() {
 516         Light l = new Light.Point();
 517         effect = new Lighting(l);
 518         setupTest(effect);
 519         effect.setLight(l);
 520         assertEquals(l, effect.getLight());
 521         pulse();
 522         assertEquals(l.impl_getImpl(), ((com.sun.scenario.effect.PhongLighting) effect.impl_getImpl()).getLight());

 523     }
 524 }


   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.EffectsTestBase;
  29 import static test.com.sun.javafx.test.TestHelper.box;
  30 import com.sun.scenario.effect.Color4f;
  31 import static org.junit.Assert.assertEquals;
  32 import static org.junit.Assert.assertNotNull;
  33 import static org.junit.Assert.assertNull;
  34 import static org.junit.Assert.assertTrue;
  35 import static org.junit.Assert.fail;
  36 import javafx.beans.property.ObjectProperty;
  37 import javafx.beans.property.SimpleObjectProperty;
  38 import javafx.scene.effect.BoxBlur;
  39 import javafx.scene.effect.Effect;
  40 import javafx.scene.effect.EffectShim;
  41 import javafx.scene.effect.Light;
  42 import javafx.scene.effect.LightShim;
  43 import javafx.scene.effect.Lighting;
  44 import javafx.scene.effect.Shadow;
  45 import javafx.scene.paint.Color;
  46 
  47 import org.junit.Before;
  48 import org.junit.Test;
  49 
  50 public class LightingTest extends EffectsTestBase {
  51     private Lighting effect;
  52 
  53     @Before
  54     public void setUp() {
  55         effect = new Lighting();
  56         setupTest(effect);
  57     }
  58 
  59     @Test
  60     public void testSetDiffuseConstant() {
  61         // try setting correct value
  62         effect.setDiffuseConstant(1.1f);
  63         assertEquals(1.1f, (float) effect.getDiffuseConstant(), 1e-100);
  64         pulse();
  65         assertEquals(1.1f, (float) ((com.sun.scenario.effect.PhongLighting) 
  66                 EffectShim.impl_getImpl(effect)).getDiffuseConstant(), 1e-100);
  67     }
  68 
  69     @Test
  70     public void testDefaultDiffuseConstant() {
  71         // default value should be 1
  72         assertEquals(1f, (float) effect.getDiffuseConstant(), 1e-100);
  73         assertEquals(1f, (float) effect.diffuseConstantProperty().get(), 1e-100);
  74         pulse();
  75         assertEquals(1f, (float) ((com.sun.scenario.effect.PhongLighting) 
  76                 EffectShim.impl_getImpl(effect)).getDiffuseConstant(), 1e-100);
  77     }
  78 
  79     @Test
  80     public void testMinDiffuseConstant() {
  81         // 0 should be ok
  82         effect.setDiffuseConstant(0);
  83         // try setting value smaller than minimal
  84         effect.setDiffuseConstant(-0.1f);
  85         assertEquals(-0.1f, (float) effect.getDiffuseConstant(), 1e-100);
  86         pulse();
  87         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) 
  88                 EffectShim.impl_getImpl(effect)).getDiffuseConstant(), 1e-100);
  89     }
  90 
  91     @Test
  92     public void testMaxDiffuseConstant() {
  93         // 2 should be ok
  94         effect.setDiffuseConstant(2);
  95         // try setting value greater than maximal
  96         effect.setDiffuseConstant(2.1f);
  97         assertEquals(2.1f, (float) effect.getDiffuseConstant(), 1e-100);
  98         pulse();
  99         assertEquals(2f, (float) ((com.sun.scenario.effect.PhongLighting) 
 100                 EffectShim.impl_getImpl(effect)).getDiffuseConstant(), 1e-100);
 101     }
 102 
 103     @Test
 104     public void testSetSpecularConstant() {
 105         // try setting correct value
 106         effect.setSpecularConstant(1.0f);
 107         assertEquals(1.0f, (float) effect.getSpecularConstant(), 1e-100);
 108         pulse();
 109         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 110                 EffectShim.impl_getImpl(effect)).getSpecularConstant(), 1e-100);
 111     }
 112 
 113     @Test
 114     public void testDefaultSpecularConstant() {
 115         // default value should be 0.3
 116         assertEquals(0.3f, (float) effect.getSpecularConstant(), 1e-100);
 117         assertEquals(0.3f, (float) effect.specularConstantProperty().get(), 1e-100);
 118         pulse();
 119         assertEquals(0.3f, (float) ((com.sun.scenario.effect.PhongLighting) 
 120                 EffectShim.impl_getImpl(effect)).getSpecularConstant(), 1e-100);
 121     }
 122     
 123     @Test
 124     public void testMinSpecularConstant() {
 125         // 0 should be ok
 126         effect.setSpecularConstant(0);
 127         // try setting value smaller than minimal
 128         effect.setSpecularConstant(-0.1f);
 129         assertEquals(-0.1f, (float) effect.getSpecularConstant(), 1e-100);
 130         pulse();
 131         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 132                 EffectShim.impl_getImpl(effect)).getSpecularConstant(), 1e-100);
 133     }
 134 
 135     @Test
 136     public void testMaxSpecularConstant() {
 137         // 2 should be ok
 138         effect.setSpecularConstant(2);
 139         // try setting value greater than maximal
 140         effect.setSpecularConstant(2.1f);
 141         assertEquals(2.1f, (float) effect.getSpecularConstant(), 1e-100);
 142         pulse();
 143         assertEquals(2f, (float) ((com.sun.scenario.effect.PhongLighting) 
 144                 EffectShim.impl_getImpl(effect)).getSpecularConstant(), 1e-100);
 145     }
 146 
 147     @Test
 148     public void testSetSpecularExponent() {
 149         // try setting correct value
 150         effect.setSpecularExponent(1.0f);
 151         assertEquals(1.0f, (float) effect.getSpecularExponent(), 1e-100);
 152         pulse();
 153         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 154                 EffectShim.impl_getImpl(effect)).getSpecularExponent(), 1e-100);
 155     }
 156 
 157     @Test
 158     public void testDefaultSpecularExponent() {
 159         // default value should be 20
 160         assertEquals(20f, (float) effect.getSpecularExponent(), 1e-100);
 161         assertEquals(20f, (float) effect.specularExponentProperty().get(), 1e-100);
 162         pulse();
 163         assertEquals(20f, (float) ((com.sun.scenario.effect.PhongLighting) 
 164                 EffectShim.impl_getImpl(effect)).getSpecularExponent(), 1e-100);
 165     }
 166 
 167     @Test
 168     public void testMinSpecularExponent() {
 169         // 0 should be ok
 170         effect.setSpecularExponent(0);
 171         // try setting value smaller than minimal
 172         effect.setSpecularExponent(-0.1f);
 173         assertEquals(-0.1f, (float) effect.getSpecularExponent(), 1e-100);
 174         pulse();
 175         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 176                 EffectShim.impl_getImpl(effect)).getSpecularExponent(), 1e-100);
 177     }
 178 
 179     @Test
 180     public void testMaxSpecularExponent() {
 181         // 40 should be ok
 182         effect.setSpecularExponent(40);
 183         // try setting value greater than maximal
 184         effect.setSpecularExponent(40.1f);
 185         assertEquals(40.1f, (float) effect.getSpecularExponent(), 1e-100);
 186         pulse();
 187         assertEquals(40f, (float) ((com.sun.scenario.effect.PhongLighting) 
 188                 EffectShim.impl_getImpl(effect)).getSpecularExponent(), 1e-100);
 189     }
 190 
 191     @Test
 192     public void testSetSurfaceScale() {
 193         // try setting correct value
 194         effect.setSurfaceScale(1.0f);
 195         assertEquals(1.0f, (float) effect.getSurfaceScale(), 1e-100);
 196         pulse();
 197         assertEquals(1.0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 198                 EffectShim.impl_getImpl(effect)).getSurfaceScale(), 1e-100);
 199     }
 200 
 201     @Test
 202     public void testDefaultSurfaceScale() {
 203         // default value should be 1.5
 204         assertEquals(1.5f, (float) effect.getSurfaceScale(), 1e-100);
 205         assertEquals(1.5f, (float) effect.surfaceScaleProperty().get(), 1e-100);
 206         pulse();
 207         assertEquals(1.5f, (float) ((com.sun.scenario.effect.PhongLighting) 
 208                 EffectShim.impl_getImpl(effect)).getSurfaceScale(), 1e-100);
 209     }
 210 
 211     @Test
 212     public void testMinSurfaceScale() {
 213         // 0 should be ok
 214         effect.setSurfaceScale(0);
 215         // try setting value smaller than minimal
 216         effect.setSurfaceScale(-0.1f);
 217         assertEquals(-0.1f, (float) effect.getSurfaceScale(), 1e-100);
 218         pulse();
 219         assertEquals(0f, (float) ((com.sun.scenario.effect.PhongLighting) 
 220                 EffectShim.impl_getImpl(effect)).getSurfaceScale(), 1e-100);
 221     }
 222 
 223     @Test
 224     public void testMaxSurfaceScale() {
 225         // 10 should be ok
 226         effect.setSurfaceScale(10);
 227         // try setting value greater than maximal
 228         effect.setSurfaceScale(10.1f);
 229         assertEquals(10.1f, (float) effect.getSurfaceScale(), 1e-100);
 230         pulse();
 231         assertEquals(10f, (float) ((com.sun.scenario.effect.PhongLighting) 
 232                 EffectShim.impl_getImpl(effect)).getSurfaceScale(), 1e-100);
 233     }
 234     
 235     @Test
 236     public void testBumpInput() {
 237         // default is not null
 238         assertNotNull(effect.getBumpInput());
 239         // default is shadow effect with radius of 10
 240         Effect e = effect.getBumpInput();
 241         assertTrue(e instanceof Shadow);
 242         assertEquals(10f, (float) ((Shadow)e).getRadius(), 1e-100);
 243                 
 244         // try setting input to some other effect
 245         Effect blur = new BoxBlur();
 246         effect.setBumpInput(blur);
 247         assertEquals(blur, effect.getBumpInput());
 248 
 249         // try setting input to null
 250         effect.setBumpInput(null);
 251         assertNull(effect.getBumpInput());
 252     }


 255     public void testContentInput() {
 256         // default is null
 257         assertNull(effect.getContentInput());
 258         // try setting input to some other effect
 259         Effect blur = new BoxBlur();
 260         effect.setContentInput(blur);
 261         assertEquals(blur, effect.getContentInput());
 262 
 263         // try setting input to null
 264         effect.setContentInput(null);
 265         assertNull(effect.getContentInput());
 266     }
 267     
 268     @Test
 269     public void testSetLight() {
 270         // try setting correct value
 271         Light l = new Light.Point();
 272         effect.setLight(l);
 273         assertEquals(l, effect.getLight());
 274         pulse();
 275         assertEquals(LightShim.impl_getImpl(l), ((com.sun.scenario.effect.PhongLighting) 
 276                 EffectShim.impl_getImpl(effect)).getLight());
 277     }
 278 
 279     @Test
 280     public void testDefaultLight() {
 281         // default value should be distant light
 282         Light l = effect.getLight();
 283         assertNotNull(l);
 284         assertTrue(l instanceof Light.Distant);
 285         assertEquals(l, effect.lightProperty().get());
 286         pulse();
 287         assertEquals(LightShim.impl_getImpl(l), ((com.sun.scenario.effect.PhongLighting) 
 288                 EffectShim.impl_getImpl(effect)).getLight());
 289     }
 290 
 291     @Test
 292     public void testNullLight() {
 293         // nullvalue should default to Distant light
 294         effect.setLight(null);
 295         Light l = effect.getLight();
 296         assertNull(l);
 297         assertNull(effect.lightProperty().get());
 298         pulse();
 299         assertNotNull(((com.sun.scenario.effect.PhongLighting) 
 300                 EffectShim.impl_getImpl(effect)).getLight());
 301     }
 302 
 303     @Test
 304     public void testDefaultLightNotChangedByOtherLightingEffect() {
 305         // default value should be distant light
 306         Light l = effect.getLight();
 307         assertNotNull(l);
 308         assertTrue(l instanceof Light.Distant);
 309         assertEquals(l, effect.lightProperty().get());
 310 
 311         Lighting lighting = new Lighting();
 312         Light l2 = lighting.getLight();
 313         assertNotNull(l2);
 314         assertTrue(l2 instanceof Light.Distant);
 315         assertEquals(l2, lighting.lightProperty().get());
 316 
 317         l.setColor(Color.AQUA);
 318 
 319         assertEquals(Color.AQUA, l.getColor());
 320         assertEquals(Color.WHITE, l2.getColor());
 321     }
 322 
 323     @Test
 324     public void testDefaultLightNotChangedByThisLightingEffect() {
 325         // default value should be distant light
 326         Light l = effect.getLight();
 327         l.setColor(Color.BEIGE);
 328 
 329         effect.setLight(null);
 330         // null light should default to Distant Light with WHITE color
 331         assertNull(effect.getLight());
 332         pulse();
 333         Color4f c = ((com.sun.scenario.effect.PhongLighting) 
 334                 EffectShim.impl_getImpl(effect)).getLight().getColor();
 335         assertEquals(1f, c.getRed(), 1e-5);
 336         assertEquals(1f, c.getGreen(), 1e-5);
 337         assertEquals(1f, c.getBlue(), 1e-5);
 338         assertEquals(1f, c.getAlpha(), 1e-5);
 339     }
 340 
 341     @Test
 342     public void testChangeLight() {
 343         // try setting correct value
 344         Light.Point l = new Light.Point();
 345         effect.setLight(l);
 346         assertEquals(l, effect.getLight());
 347         pulse();
 348         assertEquals(LightShim.impl_getImpl(l), ((com.sun.scenario.effect.PhongLighting) 
 349                 EffectShim.impl_getImpl(effect)).getLight());
 350         l.setX(100);
 351         pulse();
 352         assertEquals(100f, (float) ((com.sun.scenario.effect.light.PointLight) 
 353                 LightShim.impl_getImpl(l)).getX(), 1e-100);
 354     }
 355 
 356     @Test
 357     public void testCycles() {
 358         // try setting itself as content input
 359         try {
 360             effect.setContentInput(effect);
 361             fail("IllegalArgument should have been thrown.");
 362         } catch (IllegalArgumentException e) {
 363             assertEquals(null, effect.getContentInput());
 364         }
 365 
 366         // try setting itself as bump input
 367         try {
 368             effect.setBumpInput(effect);
 369             fail("IllegalArgument should have been thrown.");
 370         } catch (IllegalArgumentException e) {
 371             Effect efct = effect.getBumpInput();
 372             assertTrue(efct instanceof Shadow);
 373         }


 472     @Test
 473     public void testSpecularExponentSynced() throws Exception {
 474         checkDoublePropertySynced(
 475                 "javafx.scene.effect.Lighting", "specularExponent",
 476                 "com.sun.scenario.effect.PhongLighting", "specularExponent", 10);
 477     }
 478 
 479     @Test
 480     public void testSurfaceScaleSynced() throws Exception {
 481         checkDoublePropertySynced(
 482                 "javafx.scene.effect.Lighting", "surfaceScale",
 483                 "com.sun.scenario.effect.PhongLighting", "surfaceScale", 10);
 484     }
 485 
 486     @Test
 487     public void testLightSynced() throws Exception {
 488         Light l = new Light.Point();
 489         checkObjectPropertySynced(
 490                 "javafx.scene.effect.Lighting", "light",
 491                 "com.sun.scenario.effect.PhongLighting", "light",
 492                 l, LightShim.impl_getImpl(l),
 493                 null);
 494     }
 495 
 496     @Test
 497     public void testBumpInputSynced() throws Exception {
 498         BoxBlur blur = new BoxBlur();
 499         checkEffectPropertySynced(
 500                 "javafx.scene.effect.Lighting", "bumpInput",
 501                 "com.sun.scenario.effect.PhongLighting", "bumpInput",
 502                 blur, (com.sun.scenario.effect.BoxBlur)
 503                 EffectShim.impl_getImpl(blur));
 504     }
 505 
 506     @Test
 507     public void testContentInputSynced() throws Exception {
 508         BoxBlur blur = new BoxBlur();
 509         checkEffectPropertySynced(
 510                 "javafx.scene.effect.Lighting", "contentInput",
 511                 "com.sun.scenario.effect.PhongLighting", "contentInput",
 512                 blur, (com.sun.scenario.effect.BoxBlur)
 513                 EffectShim.impl_getImpl(blur));
 514     }
 515 
 516     @Test
 517     public void testBounds() {
 518         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 519     }
 520 
 521     @Test
 522     public void testBoundsWidthContentInput() {
 523         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 524         BoxBlur blur = new BoxBlur();
 525         effect.setContentInput(blur);
 526         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 527     }
 528 
 529     @Test
 530     public void testBoundsWidthBumpInput() {
 531         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 532         BoxBlur blur = new BoxBlur();
 533         effect.setBumpInput(blur);
 534         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 535     }
 536 
 537     @Test
 538     public void testBoundsWidthBumpAndContentInput() {
 539         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 540         BoxBlur blur = new BoxBlur();
 541         effect.setContentInput(blur);
 542         effect.setBumpInput(blur);
 543         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 544     }
 545     
 546     @Test
 547     public void testCreateWithParams() {
 548         Light l = new Light.Point();
 549         effect = new Lighting(l);
 550         setupTest(effect);
 551         effect.setLight(l);
 552         assertEquals(l, effect.getLight());
 553         pulse();
 554         assertEquals(LightShim.impl_getImpl(l), ((com.sun.scenario.effect.PhongLighting) 
 555                 EffectShim.impl_getImpl(effect)).getLight());
 556     }
 557 }