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 import static org.junit.Assert.assertNull; 30 import javafx.beans.property.ObjectProperty; 31 import javafx.beans.property.SimpleObjectProperty; 32 import javafx.scene.image.Image; 33 import javafx.scene.image.TestImages; 34 35 import org.junit.Before; 36 import org.junit.Test; 37 38 import com.sun.javafx.geom.Point2D; 39 import com.sun.javafx.tk.Toolkit; 40 41 public class ImageInputTest extends EffectsTestBase { 42 private ImageInput effect; 43 44 @Before 45 public void setUp() { 46 effect = new ImageInput(); 47 setupTest(effect); 48 } 49 50 @Test 51 public void testSetX() { 52 // try setting correct value 53 effect.setX(1.0f); 54 assertEquals(1.0f, effect.getX(), 1e-100); 55 pulse(); 56 assertEquals(1.0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().x, 1e-100); 57 } 58 59 @Test 60 public void testDefaultX() { 61 // default value should be 0 62 assertEquals(0, effect.getX(), 1e-100); 63 assertEquals(0, effect.xProperty().get(), 1e-100); 64 pulse(); 65 assertEquals(0, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().x, 1e-100); 66 } 67 68 @Test 69 public void testSetY() { 70 // try setting correct value 71 effect.setY(1.0f); 72 assertEquals(1.0f, effect.getY(), 1e-100); 73 pulse(); 74 assertEquals(1.0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().y, 1e-100); 75 } 76 77 @Test 78 public void testDefaultY() { 79 // default value should be 0 80 assertEquals(0, effect.getY(), 1e-100); 81 assertEquals(0, effect.yProperty().get(), 1e-100); 82 pulse(); 83 assertEquals(0, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().y, 1e-100); 84 } 85 86 @Test 87 public void testSetSource() { 88 // try setting non-existing image 89 Image i = new Image("javafx/scene/image/test.png"); 90 effect.setSource(i); 91 assertEquals(i, effect.getSource()); 92 pulse(); 93 assertEquals(null, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource()); 94 // try setting correct one 95 effect.setSource(TestImages.TEST_IMAGE_32x32); 96 pulse(); 97 assertEquals(TestImages.TEST_IMAGE_32x32, effect.getSource()); 98 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalHeight(), 99 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalHeight()); 100 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalWidth(), 101 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalWidth()); 102 } 103 104 @Test 105 public void testDefaultSource() { 106 // default value should be null 107 assertNull(effect.getSource()); 108 assertNull(effect.sourceProperty().get()); 109 pulse(); 110 assertNull(((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource()); 111 } 112 113 @Test 114 public void testXSynced() throws Exception { 115 Point2D pt = (Point2D) getDoublePropertySynced( 116 "javafx.scene.effect.ImageInput", "x", 117 "com.sun.scenario.effect.Identity", "location", 10); 118 assertEquals(10, pt.x, 1e-100); 119 } 120 121 @Test 122 public void testYSynced() throws Exception { 123 Point2D pt = (Point2D) getDoublePropertySynced( 124 "javafx.scene.effect.ImageInput", "y", 125 "com.sun.scenario.effect.Identity", "location", 10); 126 assertEquals(10, pt.y, 1e-100); 127 } 128 129 @Test 130 public void testSourceSynced() throws Exception { 131 ObjectProperty source = new SimpleObjectProperty(); 132 effect.sourceProperty().bind(source); 133 source.set(TestImages.TEST_IMAGE_32x32); 134 pulse(); 135 assertEquals(TestImages.TEST_IMAGE_32x32, effect.getSource()); 136 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalHeight(), 137 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalHeight()); 138 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalWidth(), 139 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalWidth()); 140 } 141 142 @Test 143 public void testCreateWithParams() { 144 effect = new ImageInput(TestImages.TEST_IMAGE_32x32); 145 setupTest(effect); 146 assertEquals(TestImages.TEST_IMAGE_32x32, effect.getSource()); 147 pulse(); 148 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalHeight(), 149 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalHeight()); 150 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalWidth(), 151 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalWidth()); 152 } 153 154 @Test 155 public void testCreateWithParams3() { 156 effect = new ImageInput(TestImages.TEST_IMAGE_32x32, 1, 2); 157 setupTest(effect); 158 assertEquals(TestImages.TEST_IMAGE_32x32, effect.getSource()); 159 assertEquals(1, effect.getX(), 1e-100); 160 assertEquals(2, effect.getY(), 1e-100); 161 pulse(); 162 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalHeight(), 163 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalHeight()); 164 assertEquals(Toolkit.getToolkit().toFilterable(TestImages.TEST_IMAGE_32x32).getPhysicalWidth(), 165 ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource().getPhysicalWidth()); 166 assertEquals(1.0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().x, 1e-100); 167 assertEquals(2.0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().y, 1e-100); 168 } 169 170 @Test 171 public void testCreateWithDefaultParams() { 172 effect = new ImageInput(null); 173 setupTest(effect); 174 assertNull(effect.getSource()); 175 pulse(); 176 assertNull(((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource()); 177 } 178 179 @Test 180 public void testCreateWithDefaultParams3() { 181 effect = new ImageInput(null, 0, 0); 182 setupTest(effect); 183 assertNull(effect.getSource()); 184 assertEquals(0, effect.getX(), 1e-100); 185 assertEquals(0, effect.getY(), 1e-100); 186 pulse(); 187 assertNull(((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getSource()); 188 assertEquals(0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().x, 1e-100); 189 assertEquals(0f, ((com.sun.scenario.effect.Identity) effect.impl_getImpl()).getLocation().y, 1e-100); 190 } 191 }