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.EffectShim; 30 import static org.junit.Assert.assertEquals; 31 32 import org.junit.After; 33 import org.junit.Before; 34 import org.junit.Test; 35 import test.javafx.scene.effect.EffectsTestBase; 36 37 public class BoxBlurTest extends EffectsTestBase { 38 private BoxBlur effect; 39 40 @Before 41 public void setUp() { 42 effect = new BoxBlur(); 43 setupTest(effect); 44 } 45 46 @After 47 public void tearDown() { 48 } 49 50 @Test 51 public void testSetWidth() { 52 // try setting correct value 53 effect.setWidth(1.0f); 54 assertEquals(1.0f, effect.getWidth(), 1e-100); 55 pulse(); 56 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 57 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 58 } 59 60 @Test 61 public void testDefaultWidth() { 62 // default value should be 5 63 assertEquals(5.0f, effect.getWidth(), 1e-100); 64 assertEquals(5.0f, effect.widthProperty().get(), 1e-100); 65 pulse(); 66 assertEquals(5, ((com.sun.scenario.effect.BoxBlur) 67 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 68 } 69 70 @Test 71 public void testMinWidth() { 72 // 0 should be ok 73 effect.setWidth(0); 74 // try setting value smaller than minimal 75 effect.setWidth(-0.1f); 76 assertEquals(-0.1f, effect.getWidth(), 1e-100); 77 pulse(); 78 assertEquals(0, ((com.sun.scenario.effect.BoxBlur) 79 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 80 } 81 82 @Test 83 public void testMaxWidth() { 84 // 255 should be ok 85 effect.setWidth(255); 86 // try setting value greater than maximal 87 effect.setWidth(255.1f); 88 assertEquals(255.1f, effect.getWidth(), 1e-100); 89 pulse(); 90 assertEquals(255, ((com.sun.scenario.effect.BoxBlur) 91 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 92 } 93 94 @Test 95 public void testSetHeight() { 96 // try setting correct value 97 effect.setHeight(1.0f); 98 assertEquals(1.0f, effect.getHeight(), 1e-100); 99 pulse(); 100 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 101 EffectShim.impl_getImpl(effect)).getVerticalSize()); 102 } 103 104 @Test 105 public void testDefaultHeight() { 106 // default value should be 5 107 assertEquals(5.0f, effect.getHeight(), 1e-100); 108 assertEquals(5.0f, effect.heightProperty().get(), 1e-100); 109 pulse(); 110 assertEquals(5, ((com.sun.scenario.effect.BoxBlur) 111 EffectShim.impl_getImpl(effect)).getVerticalSize()); 112 } 113 114 @Test 115 public void testMinHeight() { 116 // 0 should be ok 117 effect.setHeight(0); 118 // try setting value smaller than minimal 119 effect.setHeight(-0.1f); 120 assertEquals(-0.1f, effect.getHeight(), 1e-100); 121 pulse(); 122 assertEquals(0, ((com.sun.scenario.effect.BoxBlur) 123 EffectShim.impl_getImpl(effect)).getVerticalSize()); 124 } 125 126 @Test 127 public void testMaxHeight() { 128 // 255 should be ok 129 effect.setHeight(255); 130 // try setting value greater than maximal 131 effect.setHeight(255.1f); 132 assertEquals(255.1f, effect.getHeight(), 1e-100); 133 pulse(); 134 assertEquals(255, ((com.sun.scenario.effect.BoxBlur) 135 EffectShim.impl_getImpl(effect)).getVerticalSize()); 136 } 137 138 @Test 139 public void testSetIterations() { 140 // try setting correct value 141 effect.setIterations(2); 142 assertEquals(2, effect.getIterations()); 143 pulse(); 144 assertEquals(2, ((com.sun.scenario.effect.BoxBlur) 145 EffectShim.impl_getImpl(effect)).getPasses()); 146 } 147 148 @Test 149 public void testDefaultIterations() { 150 // default value should be 1 151 assertEquals(1, effect.getIterations()); 152 assertEquals(1, effect.iterationsProperty().get()); 153 pulse(); 154 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 155 EffectShim.impl_getImpl(effect)).getPasses()); 156 } 157 158 @Test 159 public void testMinIterations() { 160 // 0 should be ok 161 effect.setIterations(0); 162 // try setting value smaller than minimal 163 effect.setIterations(-1); 164 assertEquals(-1, effect.getIterations()); 165 pulse(); 166 assertEquals(0, ((com.sun.scenario.effect.BoxBlur) 167 EffectShim.impl_getImpl(effect)).getPasses()); 168 } 169 170 @Test 171 public void testMaxIterations() { 172 // 3 should be ok 173 effect.setIterations(3); 174 // try setting value greater than maximal 175 effect.setIterations(4); 176 assertEquals(4, effect.getIterations()); 177 pulse(); 178 assertEquals(3, ((com.sun.scenario.effect.BoxBlur) 179 EffectShim.impl_getImpl(effect)).getPasses()); 180 } 181 182 @Test 183 public void testCreateWithParams() { 184 effect = new BoxBlur(1, 1, 3); 185 setupTest(effect); 186 assertEquals(1, effect.getWidth(), 1e-100); 187 assertEquals(1, effect.getHeight(), 1e-100); 188 assertEquals(3, effect.getIterations()); 189 pulse(); 190 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 191 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 192 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 193 EffectShim.impl_getImpl(effect)).getVerticalSize()); 194 assertEquals(3, ((com.sun.scenario.effect.BoxBlur) 195 EffectShim.impl_getImpl(effect)).getPasses()); 196 } 197 198 @Test 199 public void testCreateWithDefaultParams() { 200 effect = new BoxBlur(5, 5, 1); 201 setupTest(effect); 202 assertEquals(5, effect.getWidth(), 1e-100); 203 assertEquals(5, effect.getHeight(), 1e-100); 204 assertEquals(1, effect.getIterations()); 205 pulse(); 206 assertEquals(5, ((com.sun.scenario.effect.BoxBlur) 207 EffectShim.impl_getImpl(effect)).getHorizontalSize()); 208 assertEquals(5, ((com.sun.scenario.effect.BoxBlur) 209 EffectShim.impl_getImpl(effect)).getVerticalSize()); 210 assertEquals(1, ((com.sun.scenario.effect.BoxBlur) 211 EffectShim.impl_getImpl(effect)).getPasses()); 212 } 213 214 @Test 215 public void testHeightSynced() throws Exception { 216 checkDoublePropertySynced( 217 "javafx.scene.effect.BoxBlur", "height", 218 "com.sun.scenario.effect.BoxBlur", "verticalSize", 10); 219 } 220 221 @Test 222 public void testWidthSynced() throws Exception { 223 checkDoublePropertySynced( 224 "javafx.scene.effect.BoxBlur", "width", 225 "com.sun.scenario.effect.BoxBlur", "horizontalSize", 10); 226 } 227 228 @Test 229 public void testIterationsSynced() throws Exception { 230 checkIntPropertySynced( 231 "javafx.scene.effect.BoxBlur", "iterations", 232 "com.sun.scenario.effect.BoxBlur", "passes", 2); 233 } 234 235 @Test 236 public void testInputSynced() throws Exception { 237 BoxBlur blur = new BoxBlur(); 238 checkEffectPropertySynced( 239 "javafx.scene.effect.BoxBlur", "input", 240 "com.sun.scenario.effect.BoxBlur", "input", 241 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl()); 242 } 243 }