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; 27 28 import java.util.Arrays; 29 import java.util.Collection; 30 31 import javafx.scene.image.Image; 32 import test.javafx.scene.image.TestImages; 33 34 import org.junit.AfterClass; 35 import org.junit.BeforeClass; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.junit.runners.Parameterized; 39 import org.junit.runners.Parameterized.Parameters; 40 41 import test.com.sun.javafx.pgstub.CursorSizeConverter; 42 import test.com.sun.javafx.pgstub.StubToolkit; 43 import com.sun.javafx.tk.Toolkit; 44 import javafx.scene.ImageCursor; 45 46 @RunWith(Parameterized.class) 47 public final class ImageCursor_findBestImage_Test { 48 private static final Image[] TEST_CURSOR_IMAGES = { 49 TestImages.TEST_IMAGE_32x32, 50 TestImages.TEST_IMAGE_64x64, 51 TestImages.TEST_IMAGE_32x64, 52 TestImages.TEST_IMAGE_64x32 53 }; 54 55 private static StubToolkit toolkit; 56 private static CursorSizeConverter oldCursorSizeConverter; 57 58 private final int bestWidth; 59 private final int bestHeight; 60 private final float hotspotX; 61 private final float hotspotY; 62 63 private final int expectedIndex; 64 private final float expectedHotspotX; 65 private final float expectedHotspotY; 66 67 68 /* 69 * Parameters: [bestWidth], [bestHeight], [hotspotX], [hotspotY], 70 * [expected index], 71 * [expected hotspotX], 72 * [expected hotspotY] 73 */ 74 @Parameters 75 public static Collection data() { 76 return Arrays.asList(new Object[][] { 77 { 32, 64, 0, 0, 2, 0, 0 }, 78 { 64, 32, 32, 32, 3, 63, 31 }, 79 { 48, 64, 16, 16, 2, 16, 32 }, 80 { 64, 48, 16, 16, 3, 32, 16 }, 81 { 92, 92, 16, 4, 1, 32, 8 }, 82 { 16, 16, 4, 16, 0, 4, 16 }, 83 { 16, 32, 0, 0, 0, 0, 0 }, 84 { 32, 16, 0, 0, 0, 0, 0 } 85 }); 86 } 87 88 @BeforeClass 89 public static void setUpClass() { 90 toolkit = (StubToolkit) Toolkit.getToolkit(); 91 oldCursorSizeConverter = toolkit.getCursorSizeConverter(); 92 } 93 94 @AfterClass 95 public static void tearDownClass() { 96 toolkit.setCursorSizeConverter(oldCursorSizeConverter); 97 } 98 99 public ImageCursor_findBestImage_Test(final int bestWidth, 100 final int bestHeight, 101 final float hotspotX, 102 final float hotspotY, 103 final int expectedIndex, 104 final float expectedHotspotX, 105 final float expectedHotspotY) { 106 this.bestWidth = bestWidth; 107 this.bestHeight = bestHeight; 108 this.hotspotX = hotspotX; 109 this.hotspotY = hotspotY; 110 111 this.expectedIndex = expectedIndex; 112 this.expectedHotspotX = expectedHotspotX; 113 this.expectedHotspotY = expectedHotspotY; 114 } 115 116 @Test 117 public void findBestImageTest() { 118 toolkit.setCursorSizeConverter( 119 CursorSizeConverter.createConstantConverter(bestWidth, 120 bestHeight)); 121 final ImageCursor selectedCursor = ImageCursor.chooseBestCursor( 122 TEST_CURSOR_IMAGES, 123 hotspotX, hotspotY); 124 ImageCursorTest.assertCursorEquals(selectedCursor, 125 TEST_CURSOR_IMAGES[expectedIndex], 126 expectedHotspotX, expectedHotspotY); 127 } 128 }