Path: blob/master/test/jdk/java/awt/Frame/SetIconImagesCrashTest/SetIconImagesCrashTest.java
41154 views
/*1* Copyright (c) 2016, 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 816698027* @summary Test to check Window.setIconImages() does not result in crash when28* a frame is shown29* @run main/othervm SetIconImagesCrashTest30* @run main/othervm -Dsun.java2d.uiScale=2 SetIconImagesCrashTest31*/3233import java.awt.Color;34import java.awt.Graphics;35import java.awt.Window;36import java.awt.Frame;37import java.util.List;38import java.awt.image.BufferedImage;39import java.util.ArrayList;40import javax.swing.SwingUtilities;4142public class SetIconImagesCrashTest {4344public static void main(String[] args) throws Exception {4546List<BufferedImage> imageList = new ArrayList<BufferedImage>();47imageList.add(new BufferedImage(200, 200,48BufferedImage.TYPE_BYTE_BINARY));4950for (int i = 0; i < 10; i++) {51Frame f = new Frame();52test(f, imageList);53}54}5556public static void test(final Window window,57final List<BufferedImage> imageList) throws Exception {5859SwingUtilities.invokeAndWait(new Runnable() {60@Override61public void run() {62for (BufferedImage image : imageList) {63Graphics graphics = image.getGraphics();64graphics.setColor(Color.RED);65graphics.fillRect(660, 0, image.getWidth(), image.getHeight());67graphics.dispose();68}6970window.setIconImages(imageList);71window.setSize(200, 200);72window.setVisible(true);73}74});7576while (!window.isVisible()) {77Thread.sleep((long) (20));78}7980Thread.sleep((long) (50));8182SwingUtilities.invokeAndWait(new Runnable() {83@Override84public void run() {85window.setVisible(false);86window.dispose();87}88});89}90}91929394