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 com.sun.javafx.test.TestHelper.box; 29 import static org.junit.Assert.assertEquals; 30 31 import com.sun.javafx.FXUnit; 32 import org.junit.Before; 33 import org.junit.Rule; 34 import org.junit.Test; 35 36 public class GlowTest extends EffectsTestBase { 37 38 @Rule 39 public FXUnit fx = new FXUnit(); 40 41 private Glow effect; 42 43 @Before 44 public void setUp() { 45 effect = new Glow(); 46 setupTest(effect); 47 } 48 49 @Test 50 public void testSetLevel() { 51 // try setting correct value 52 effect.setLevel(1); 53 assertEquals(1.0f, (float) effect.getLevel(), 1e-100); 54 pulse(); 55 assertEquals(1.0f, (float) ((com.sun.scenario.effect.Glow)effect.impl_getImpl()).getLevel(), 1e-100); 56 } 57 58 @Test 59 public void testDefaultLevel() { 60 // default value should be 0.3 61 assertEquals(0.3f, (float) effect.getLevel(), 1e-100); 62 assertEquals(0.3f, (float) effect.levelProperty().get(), 1e-100); 63 pulse(); 64 assertEquals(0.3f, (float) ((com.sun.scenario.effect.Glow)effect.impl_getImpl()).getLevel(), 1e-100); 65 } 66 67 @Test 68 public void testMinLevel() { 69 // 0 should be ok 70 effect.setLevel(0); 71 // try setting value smaller than minimal 72 effect.setLevel(-0.1f); 73 assertEquals(-0.1f, (float) effect.getLevel(), 1e-100); 74 pulse(); 75 assertEquals(0.0f, (float) ((com.sun.scenario.effect.Glow)effect.impl_getImpl()).getLevel(), 1e-100); 76 } 77 78 @Test 79 public void testMaxLevel() { 80 // 1 should be ok 81 effect.setLevel(1); 82 // try setting value greater than maximal 83 effect.setLevel(1.1f); 84 assertEquals(1.1f, (float) effect.getLevel(), 1e-100); 85 pulse(); 86 assertEquals(1.0f, (float) ((com.sun.scenario.effect.Glow)effect.impl_getImpl()).getLevel(), 1e-100); 87 } 88 89 @Test 90 public void testCreateWithParams() { 91 effect = new Glow(1); 92 setupTest(effect); 93 assertEquals(1, effect.getLevel(), 1e-100); 94 pulse(); 95 assertEquals(1, ((com.sun.scenario.effect.Glow)effect.impl_getImpl()).getLevel(), 1e-100); 96 } 97 98 @Test 99 public void testLevelSynced() throws Exception { 100 checkDoublePropertySynced( 101 "javafx.scene.effect.Glow", "level", 102 "com.sun.scenario.effect.Glow", "level", 0.5); 103 } 104 105 @Test 106 public void testInputSynced() throws Exception { 107 BoxBlur blur = new BoxBlur(); 108 checkEffectPropertySynced( 109 "javafx.scene.effect.Glow", "input", 110 "com.sun.scenario.effect.Glow", "input", 111 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl()); 112 } 113 114 @Test 115 public void testBounds() { 116 assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal()); 117 } 118 119 @Test 120 public void testBoundsWidthInput() { 121 assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal()); 122 BoxBlur blur = new BoxBlur(); 123 effect.setInput(blur); 124 assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal()); 125 } 126 }