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 
  30 import org.junit.After;
  31 import org.junit.Before;
  32 import org.junit.Test;
  33 
  34 public class BoxBlurTest extends EffectsTestBase {
  35     private BoxBlur effect;
  36 
  37     @Before
  38     public void setUp() {
  39         effect = new BoxBlur();
  40         setupTest(effect);
  41     }
  42 
  43     @After
  44     public void tearDown() {
  45     }
  46 
  47     @Test
  48     public void testSetWidth() {
  49         // try setting correct value
  50         effect.setWidth(1.0f);
  51         assertEquals(1.0f, effect.getWidth(), 1e-100);
  52         pulse();
  53         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
  54     }
  55     
  56     @Test
  57     public void testDefaultWidth() {
  58         // default value should be 5
  59         assertEquals(5.0f, effect.getWidth(), 1e-100);
  60         assertEquals(5.0f, effect.widthProperty().get(), 1e-100);
  61         pulse();
  62         assertEquals(5, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
  63     }
  64     
  65     @Test
  66     public void testMinWidth() {
  67         // 0 should be ok
  68         effect.setWidth(0);
  69         // try setting value smaller than minimal
  70         effect.setWidth(-0.1f);
  71         assertEquals(-0.1f, effect.getWidth(), 1e-100);
  72         pulse();
  73         assertEquals(0, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
  74     }
  75 
  76     @Test
  77     public void testMaxWidth() {
  78         // 255 should be ok
  79         effect.setWidth(255);
  80         // try setting value greater than maximal
  81         effect.setWidth(255.1f); 
  82         assertEquals(255.1f, effect.getWidth(), 1e-100);
  83         pulse();
  84         assertEquals(255, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
  85     }
  86     
  87     @Test
  88     public void testSetHeight() {
  89         // try setting correct value
  90         effect.setHeight(1.0f);
  91         assertEquals(1.0f, effect.getHeight(), 1e-100);
  92         pulse();
  93         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
  94     }
  95     
  96     @Test
  97     public void testDefaultHeight() {
  98         // default value should be 5
  99         assertEquals(5.0f, effect.getHeight(), 1e-100);
 100         assertEquals(5.0f, effect.heightProperty().get(), 1e-100);
 101         pulse();
 102         assertEquals(5, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
 103     }
 104     
 105     @Test
 106     public void testMinHeight() {
 107         // 0 should be ok
 108         effect.setHeight(0);
 109         // try setting value smaller than minimal
 110         effect.setHeight(-0.1f);
 111         assertEquals(-0.1f, effect.getHeight(), 1e-100);
 112         pulse();
 113         assertEquals(0, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
 114     }
 115 
 116     @Test
 117     public void testMaxHeight() {
 118         // 255 should be ok
 119         effect.setHeight(255);
 120         // try setting value greater than maximal
 121         effect.setHeight(255.1f); 
 122         assertEquals(255.1f, effect.getHeight(), 1e-100);
 123         pulse();
 124         assertEquals(255, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
 125     }
 126     
 127     @Test
 128     public void testSetIterations() {
 129         // try setting correct value
 130         effect.setIterations(2);
 131         assertEquals(2, effect.getIterations());
 132         pulse();
 133         assertEquals(2, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 134     }
 135     
 136     @Test
 137     public void testDefaultIterations() {
 138         // default value should be 1
 139         assertEquals(1, effect.getIterations());
 140         assertEquals(1, effect.iterationsProperty().get());
 141         pulse();
 142         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 143     }
 144     
 145     @Test
 146     public void testMinIterations() {
 147         // 0 should be ok
 148         effect.setIterations(0);
 149         // try setting value smaller than minimal
 150         effect.setIterations(-1);
 151         assertEquals(-1, effect.getIterations());
 152         pulse();
 153         assertEquals(0, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 154     }
 155 
 156     @Test
 157     public void testMaxIterations() {
 158         // 3 should be ok
 159         effect.setIterations(3);
 160         // try setting value greater than maximal
 161         effect.setIterations(4); 
 162         assertEquals(4, effect.getIterations());
 163         pulse();
 164         assertEquals(3, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 165     }
 166 
 167     @Test
 168     public void testCreateWithParams() {
 169         effect = new BoxBlur(1, 1, 3);
 170         setupTest(effect);
 171         assertEquals(1, effect.getWidth(), 1e-100);
 172         assertEquals(1, effect.getHeight(), 1e-100);
 173         assertEquals(3, effect.getIterations());
 174         pulse();
 175         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
 176         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
 177         assertEquals(3, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 178     }
 179 
 180     @Test
 181     public void testCreateWithDefaultParams() {
 182         effect = new BoxBlur(5, 5, 1);
 183         setupTest(effect);
 184         assertEquals(5, effect.getWidth(), 1e-100);
 185         assertEquals(5, effect.getHeight(), 1e-100);
 186         assertEquals(1, effect.getIterations());
 187         pulse();
 188         assertEquals(5, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getHorizontalSize());
 189         assertEquals(5, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getVerticalSize());
 190         assertEquals(1, ((com.sun.scenario.effect.BoxBlur)effect.impl_getImpl()).getPasses());
 191     }
 192 
 193     @Test
 194     public void testHeightSynced() throws Exception {
 195         checkDoublePropertySynced(
 196                 "javafx.scene.effect.BoxBlur", "height",
 197                 "com.sun.scenario.effect.BoxBlur", "verticalSize", 10);
 198     }
 199 
 200     @Test
 201     public void testWidthSynced() throws Exception {
 202         checkDoublePropertySynced(
 203                 "javafx.scene.effect.BoxBlur", "width",
 204                 "com.sun.scenario.effect.BoxBlur", "horizontalSize", 10);
 205     }
 206 
 207     @Test
 208     public void testIterationsSynced() throws Exception {
 209         checkIntPropertySynced(
 210                 "javafx.scene.effect.BoxBlur", "iterations",
 211                 "com.sun.scenario.effect.BoxBlur", "passes", 2);
 212     }
 213 
 214     @Test
 215     public void testInputSynced() throws Exception {
 216         BoxBlur blur = new BoxBlur();
 217         checkEffectPropertySynced(
 218                 "javafx.scene.effect.BoxBlur", "input",
 219                 "com.sun.scenario.effect.BoxBlur", "input",
 220                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
 221     }
 222 }