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 com.sun.javafx.FXUnit;
  32 import org.junit.Before;
  33 import org.junit.Rule;
  34 import org.junit.Test;
  35 
  36 public class SepiaToneTest extends EffectsTestBase {
  37 
  38     @Rule
  39     public FXUnit fx = new FXUnit();
  40 
  41     private SepiaTone effect;
  42 
  43     @Before
  44     public void setUp() {
  45         effect = new SepiaTone();
  46         setupTest(effect);
  47     }
  48 
  49     @Test
  50     public void testSetLevel() {
  51         // try setting correct value
  52         effect.setLevel(0.5f);
  53         assertEquals(0.5f, effect.getLevel(), 1e-100);
  54         pulse();
  55         assertEquals(0.5f, ((com.sun.scenario.effect.SepiaTone)effect.impl_getImpl()).getLevel(), 1e-100);
  56     }
  57     
  58     @Test
  59     public void testDefaultLevel() {
  60         // default value should be 1
  61         assertEquals(1f, effect.getLevel(), 1e-100);
  62         assertEquals(1f, effect.levelProperty().get(), 1e-100);
  63         pulse();
  64         assertEquals(1f, ((com.sun.scenario.effect.SepiaTone)effect.impl_getImpl()).getLevel(), 1e-100);
  65     }
  66     
  67     @Test
  68     public void testMinLevel() {
  69         // 0 should be ok
  70         effect.setLevel(0);
  71         // try setting value smaller than minimal
  72         effect.setLevel(-0.1f);
  73         assertEquals(-0.1f, effect.getLevel(), 1e-100);
  74         pulse();
  75         assertEquals(0f, ((com.sun.scenario.effect.SepiaTone)effect.impl_getImpl()).getLevel(), 1e-100);        
  76     }
  77     
  78     @Test
  79     public void testMaxLevel() {
  80         // 1 should be ok
  81         effect.setLevel(1);
  82         // try setting value greater than maximal
  83         effect.setLevel(1.1f); 
  84         assertEquals(1.1f, effect.getLevel(), 1e-100);
  85         pulse();
  86         assertEquals(1f, ((com.sun.scenario.effect.SepiaTone)effect.impl_getImpl()).getLevel(), 1e-100);        
  87     }
  88 
  89     @Test
  90     public void testLevelSynced() throws Exception {
  91         checkDoublePropertySynced(
  92                 "javafx.scene.effect.SepiaTone", "level",
  93                 "com.sun.scenario.effect.SepiaTone", "level", 0.5);
  94     }
  95 
  96     @Test
  97     public void testInputSynced() throws Exception {
  98         BoxBlur blur = new BoxBlur();
  99         checkEffectPropertySynced(
 100                 "javafx.scene.effect.SepiaTone", "input",
 101                 "com.sun.scenario.effect.SepiaTone", "input",
 102                 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl());
 103     }
 104 
 105     @Test
 106     public void testBounds() {
 107         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 108     }
 109 
 110     @Test
 111     public void testBoundsWidthInput() {
 112         assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal());
 113         BoxBlur blur = new BoxBlur();
 114         effect.setInput(blur);
 115         assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal());
 116     }
 117 
 118     @Test
 119     public void testCreateWithParams() {
 120         effect = new SepiaTone(0.1);
 121         setupTest(effect);
 122         assertEquals(0.1, effect.getLevel(), 1e-100);
 123         pulse();
 124         assertEquals(0.1f, ((com.sun.scenario.effect.SepiaTone) effect.impl_getImpl()).getLevel(), 1e-100);
 125     }
 126 
 127     @Test
 128     public void testCreateWithDefaultParams() {
 129         effect = new SepiaTone(1);
 130         setupTest(effect);
 131         assertEquals(1, effect.getLevel(), 1e-100);
 132         pulse();
 133         assertEquals(1f, ((com.sun.scenario.effect.SepiaTone) effect.impl_getImpl()).getLevel(), 1e-100);
 134     }
 135 }