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