Path: blob/master/test/jdk/java/awt/Graphics2D/Test8004859/Test8004859.java
41154 views
/*1* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Graphics2D;24import java.awt.Rectangle;25import java.awt.Shape;26import java.awt.geom.NoninvertibleTransformException;27import java.awt.image.BufferedImage;2829import sun.java2d.SunGraphics2D;3031/**32* @test33* @bug 800485934* @summary getClipBounds/getClip should return equivalent bounds.35* @author Sergey Bylokhov36* @modules java.desktop/sun.java2d37* java.desktop/sun.java2d.pipe38*/39public final class Test8004859 {4041private static Shape[] clips = {new Rectangle(0, 0, -1, -1), new Rectangle(42100, 100, -100, -100)};4344private static boolean status = true;4546public static void main(final String[] args)47throws NoninvertibleTransformException {48final BufferedImage bi = new BufferedImage(300, 300,49BufferedImage.TYPE_INT_RGB);50final Graphics2D g = (Graphics2D) bi.getGraphics();51test(g);52g.translate(2.0, 2.0);53test(g);54g.translate(-4.0, -4.0);55test(g);56g.scale(2.0, 2.0);57test(g);58g.scale(-4.0, -4.0);59test(g);60g.rotate(Math.toRadians(90));61test(g);62g.rotate(Math.toRadians(90));63test(g);64g.rotate(Math.toRadians(90));65test(g);66g.rotate(Math.toRadians(90));67test(g);68g.dispose();69if (!status) {70throw new RuntimeException("Test failed");71}72}7374private static void test(final Graphics2D g) {75for (final Shape clip : clips) {76g.setClip(clip);77if (!g.getClip().equals(clip)) {78System.err.println("Expected clip: " + clip);79System.err.println("Actual clip: " + g.getClip());80System.err.println("bounds="+g.getClip().getBounds2D());81System.err.println("bounds="+g.getClip().getBounds());82status = false;83}84final Rectangle bounds = g.getClipBounds();85if (!clip.equals(bounds)) {86System.err.println("Expected getClipBounds(): " + clip);87System.err.println("Actual getClipBounds(): " + bounds);88status = false;89}90g.getClipBounds(bounds);91if (!clip.equals(bounds)) {92System.err.println("Expected getClipBounds(r): " + clip);93System.err.println("Actual getClipBounds(r): " + bounds);94status = false;95}96if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion97.isEmpty()) {98System.err.println("clipRegion should not be empty");99status = false;100}101}102}103}104105106