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.Reflection;
  30 import static org.junit.Assert.assertEquals;
  31 
  32 import org.junit.Before;
  33 import org.junit.Test;
  34 
  35 public class ReflectionTest extends EffectsTestBase {
  36     private Reflection effect;
  37 
  38     @Before
  39     public void setUp() {
  40         effect = new Reflection();
  41         setupTest(effect);
  42     }
  43 
  44     @Test
  45     public void testSetTopOpacity() {
  46         // try setting correct value
  47         effect.setTopOpacity(1.0f);
  48         assertEquals(1.0f, effect.getTopOpacity(), 1e-100);
  49         pulse();
  50         assertEquals(1.0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
  51     }
  52     
  53     @Test
  54     public void testDefaultTopOpacity() {
  55         // default value should be 0.5
  56         assertEquals(0.5f, effect.getTopOpacity(), 1e-100);
  57         assertEquals(0.5f, effect.topOpacityProperty().get(), 1e-100);
  58         pulse();
  59         assertEquals(0.5f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
  60     }
  61     
  62     @Test
  63     public void testMinTopOpacity() {
  64         // 0 should be ok
  65         effect.setTopOpacity(0);
  66         // try setting value smaller than minimal
  67         effect.setTopOpacity(-0.1f);
  68         assertEquals(-0.1f, effect.getTopOpacity(), 1e-100);
  69         pulse();
  70         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
  71     }
  72 
  73     @Test
  74     public void testMaxTopOpacity() {
  75         // 1 should be ok
  76         effect.setTopOpacity(1);
  77         // try setting value greater than maximal
  78         effect.setTopOpacity(1.1f); 
  79         assertEquals(1.1f, effect.getTopOpacity(), 1e-100);
  80         pulse();
  81         assertEquals(1f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
  82     }    
  83     
  84     @Test
  85     public void testSetBottomOpacity() {
  86         // try setting correct value
  87         effect.setBottomOpacity(1.0f);
  88         assertEquals(1.0f, effect.getBottomOpacity(), 1e-100);
  89         pulse();
  90         assertEquals(1.0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);
  91     }
  92     
  93     @Test
  94     public void testDefaultBottomOpacity() {
  95         // default value should be 1
  96         assertEquals(0f, effect.getBottomOpacity(), 1e-100);
  97         assertEquals(0f, effect.bottomOpacityProperty().get(), 1e-100);
  98         pulse();
  99         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);
 100     }
 101     
 102     @Test
 103     public void testMinBottomOpacity() {
 104         // 0 should be ok
 105         effect.setBottomOpacity(0);
 106         // try setting value smaller than minimal
 107         effect.setBottomOpacity(-0.1f);
 108         assertEquals(-0.1f, effect.getBottomOpacity(), 1e-100);
 109         pulse();
 110         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);       
 111     }
 112 
 113     @Test
 114     public void testMaxBottomOpacity() {
 115         // 1 should be ok
 116         effect.setBottomOpacity(1);
 117         // try setting value greater than maximal
 118         effect.setBottomOpacity(1.1f);
 119         assertEquals(1.1f, effect.getBottomOpacity(), 1e-100);
 120         pulse();
 121         assertEquals(1f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);        
 122     }    
 123     
 124     @Test
 125     public void testSetFraction() {
 126         // try setting correct value
 127         effect.setFraction(1.0f);
 128         assertEquals(1.0f, effect.getFraction(), 1e-100);
 129         pulse();
 130         assertEquals(1.0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);
 131     }
 132     
 133     @Test
 134     public void testDefaultFraction() {
 135         // default value should be 0.75
 136         assertEquals(0.75f, effect.getFraction(), 1e-100);
 137         assertEquals(0.75f, effect.fractionProperty().get(), 1e-100);
 138         pulse();
 139         assertEquals(0.75f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);
 140     }
 141     
 142     @Test
 143     public void testMinFraction() {
 144         // 0 should be ok
 145         effect.setFraction(0);
 146         // try setting value smaller than minimal
 147         effect.setFraction(-0.1f);
 148         assertEquals(-0.1f, effect.getFraction(), 1e-100);
 149         pulse();
 150         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);      
 151     }
 152 
 153     @Test
 154     public void testMaxFraction() {
 155         // 1 should be ok
 156         effect.setFraction(1);
 157         // try setting value greater than maximal
 158         effect.setFraction(1.1f);
 159         assertEquals(1.1f, effect.getFraction(), 1e-100);
 160         pulse();
 161         assertEquals(1f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);
 162     }
 163     
 164     @Test
 165     public void testSetTopOffset() {
 166         // try setting correct value
 167         effect.setTopOffset(1.0f);
 168         assertEquals(1.0f, effect.getTopOffset(), 1e-100);
 169         pulse();
 170         assertEquals(1.0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOffset(), 1e-100);
 171     }
 172     
 173     @Test
 174     public void testDefaultTopOffset() {
 175         // default value should be 0
 176         assertEquals(0f, effect.getTopOffset(), 1e-100);
 177         assertEquals(0f, effect.topOffsetProperty().get(), 1e-100);
 178         pulse();
 179         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOffset(), 1e-100);
 180     }
 181 
 182     @Test
 183     public void testBottomOpacitySynced() throws Exception {
 184         checkDoublePropertySynced(
 185                 "javafx.scene.effect.Reflection", "bottomOpacity",
 186                 "com.sun.scenario.effect.Reflection", "bottomOpacity", 0.3);
 187     }
 188 
 189     @Test
 190     public void testTopOpacitySynced() throws Exception {
 191         checkDoublePropertySynced(
 192                 "javafx.scene.effect.Reflection", "topOpacity",
 193                 "com.sun.scenario.effect.Reflection", "topOpacity", 0.3);
 194     }
 195 
 196     @Test
 197     public void testTopOffsetSynced() throws Exception {
 198         checkDoublePropertySynced(
 199                 "javafx.scene.effect.Reflection", "topOffset",
 200                 "com.sun.scenario.effect.Reflection", "topOffset", 15);
 201     }
 202 
 203     @Test
 204     public void testFractionSynced() throws Exception {
 205         checkDoublePropertySynced(
 206                 "javafx.scene.effect.Reflection", "fraction",
 207                 "com.sun.scenario.effect.Reflection", "fraction", 0.5);
 208     }
 209 
 210     @Test
 211     public void testInputSynced() throws Exception {
 212         BoxBlur blur = new BoxBlur();
 213         checkEffectPropertySynced(
 214                 "javafx.scene.effect.Reflection", "input",
 215                 "com.sun.scenario.effect.Reflection", "input",
 216                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
 217     }
 218 
 219     @Test
 220     public void testCreateWithParams() {
 221         effect = new Reflection(1, 0.2, 0.4, 0.5);
 222         setupTest(effect);
 223         assertEquals(1, effect.getTopOffset(), 1e-100);
 224         assertEquals(0.2, effect.getFraction(), 1e-100);
 225         assertEquals(0.4, effect.getTopOpacity(), 1e-100);
 226         assertEquals(0.5, effect.getBottomOpacity(), 1e-100);
 227         pulse();
 228         assertEquals(1.0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOffset(), 1e-100);
 229         assertEquals(0.2f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);
 230         assertEquals(0.4f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
 231         assertEquals(0.5f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);
 232     }
 233 
 234     @Test
 235     public void testCreateWithDefaultParams() {
 236         effect = new Reflection(0, 0.75, 0.5, 1);
 237         setupTest(effect);
 238         assertEquals(0, effect.getTopOffset(), 1e-100);
 239         assertEquals(0.75, effect.getFraction(), 1e-100);
 240         assertEquals(0.5, effect.getTopOpacity(), 1e-100);
 241         assertEquals(1, effect.getBottomOpacity(), 1e-100);
 242         pulse();
 243         assertEquals(0f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOffset(), 1e-100);
 244         assertEquals(0.75f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getFraction(), 1e-100);
 245         assertEquals(0.5f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getTopOpacity(), 1e-100);
 246         assertEquals(1f, ((com.sun.scenario.effect.Reflection)effect.impl_getImpl()).getBottomOpacity(), 1e-100);
 247     }
 248 }