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