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.DisplacementMap; 30 import javafx.scene.effect.FloatMap; 31 import static test.com.sun.javafx.test.TestHelper.box; 32 import static org.junit.Assert.assertEquals; 33 import static org.junit.Assert.assertFalse; 34 import static org.junit.Assert.assertNotNull; 35 import static org.junit.Assert.assertNull; 36 import static org.junit.Assert.assertTrue; 37 38 import org.junit.Before; 39 import org.junit.Test; 40 41 public class DisplacementMapTest extends EffectsTestBase { 42 private DisplacementMap effect; 43 44 @Before 45 public void setUp() { 46 effect = new DisplacementMap(); 47 setupTest(effect); 48 } 49 50 @Test 51 public void testSetOffsetX() { 52 // try setting correct value 53 effect.setOffsetX(1.0f); 54 assertEquals(1.0f, effect.getOffsetX(), 1e-100); 55 pulse(); 56 assertEquals(1.0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetX(), 1e-100); 57 } 58 59 @Test 60 public void testDefaultOffsetX() { 61 // default value should be 0 62 assertEquals(0f, effect.getOffsetX(), 1e-100); 63 assertEquals(0f, effect.offsetXProperty().get(), 1e-100); 64 pulse(); 65 assertEquals(0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetX(), 1e-100); 66 } 67 68 @Test 69 public void testSetOffsetY() { 70 // try setting correct value 71 effect.setOffsetY(1.0f); 72 assertEquals(1.0f, effect.getOffsetY(), 1e-100); 73 pulse(); 74 assertEquals(1.0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetY(), 1e-100); 75 } 76 77 @Test 78 public void testDefaultOffsetY() { 79 // default value should be 0 80 assertEquals(0f, effect.getOffsetY(), 1e-100); 81 assertEquals(0f, effect.offsetYProperty().get(), 1e-100); 82 pulse(); 83 assertEquals(0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetY(), 1e-100); 84 } 85 86 @Test 87 public void testSetScaleX() { 88 // try setting correct value 89 effect.setScaleX(1.1f); 90 assertEquals(1.1f, effect.getScaleX(), 1e-100); 91 pulse(); 92 assertEquals(1.1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleX(), 1e-100); 93 } 94 95 @Test 96 public void testDefaultScaleX() { 97 // default value should be 1 98 assertEquals(1f, effect.getScaleX(), 1e-100); 99 assertEquals(1f, effect.scaleXProperty().get(), 1e-100); 100 pulse(); 101 assertEquals(1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleX(), 1e-100); 102 } 103 104 @Test 105 public void testSetScaleY() { 106 // try setting correct value 107 effect.setScaleY(1.1f); 108 assertEquals(1.1f, effect.getScaleY(), 1e-100); 109 pulse(); 110 assertEquals(1.1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleY(), 1e-100); 111 } 112 113 @Test 114 public void testDefaultScaleY() { 115 // default value should be 1 116 assertEquals(1f, effect.getScaleY(), 1e-100); 117 assertEquals(1f, effect.scaleYProperty().get(), 1e-100); 118 pulse(); 119 assertEquals(1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleY(), 1e-100); 120 } 121 122 @Test 123 public void testSetWrap() { 124 // try setting correct value 125 effect.setWrap(true); 126 assertTrue(effect.isWrap()); 127 pulse(); 128 assertTrue(((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getWrap()); 129 } 130 131 @Test 132 public void testDefaultWrap() { 133 // default value should be false 134 assertFalse(effect.isWrap()); 135 assertFalse(effect.wrapProperty().get()); 136 pulse(); 137 assertFalse(((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getWrap()); 138 } 139 140 private FloatMap createFloatMap(int width, int height) { 141 FloatMap map = new FloatMap(); 142 map.setWidth(width); 143 map.setHeight(height); 144 145 for (int i = 0; i < width; i++) { 146 double v = 1.0; 147 for (int j = 0; j < height; j++) { 148 map.setSamples(i, j, 0.0f, (float) v); 149 } 150 } 151 152 return map; 153 } 154 155 @Test 156 public void testSetMap() { 157 int w = 100; 158 int h = 50; 159 160 FloatMap map = createFloatMap(w, h); 161 map.setWidth(w); 162 map.setHeight(h); 163 164 effect.setMapData(map); 165 166 assertEquals(w, map.getWidth()); 167 assertEquals(h, map.getHeight()); 168 pulse(); 169 com.sun.scenario.effect.FloatMap mapImpl = 170 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 171 assertNotNull(mapImpl); 172 assertEquals(w, mapImpl.getWidth()); 173 assertEquals(h, mapImpl.getHeight()); 174 } 175 176 @Test 177 public void testDefaultMap() { 178 // Default is empty map 179 FloatMap map = effect.getMapData(); 180 assertNotNull(map); 181 assertEquals(1, map.getWidth()); 182 assertEquals(1, map.getHeight()); 183 pulse(); 184 com.sun.scenario.effect.FloatMap mapImpl = 185 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 186 assertNotNull(mapImpl); 187 assertEquals(1, mapImpl.getWidth()); 188 assertEquals(1, mapImpl.getHeight()); 189 190 assertEquals(map, effect.mapDataProperty().get()); 191 } 192 193 @Test 194 public void testDefaultMapNotChangedByThisEffect() { 195 // Default is empty map 196 FloatMap map = effect.getMapData(); 197 map.setHeight(100); 198 map.setWidth(200); 199 200 effect.setMapData(null); 201 202 // null map data should default to empty map 203 assertNull(effect.getMapData()); 204 pulse(); 205 com.sun.scenario.effect.FloatMap mapImpl = 206 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 207 assertNotNull(mapImpl); 208 assertEquals(1, mapImpl.getWidth()); 209 assertEquals(1, mapImpl.getHeight()); 210 } 211 212 @Test 213 public void testOffsetXSynced() throws Exception { 214 checkDoublePropertySynced( 215 "javafx.scene.effect.DisplacementMap", "offsetX", 216 "com.sun.scenario.effect.DisplacementMap", "offsetX", 10); 217 } 218 219 @Test 220 public void testOffsetYSynced() throws Exception { 221 checkDoublePropertySynced( 222 "javafx.scene.effect.DisplacementMap", "offsetY", 223 "com.sun.scenario.effect.DisplacementMap", "offsetY", 10); 224 } 225 226 @Test 227 public void testScaleXSynced() throws Exception { 228 checkDoublePropertySynced( 229 "javafx.scene.effect.DisplacementMap", "scaleX", 230 "com.sun.scenario.effect.DisplacementMap", "scaleX", 10); 231 } 232 233 @Test 234 public void testScaleYSynced() throws Exception { 235 checkDoublePropertySynced( 236 "javafx.scene.effect.DisplacementMap", "scaleY", 237 "com.sun.scenario.effect.DisplacementMap", "scaleY", 10); 238 } 239 240 @Test 241 public void testWrapSynced() throws Exception { 242 checkBooleanPropertySynced( 243 "javafx.scene.effect.DisplacementMap", "wrap", 244 "com.sun.scenario.effect.DisplacementMap", "wrap", true); 245 } 246 247 @Test 248 public void testInputSynced() throws Exception { 249 BoxBlur blur = new BoxBlur(); 250 checkEffectPropertySynced( 251 "javafx.scene.effect.DisplacementMap", "input", 252 "com.sun.scenario.effect.DisplacementMap", "contentInput", 253 blur, (com.sun.scenario.effect.BoxBlur)blur.impl_getImpl()); 254 } 255 256 @Test 257 public void testBounds() { 258 assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal()); 259 } 260 261 @Test 262 public void testBoundsWidthInput() { 263 assertEquals(box(0, 0, 100, 100), n.getBoundsInLocal()); 264 BoxBlur blur = new BoxBlur(); 265 effect.setInput(blur); 266 assertEquals(box(-2, -2, 104, 104), n.getBoundsInLocal()); 267 } 268 269 @Test 270 public void testCreateWithParams() { 271 int w = 100; 272 int h = 50; 273 274 FloatMap map = createFloatMap(w, h); 275 effect = new DisplacementMap(map); 276 setupTest(effect); 277 assertEquals(map, effect.getMapData()); 278 pulse(); 279 com.sun.scenario.effect.FloatMap mapImpl = 280 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 281 assertNotNull(mapImpl); 282 assertEquals(w, mapImpl.getWidth()); 283 assertEquals(h, mapImpl.getHeight()); 284 } 285 286 @Test 287 public void testCreateWithParams5() { 288 int w = 100; 289 int h = 50; 290 291 FloatMap map = createFloatMap(w, h); 292 effect = new DisplacementMap(map, 1, 2, 3, 4); 293 setupTest(effect); 294 assertEquals(1, effect.getOffsetX(), 1e-100); 295 assertEquals(2, effect.getOffsetY(), 1e-100); 296 assertEquals(3, effect.getScaleX(), 1e-100); 297 assertEquals(4, effect.getScaleY(), 1e-100); 298 assertEquals(map, effect.getMapData()); 299 pulse(); 300 assertEquals(1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetX(), 1e-100); 301 assertEquals(2f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetY(), 1e-100); 302 assertEquals(3f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleX(), 1e-100); 303 assertEquals(4f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleY(), 1e-100); 304 com.sun.scenario.effect.FloatMap mapImpl = 305 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 306 assertNotNull(mapImpl); 307 assertEquals(w, mapImpl.getWidth()); 308 assertEquals(h, mapImpl.getHeight()); 309 } 310 311 @Test 312 public void testCreateWithDefaultParams() { 313 int w = 1; 314 int h = 1; 315 316 FloatMap map = createFloatMap(w, h); 317 effect = new DisplacementMap(map); 318 setupTest(effect); 319 assertEquals(map, effect.getMapData()); 320 pulse(); 321 com.sun.scenario.effect.FloatMap mapImpl = 322 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 323 assertNotNull(mapImpl); 324 assertEquals(w, mapImpl.getWidth()); 325 assertEquals(h, mapImpl.getHeight()); 326 } 327 328 @Test 329 public void testCreateWithDefaultParams5() { 330 int w = 1; 331 int h = 1; 332 333 FloatMap map = createFloatMap(w, h); 334 effect = new DisplacementMap(map, 0, 0, 1, 1); 335 setupTest(effect); 336 assertEquals(0, effect.getOffsetX(), 1e-100); 337 assertEquals(0, effect.getOffsetY(), 1e-100); 338 assertEquals(1, effect.getScaleX(), 1e-100); 339 assertEquals(1, effect.getScaleY(), 1e-100); 340 assertEquals(map, effect.getMapData()); 341 pulse(); 342 assertEquals(0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetX(), 1e-100); 343 assertEquals(0f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getOffsetY(), 1e-100); 344 assertEquals(1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleX(), 1e-100); 345 assertEquals(1f, ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getScaleY(), 1e-100); 346 com.sun.scenario.effect.FloatMap mapImpl = 347 ((com.sun.scenario.effect.DisplacementMap) effect.impl_getImpl()).getMapData(); 348 assertNotNull(mapImpl); 349 assertEquals(w, mapImpl.getWidth()); 350 assertEquals(h, mapImpl.getHeight()); 351 } 352 }