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.image; 27 28 import static com.sun.javafx.test.TestHelper.assertBoundsEqual; 29 import static com.sun.javafx.test.TestHelper.box; 30 import static javafx.scene.image.ImageViewConfig.config; 31 import static javafx.scene.image.TestImages.TEST_IMAGE_100x200; 32 import static javafx.scene.image.TestImages.TEST_IMAGE_200x100; 33 34 import java.util.Arrays; 35 import java.util.Collection; 36 37 import javafx.geometry.BoundingBox; 38 39 import org.junit.After; 40 import org.junit.Before; 41 import org.junit.Test; 42 import org.junit.runner.RunWith; 43 import org.junit.runners.Parameterized; 44 import org.junit.runners.Parameterized.Parameters; 45 46 @RunWith(Parameterized.class) 47 public final class ImageView_verifyBounds_Test { 48 49 private final ImageViewConfig imageViewConfig; 50 private final BoundingBox expectedBounds; 51 52 private ImageView imageView; 53 54 /* 55 * Parameters: [image view config], [expected bounds] 56 */ 57 @Parameters 58 public static Collection data() { 59 return Arrays.asList(new Object[][] { 60 { config(TEST_IMAGE_100x200, 0, 0), box(0, 0, 100, 200) }, 61 { config(TEST_IMAGE_200x100, 20, 10), box(20, 10, 200, 100) }, 62 { 63 config(null, 0, 0, 400, 400, false), 64 box(0, 0, 400, 400) 65 }, 66 { 67 config(TEST_IMAGE_100x200, 10, 20, 0, 400, false), 68 box(10, 20, 100, 400) 69 }, 70 { 71 config(TEST_IMAGE_200x100, 20, 10, 400, 0, false), 72 box(20, 10, 400, 100) 73 }, 74 { 75 config(null, 0, 0, 400, 400, true), 76 box(0, 0, 400, 400) 77 }, 78 { 79 config(TEST_IMAGE_100x200, 10, 20, 400, 400, true), 80 box(10, 20, 200, 400) 81 }, 82 { 83 config(TEST_IMAGE_200x100, 20, 10, 400, 400, true), 84 box(20, 10, 400, 200) 85 }, 86 { 87 config(TEST_IMAGE_100x200, 10, 20, 88 -50, 100, 200, 100, 89 400, 0, true), 90 box(10, 20, 400, 200) 91 }, 92 { 93 config(TEST_IMAGE_200x100, 20, 10, 94 100, -50, 100, 200, 95 0, 400, true), 96 box(20, 10, 200, 400) 97 }, 98 /* tests for invalid viewport */ 99 { 100 config(TEST_IMAGE_200x100, 0, 0, 101 0, 0, 0, 100, 102 400, 400, true), 103 box(0, 0, 400, 200) 104 }, 105 { 106 config(TEST_IMAGE_100x200, 0, 0, 107 0, 0, 100, 0, 108 400, 400, true), 109 box(0, 0, 200, 400) 110 } 111 }); 112 } 113 114 public ImageView_verifyBounds_Test(final ImageViewConfig imageViewConfig, 115 final BoundingBox expectedBounds) { 116 this.imageViewConfig = imageViewConfig; 117 this.expectedBounds = expectedBounds; 118 } 119 120 @Before 121 public void setUp() { 122 imageView = new ImageView(); 123 imageViewConfig.applyTo(imageView); 124 } 125 126 @After 127 public void tearDown() { 128 imageView = null; 129 } 130 131 @Test 132 public void verifyBounds() { 133 assertBoundsEqual(expectedBounds, imageView.getBoundsInLocal()); 134 } 135 }