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.MotionBlur;
  30 import static org.junit.Assert.assertEquals;
  31 
  32 import org.junit.Before;
  33 import org.junit.Test;
  34 
  35 public class MotionBlurTest extends EffectsTestBase {
  36     private MotionBlur effect;
  37 
  38     @Before
  39     public void setUp() {
  40         effect = new MotionBlur();
  41         setupTest(effect);
  42     }
  43 
  44     @Test
  45     public void testSetAngle() {
  46         // try setting correct value
  47         effect.setAngle(1.5f);
  48         assertEquals(1.5f, effect.getAngle(), 1e-100);
  49         pulse();
  50         assertEquals(1.5f, Math.toDegrees(((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getAngle()), 1e-5);
  51     }
  52     
  53     @Test
  54     public void testDefaultAngle() {
  55         // default value should be 0
  56         assertEquals(0f, effect.getAngle(), 1e-100);
  57         assertEquals(0f, effect.angleProperty().get(), 1e-100);
  58         pulse();
  59         assertEquals(0f, ((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getAngle(), 1e-100);
  60     }
  61     
  62     @Test
  63     public void testSetRadius() {
  64         // try setting correct value
  65         effect.setRadius(0.5f);
  66         assertEquals(0.5f, effect.getRadius(), 1e-100);
  67         pulse();
  68         assertEquals(0.5f, ((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getRadius(), 1e-100);
  69     }
  70     
  71     @Test
  72     public void testDefaultRadius() {
  73         // default value should be 10
  74         assertEquals(10f, effect.getRadius(), 1e-100);
  75         assertEquals(10f, effect.radiusProperty().get(), 1e-100);
  76         pulse();
  77         assertEquals(10f, ((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getRadius(), 1e-100);
  78     }
  79     
  80     @Test
  81     public void testMinRadius() {
  82         // 0 should be ok
  83         effect.setRadius(0);
  84         // try setting value smaller than minimal
  85         effect.setRadius(-0.1f);
  86         assertEquals(-0.1f, effect.getRadius(), 1e-100);
  87         pulse();
  88         assertEquals(0f, ((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getRadius(), 1e-100);        
  89     }
  90     
  91     @Test
  92     public void testMaxRadius() {
  93         // 63 should be ok
  94         effect.setRadius(63);
  95         // try setting value greater than maximal
  96         effect.setRadius(63.1f); 
  97         assertEquals(63.1f, effect.getRadius(), 1e-100);
  98         pulse();
  99         assertEquals(63f, ((com.sun.scenario.effect.MotionBlur)effect.impl_getImpl()).getRadius(), 1e-100);        
 100     }
 101 
 102     @Test
 103     public void testAngleSynced() throws Exception {
 104         float result = (Float)getDoublePropertySynced(
 105                 "javafx.scene.effect.MotionBlur", "angle",
 106                 "com.sun.scenario.effect.MotionBlur", "angle", 10);
 107         assertEquals(10, Math.toDegrees(result), 1e-5);
 108     }
 109 
 110     @Test
 111     public void testRadiusSynced() throws Exception {
 112         checkDoublePropertySynced(
 113                 "javafx.scene.effect.MotionBlur", "radius",
 114                 "com.sun.scenario.effect.MotionBlur", "radius", 15);
 115     }
 116 
 117     @Test
 118     public void testInputSynced() throws Exception {
 119         BoxBlur blur = new BoxBlur();
 120         checkEffectPropertySynced(
 121                 "javafx.scene.effect.MotionBlur", "input",
 122                 "com.sun.scenario.effect.MotionBlur", "input",
 123                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
 124     }
 125     
 126     @Test
 127     public void testCreateWithParams() {
 128         effect = new MotionBlur(1, 2);
 129         setupTest(effect);
 130         assertEquals(1, effect.getAngle(), 1e-100);
 131         assertEquals(2, effect.getRadius(), 1e-100);
 132         pulse();
 133         assertEquals(1.0f, Math.toDegrees(((com.sun.scenario.effect.MotionBlur) effect.impl_getImpl()).getAngle()), 1e-5);
 134         assertEquals(2.0f, ((com.sun.scenario.effect.MotionBlur) effect.impl_getImpl()).getRadius(), 1e-100);
 135     }
 136 
 137     @Test
 138     public void testCreateWithDefaultParams() {
 139         effect = new MotionBlur(0, 10);
 140         setupTest(effect);
 141         assertEquals(0, effect.getAngle(), 1e-100);
 142         assertEquals(10, effect.getRadius(), 1e-100);
 143         pulse();
 144         assertEquals(0f, Math.toDegrees(((com.sun.scenario.effect.MotionBlur) effect.impl_getImpl()).getAngle()), 1e-5);
 145         assertEquals(10f, ((com.sun.scenario.effect.MotionBlur) effect.impl_getImpl()).getRadius(), 1e-100);
 146     }
 147 }