Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Graphics2D/Test8004859/Test8004859.java
38828 views
/*1* Copyright (c) 2013, 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*/37public final class Test8004859 {3839private static Shape[] clips = {new Rectangle(0, 0, -1, -1), new Rectangle(40100, 100, -100, -100)};4142private static boolean status = true;4344public static void main(final String[] args)45throws NoninvertibleTransformException {46final BufferedImage bi = new BufferedImage(300, 300,47BufferedImage.TYPE_INT_RGB);48final Graphics2D g = (Graphics2D) bi.getGraphics();49test(g);50g.translate(2.0, 2.0);51test(g);52g.translate(-4.0, -4.0);53test(g);54g.scale(2.0, 2.0);55test(g);56g.scale(-4.0, -4.0);57test(g);58g.rotate(Math.toRadians(90));59test(g);60g.rotate(Math.toRadians(90));61test(g);62g.rotate(Math.toRadians(90));63test(g);64g.rotate(Math.toRadians(90));65test(g);66g.dispose();67if (!status) {68throw new RuntimeException("Test failed");69}70}7172private static void test(final Graphics2D g) {73for (final Shape clip : clips) {74g.setClip(clip);75if (!g.getClip().equals(clip)) {76System.err.println("Expected clip: " + clip);77System.err.println("Actual clip: " + g.getClip());78System.err.println("bounds="+g.getClip().getBounds2D());79System.err.println("bounds="+g.getClip().getBounds());80status = false;81}82final Rectangle bounds = g.getClipBounds();83if (!clip.equals(bounds)) {84System.err.println("Expected getClipBounds(): " + clip);85System.err.println("Actual getClipBounds(): " + bounds);86status = false;87}88g.getClipBounds(bounds);89if (!clip.equals(bounds)) {90System.err.println("Expected getClipBounds(r): " + clip);91System.err.println("Actual getClipBounds(r): " + bounds);92status = false;93}94if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion95.isEmpty()) {96System.err.println("clipRegion should not be empty");97status = false;98}99}100}101}102103104