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.image; 27 28 import static test.javafx.scene.image.ImageViewConfig.config; 29 import static test.javafx.scene.image.TestImages.TEST_IMAGE_100x200; 30 import static test.javafx.scene.image.TestImages.TEST_IMAGE_200x100; 31 import static org.junit.Assert.assertEquals; 32 33 import java.util.Arrays; 34 import java.util.Collection; 35 import javafx.scene.image.ImageView; 36 37 import org.junit.After; 38 import org.junit.Before; 39 import org.junit.Test; 40 import org.junit.runner.RunWith; 41 import org.junit.runners.Parameterized; 42 import org.junit.runners.Parameterized.Parameters; 43 44 @RunWith(Parameterized.class) 45 public class ImageView_verifyContains_Test { 46 47 private final ImageViewConfig imageViewConfig; 48 private final float x; 49 private final float y; 50 private final boolean expectedContainsResult; 51 52 private ImageView imageView; 53 54 /* 55 * Parameters: [image view config], [x], [y], [result] 56 * 57 * Note: 58 * Every test image has the following hit test pattern: 59 * 60 * TTT|FFF 61 * TTT|FFF 62 * ---+--- 63 * FFF|TTT 64 * FFF|TTT 65 */ 66 @Parameters 67 public static Collection data() { 68 return Arrays.asList(new Object[][] { 69 { config(null, 0, 0), 0, 0, false }, 70 { config(TEST_IMAGE_100x200, 0, 0), 25, 50, true }, 71 { config(TEST_IMAGE_100x200, 25, 50), 25 + 75, 50 + 50, false }, 72 { config(TEST_IMAGE_100x200, 25, 0), 25 + 25, 150, false }, 73 { config(TEST_IMAGE_100x200, 0, 50), 75, 50 + 150, true }, 74 { config(TEST_IMAGE_200x100, 0, 0), 250, 75, false }, 75 { config(TEST_IMAGE_200x100, 50, 25), 50 + 150, 25 + 125, false }, 76 { config(TEST_IMAGE_200x100, 50, 0), 0, 25, false }, 77 { config(TEST_IMAGE_200x100, 0, 25), 50, 0, false }, 78 { 79 config(null, 0, 0, 400, 400, false), 80 200, 200, false 81 }, 82 { 83 config(TEST_IMAGE_100x200, 50, 0, 0, 400, false), 84 50 + 25, 100, true 85 }, 86 { 87 config(TEST_IMAGE_200x100, 0, 50, 400, 0, false), 88 300, 50 + 75, true 89 }, 90 { 91 config(TEST_IMAGE_100x200, 0, 200, 400, 400, true), 92 150, 200 + 300, true 93 }, 94 { 95 config(TEST_IMAGE_200x100, 200, 0, 400, 400, true), 96 200 + 100, 50, true 97 }, 98 { 99 config(TEST_IMAGE_100x200, 0, 0, 100 50, 0, 100, 200, 101 0, 400, true), 102 50, 300, true 103 }, 104 { 105 config(TEST_IMAGE_100x200, 0, 0, 106 -50, 0, 100, 200, 107 400, 400, true), 108 50, 100, false 109 }, 110 { 111 config(TEST_IMAGE_100x200, 0, 0, 112 50, 50, 50, 150, 113 400, 400, false), 114 395, 395, true 115 }, 116 { 117 config(TEST_IMAGE_200x100, 20, 10, 118 0, 50, 200, 100, 119 400, 0, true), 120 300, 50, true 121 }, 122 { 123 config(TEST_IMAGE_200x100, 20, 10, 124 0, -50, 200, 100, 125 400, 0, true), 126 100, 50, false 127 }, 128 // /* tests for invalid viewport */ 129 // { 130 // config(TEST_IMAGE_200x100, 0, 0, 131 // 0, 0, 0, 100, 132 // 400, 400, true), 133 // 0, 0, false 134 // }, 135 // { 136 // config(TEST_IMAGE_100x200, 0, 0, 137 // 0, 0, 100, 0, 138 // 400, 400, true), 139 // 0, 0, false 140 // } 141 }); 142 } 143 144 public ImageView_verifyContains_Test(final ImageViewConfig imageViewConfig, 145 final float x, 146 final float y, 147 final boolean expectedContainsResult) { 148 this.imageViewConfig = imageViewConfig; 149 this.x = x; 150 this.y = y; 151 this.expectedContainsResult = expectedContainsResult; 152 } 153 154 @Before 155 public void setUp() { 156 imageView = new ImageView(); 157 imageViewConfig.applyTo(imageView); 158 } 159 160 @After 161 public void tearDown() { 162 imageView = null; 163 } 164 165 @Test 166 public void verifyContains() { 167 assertEquals(expectedContainsResult, 168 imageView.contains(x, y)); 169 } 170 }