Path: blob/master/test/jdk/java/awt/Graphics/DrawOvalTest.java
66644 views
/*1* Copyright (c) 2021, 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*/2223/**24* @test25* @key headful26* @bug 826615927* @summary Test to detect regression in pixel drawing.28* A small circle is drawn and boundary pixels are compared to expected pixels.29* Note : this test is specifically written for uiScale=1.030* @run main/othervm -Dsun.java2d.uiScale=1.0 DrawOvalTest31*/3233import javax.imageio.ImageIO;34import java.awt.Color;35import java.awt.Graphics2D;36import java.awt.GraphicsConfiguration;37import java.awt.GraphicsEnvironment;38import java.awt.Transparency;39import java.awt.image.BufferedImage;40import java.awt.image.VolatileImage;41import java.io.File;42import java.io.IOException;4344public class DrawOvalTest {45public static void main(String[] args) throws IOException {46GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()47.getDefaultScreenDevice().getDefaultConfiguration();48VolatileImage vi = gc.createCompatibleVolatileImage(10, 10, Transparency.TRANSLUCENT);4950// Draw test rendering sequence51BufferedImage snapshot = null;52Graphics2D g2 = vi.createGraphics();5354do {55vi.validate(gc);56render(g2);57snapshot = vi.getSnapshot();58} while (vi.contentsLost());5960// Pixel color sequence expected after test rendering is complete61// Blue color = -1677696162// Red color = -6553663int sequence[] = {64-16776961,65-16776961,66-16776961,67-65536,68-65536,69-65536,70-65536,71-16776961,72-16776961,73-1677696174};7576// Test the color of pixels at the image boundary77for (int i = 0; i < snapshot.getWidth(); i++) {7879// Test first row, last row, first column and last column80if ( snapshot.getRGB(i, 0) != sequence[i] ||81snapshot.getRGB(i, 9) != sequence[i] ||82snapshot.getRGB(0, i) != sequence[i] ||83snapshot.getRGB(9, i) != sequence[i] ) {84ImageIO.write(snapshot, "png", new File("DrawOvalTest_snapshot.png"));85throw new RuntimeException("Test failed.");86}87}88}8990private static void render(Graphics2D g2) {91g2.setColor(Color.BLUE);92g2.fillRect(0, 0, 10, 10);93g2.setColor(Color.RED);94g2.drawOval(0, 0, 9, 9);95}96}979899