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 com.sun.javafx.test.TestHelper.box;
  29 import static org.junit.Assert.assertEquals;
  30 
  31 import org.junit.Before;
  32 import org.junit.Test;
  33 
  34 public class ColorAdjustTest extends EffectsTestBase {
  35     private ColorAdjust effect;
  36 
  37     @Before
  38     public void setUp() {
  39         effect = new ColorAdjust();
  40         setupTest(effect);
  41     }
  42 
  43     @Test
  44     public void testSetBrightness() {
  45         // try setting correct value
  46         effect.setBrightness(1.0f);
  47         assertEquals(1.0f, effect.getBrightness(), 1e-100);
  48         pulse();
  49         assertEquals(1.0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getBrightness(), 1e-100);
  50     }
  51     
  52     @Test
  53     public void testDefaultBrightness() {
  54         // default value should be 0
  55         assertEquals(0f, effect.getBrightness(), 1e-100);
  56         assertEquals(0f, effect.brightnessProperty().get(), 1e-100);
  57         pulse();
  58         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getBrightness(), 1e-100);
  59     }
  60     
  61     @Test
  62     public void testMinBrightness() {
  63         // -1 should be ok
  64         effect.setBrightness(-1);
  65         // try setting value smaller than minimal
  66         effect.setBrightness(-1.1f);
  67         assertEquals(-1.1f, effect.getBrightness(), 1e-100);
  68         pulse();
  69         assertEquals(-1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getBrightness(), 1e-100);
  70     }
  71 
  72     @Test
  73     public void testMaxBrightness() {
  74         // 1 should be ok
  75         effect.setBrightness(1);
  76         // try setting value greater than maximal
  77         effect.setBrightness(1.1f); 
  78         assertEquals(1.1f, effect.getBrightness(), 1e-100);
  79         pulse();
  80         assertEquals(1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getBrightness(), 1e-100);
  81     }
  82         
  83     @Test
  84     public void testSetContrast() {
  85         // try setting correct value
  86         effect.setContrast(0.5);
  87         assertEquals(0.5, effect.getContrast(), 1e-100);
  88         pulse();
  89         assertEquals(0.5, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getContrast(), 1e-100);
  90     }
  91     
  92     @Test
  93     public void testDefaultContrast() {
  94         // default value should be 0
  95         assertEquals(0.0, effect.getContrast(), 1e-100);
  96         assertEquals(0.0, effect.contrastProperty().get(), 1e-100);
  97         pulse();
  98         assertEquals(0.0, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getContrast(), 1e-100);
  99     }
 100     
 101     @Test
 102     public void testMinContrast() {
 103         // -1 should be ok
 104         effect.setContrast(-1.0);
 105         // try setting value smaller than minimal
 106         effect.setContrast(-1.1);
 107         assertEquals(-1.1, effect.getContrast(), 1e-100);
 108         pulse();
 109         assertEquals(-1.0, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getContrast(), 1e-100);
 110     }
 111 
 112     @Test
 113     public void testMaxContrast() {
 114         // 1 should be ok
 115         effect.setContrast(1.0);
 116         // try setting value greater than maximal
 117         effect.setContrast(1.1);
 118         assertEquals(1.1, effect.getContrast(), 1e-100);
 119         pulse();
 120         assertEquals(1.0, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getContrast(), 1e-100);
 121     }
 122         
 123     @Test
 124     public void testSetHue() {
 125         // try setting correct value
 126         effect.setHue(1.0f);
 127         assertEquals(1.0f, effect.getHue(), 1e-100);
 128         pulse();
 129         assertEquals(1.0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getHue(), 1e-100);
 130     }
 131     
 132     @Test
 133     public void testDefaultHue() {
 134         // default value should be 0
 135         assertEquals(0f, effect.getHue(), 1e-100);
 136         assertEquals(0f, effect.hueProperty().get(), 1e-100);
 137         pulse();
 138         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getHue(), 1e-100);
 139     }
 140     
 141     @Test
 142     public void testMinHue() {
 143         // -1 should be ok
 144         effect.setHue(-1);
 145         // try setting value smaller than minimal
 146         effect.setHue(-1.1f);
 147         assertEquals(-1.1f, effect.getHue(), 1e-100);
 148         pulse();
 149         assertEquals(-1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getHue(), 1e-100);
 150     }
 151 
 152     @Test
 153     public void testMaxHue() {
 154         // 1 should be ok
 155         effect.setHue(1);
 156         // try setting value greater than maximal
 157         effect.setHue(1.1f); 
 158         assertEquals(1.1f, effect.getHue(), 1e-100);
 159         pulse();
 160         assertEquals(1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getHue(), 1e-100);
 161     }
 162         
 163     @Test
 164     public void testSetSaturation() {
 165         // try setting correct value
 166         effect.setSaturation(1.0f);
 167         assertEquals(1.0f, effect.getSaturation(), 1e-100);
 168         pulse();
 169         assertEquals(1.0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getSaturation(), 1e-100);
 170     }
 171     
 172     @Test
 173     public void testDefaultSaturation() {
 174         // default value should be 0
 175         assertEquals(0f, effect.getSaturation(), 1e-100);
 176         assertEquals(0f, effect.saturationProperty().get(), 1e-100);
 177         pulse();
 178         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getSaturation(), 1e-100);
 179     }
 180     
 181     @Test
 182     public void testMinSaturation() {
 183         // -1 should be ok
 184         effect.setSaturation(-1);
 185         // try setting value smaller than minimal
 186         effect.setSaturation(-1.1f);
 187         assertEquals(-1.1f, effect.getSaturation(), 1e-100);
 188         pulse();
 189         assertEquals(-1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getSaturation(), 1e-100);
 190     }
 191 
 192     @Test
 193     public void testMaxSaturation() {
 194         // 1 should be ok
 195         effect.setSaturation(1);
 196         // try setting value greater than maximal
 197         effect.setSaturation(1.1f); 
 198         assertEquals(1.1f, effect.getSaturation(), 1e-100);
 199         pulse();
 200         assertEquals(1f, ((com.sun.scenario.effect.ColorAdjust)effect.impl_getImpl()).getSaturation(), 1e-100);
 201     }
 202 
 203     @Test
 204     public void testBrightnessSynced() throws Exception {
 205         checkDoublePropertySynced(
 206                 "javafx.scene.effect.ColorAdjust", "brightness",
 207                 "com.sun.scenario.effect.ColorAdjust", "brightness", 0.3);
 208     }
 209 
 210     @Test
 211     public void testContrastSynced() throws Exception {
 212         checkDoublePropertySynced(
 213                 "javafx.scene.effect.ColorAdjust", "contrast",
 214                 "com.sun.scenario.effect.ColorAdjust", "contrast", 0.3);
 215     }
 216 
 217     @Test
 218     public void testHueSynced() throws Exception {
 219         checkDoublePropertySynced(
 220                 "javafx.scene.effect.ColorAdjust", "hue",
 221                 "com.sun.scenario.effect.ColorAdjust", "hue", 0.3);
 222     }
 223 
 224     @Test
 225     public void testSaturationSynced() throws Exception {
 226         checkDoublePropertySynced(
 227                 "javafx.scene.effect.ColorAdjust", "saturation",
 228                 "com.sun.scenario.effect.ColorAdjust", "saturation", 0.3);
 229     }
 230 
 231     @Test
 232     public void testInputSynced() throws Exception {
 233         BoxBlur blur = new BoxBlur();
 234         checkEffectPropertySynced(
 235                 "javafx.scene.effect.ColorAdjust", "input",
 236                 "com.sun.scenario.effect.ColorAdjust", "input",
 237                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
 238     }
 239 
 240     @Test
 241     public void testBounds() {
 242         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 243     }
 244 
 245     @Test
 246     public void testBoundsWidthInput() {
 247         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 248         BoxBlur blur = new BoxBlur();
 249         effect.setInput(blur);
 250         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 251     }
 252 
 253     @Test
 254     public void testCreateWithParams() {
 255         effect = new ColorAdjust(-.5, 0.5, -0.1, 0.1);
 256         setupTest(effect);
 257         assertEquals(-0.5, effect.getHue(), 1e-100);
 258         assertEquals(0.5, effect.getSaturation(), 1e-100);
 259         assertEquals(-0.1, effect.getBrightness(), 1e-100);
 260         assertEquals(0.1, effect.getContrast(), 1e-100);
 261         pulse();
 262         assertEquals(-0.5f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getHue(), 1e-100);
 263         assertEquals(0.5f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getSaturation(), 1e-100);
 264         assertEquals(-0.1f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getBrightness(), 1e-100);
 265         assertEquals(0.1f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getContrast(), 1e-100);
 266     }
 267     
 268     @Test
 269     public void testCreateWithDefaultParams() {
 270         effect = new ColorAdjust(0, 0, 0, 0);
 271         setupTest(effect);
 272         assertEquals(0, effect.getHue(), 1e-100);
 273         assertEquals(0, effect.getSaturation(), 1e-100);
 274         assertEquals(0, effect.getBrightness(), 1e-100);
 275         assertEquals(0, effect.getContrast(), 1e-100);
 276         pulse();
 277         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getHue(), 1e-100);
 278         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getSaturation(), 1e-100);
 279         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getBrightness(), 1e-100);
 280         assertEquals(0f, ((com.sun.scenario.effect.ColorAdjust) effect.impl_getImpl()).getContrast(), 1e-100);
 281     }
 282 }