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