Path: blob/master/test/jdk/java/awt/Graphics2D/ScaledCopyArea/ScaledCopyArea.java
41153 views
/*1* Copyright (c) 2014, 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.Color;24import java.awt.Graphics2D;25import java.awt.image.BufferedImage;2627/**28* @test29* @bug 802945530* @summary Tests that copyarea on offscreen images works as expected when31* scaled transform is set32* @run main ScaledCopyArea33*/34public final class ScaledCopyArea {3536public static void main(final String[] args) {37final BufferedImage bi = new BufferedImage(100, 300,38BufferedImage.TYPE_INT_RGB);39final Graphics2D g = bi.createGraphics();40g.scale(2, 2);41g.setColor(Color.RED);42g.fillRect(0, 0, 100, 300);43g.setColor(Color.GREEN);44g.fillRect(0, 100, 100, 100);45g.copyArea(0, 100, 100, 100, 0, -100);46g.dispose();47for (int x = 0; x < 100; ++x) {48for (int y = 0; y < 100; ++y) {49final int actual = bi.getRGB(x, y);50final int exp = Color.GREEN.getRGB();51if (actual != exp) {52System.err.println("Expected:" + Integer.toHexString(exp));53System.err.println("Actual:" + Integer.toHexString(actual));54throw new RuntimeException("Test " + "failed");55}56}57}58}59}606162