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.Before;
  31 import org.junit.Test;
  32 
  33 public class GaussianBlurTest extends EffectsTestBase {
  34     private GaussianBlur effect;
  35 
  36     @Before
  37     public void setUp() {
  38         effect = new GaussianBlur();
  39         setupTest(effect);
  40     }
  41 
  42     @Test
  43     public void testSetRadius() {
  44         // try setting correct value
  45         effect.setRadius(1.0f);
  46         assertEquals(1.0f, effect.getRadius(), 1e-100);
  47         pulse();
  48         assertEquals(1.0f, ((com.sun.scenario.effect.GaussianBlur)effect.impl_getImpl()).getRadius(), 1e-100);
  49     }
  50     
  51     @Test
  52     public void testDefaultRadius() {
  53         // default value should be 10
  54         assertEquals(10, effect.getRadius(), 1e-10);
  55         assertEquals(10, effect.radiusProperty().get(), 1e-10);
  56         pulse();
  57         assertEquals(10, ((com.sun.scenario.effect.GaussianBlur)effect.impl_getImpl()).getRadius(), 1e-100);
  58     }
  59     
  60     @Test
  61     public void testMinRadius() {
  62         // 0 should be ok
  63         effect.setRadius(0);
  64         // try setting value smaller than minimal
  65         effect.setRadius(-0.1f);
  66         assertEquals(-0.1f, effect.getRadius(), 1e-100);
  67         pulse();
  68         assertEquals(0f, ((com.sun.scenario.effect.GaussianBlur)effect.impl_getImpl()).getRadius(), 1e-100);        
  69     }
  70 
  71     @Test
  72     public void testMaxRadius() {
  73         // 63 should be ok
  74         effect.setRadius(63);
  75         // try setting value greater than maximal
  76         effect.setRadius(63.1f); 
  77         assertEquals(63.1f, effect.getRadius(), 1e-100);
  78         pulse();
  79         assertEquals(63f, ((com.sun.scenario.effect.GaussianBlur)effect.impl_getImpl()).getRadius(), 1e-100);        
  80     }
  81 
  82     @Test
  83     public void testRadiusSynced() throws Exception {
  84         checkDoublePropertySynced(
  85                 "javafx.scene.effect.GaussianBlur", "radius",
  86                 "com.sun.scenario.effect.GaussianBlur", "radius", 15);
  87     }
  88 
  89     @Test
  90     public void testInputSynced() throws Exception {
  91         BoxBlur blur = new BoxBlur();
  92         checkEffectPropertySynced(
  93                 "javafx.scene.effect.GaussianBlur", "input",
  94                 "com.sun.scenario.effect.GaussianBlur", "input",
  95                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
  96     }
  97 
  98     @Test
  99     public void testCreateWithParams() {
 100         effect = new GaussianBlur(4);
 101         setupTest(effect);
 102         assertEquals(4, effect.getRadius(), 1e-100);
 103         pulse();
 104         assertEquals(4f, ((com.sun.scenario.effect.GaussianBlur) effect.impl_getImpl()).getRadius(), 1e-100);
 105     }
 106 
 107     @Test
 108     public void testCreateWithDefaultParams() {
 109         effect = new GaussianBlur(10);
 110         setupTest(effect);
 111         assertEquals(10, effect.getRadius(), 1e-100);
 112         pulse();
 113         assertEquals(10f, ((com.sun.scenario.effect.GaussianBlur) effect.impl_getImpl()).getRadius(), 1e-100);
 114     }
 115 }