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.paint; 27 28 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.assertFalse; 30 import static org.junit.Assert.assertNotNull; 31 import static org.junit.Assert.assertSame; 32 import static org.junit.Assert.assertTrue; 33 import javafx.scene.image.Image; 34 import javafx.scene.paint.ImagePattern; 35 36 import org.junit.Test; 37 38 import test.com.sun.javafx.pgstub.StubImageLoaderFactory; 39 import test.com.sun.javafx.pgstub.StubPlatformImageInfo; 40 import test.com.sun.javafx.pgstub.StubToolkit; 41 import com.sun.javafx.tk.Toolkit; 42 import javafx.scene.paint.ImagePattern; 43 44 public class ImagePatternTest { 45 46 private Image createImage() { 47 final String url = "file:test.png"; 48 49 StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit(); 50 StubImageLoaderFactory imageLoaderFactory = 51 toolkit.getImageLoaderFactory(); 52 53 imageLoaderFactory.registerImage( 54 url, new StubPlatformImageInfo(100, 200)); 55 56 return new Image(url); 57 } 58 59 @Test 60 public void testImagePatternShort() { 61 Image image = createImage(); 62 ImagePattern pattern = new ImagePattern(image); 63 64 assertEquals(image, pattern.getImage()); 65 assertEquals(0f, pattern.getX(), 0.0001); 66 assertEquals(0f, pattern.getY(), 0.0001); 67 assertEquals(1f, pattern.getWidth(), 0.0001); 68 assertEquals(1f, pattern.getHeight(), 0.0001); 69 assertTrue(pattern.isProportional()); 70 } 71 72 @Test 73 public void testImagePatternLong() { 74 Image image = createImage(); 75 ImagePattern pattern = new ImagePattern(image, 1, 2, 3, 4, false); 76 77 assertEquals(image, pattern.getImage()); 78 assertEquals(1f, pattern.getX(), 0.0001); 79 assertEquals(2f, pattern.getY(), 0.0001); 80 assertEquals(3f, pattern.getWidth(), 0.0001); 81 assertEquals(4f, pattern.getHeight(), 0.0001); 82 assertFalse(pattern.isProportional()); 83 } 84 85 @Test 86 public void testImpl_getPlatformPaint() { 87 ImagePattern pattern = new ImagePattern(createImage()); 88 89 Object paint = Toolkit.getPaintAccessor().getPlatformPaint(pattern); 90 assertNotNull(paint); 91 assertSame(paint, Toolkit.getPaintAccessor().getPlatformPaint(pattern)); 92 } 93 94 95 }