/
githubmirror
/
panama-vector
Обзор
Документация
Войти
/
githubmirror
/
panama-vector
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/jdk/java/awt/FullScreen/SetFSWindow/FSFrame.java
175 строк
6 KB
Alexander Zvegintsev
8389589: [TEST_BUG] java/awt/FullScreen/SetFSWindow/FSFrame.java hides failure by swallowing exception
06 авг 2026, 07:41
06 авг 2026, 07:41
52cd87f
Код
Авторство
О чём код?
/* * Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test id=default * @key headful * @bug 6240507 6662642 * @summary verify that isFullScreenSupported work * correctly. Note that the test may fail on older Gnome versions (see bug 6500686). * @run main FSFrame */ /* * @test id=windows_d3d_false * @key headful * @bug 6240507 6662642 * @summary verify that isFullScreenSupported work * correctly. Note that the test may fail on older Gnome versions (see bug 6500686). * @requires (os.family == "windows") * @run main/othervm -Dsun.java2d.d3d=false FSFrame */ import java.awt.Color; import java.awt.EventQueue; import java.awt.Frame; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import javax.imageio.ImageIO; public class FSFrame extends Frame { static FSFrame frame; static Robot robot = null; public void paint(Graphics g) { g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); } @Override public void update(Graphics g) { paint(g); } boolean checkColor(int x, int y, BufferedImage bImg) { int pixelColor; int correctColor = Color.green.getRGB(); pixelColor = bImg.getRGB(x, y); if (pixelColor != correctColor) { System.out.println("FAILURE: pixelColor " + Integer.toHexString(pixelColor) + " != correctColor " + Integer.toHexString(correctColor) + " at coordinates (" + x + ", " + y + ")"); return false; } return true; } void checkFSDisplay(boolean fsSupported) { GraphicsConfiguration gc = getGraphicsConfiguration(); Rectangle r = gc.getBounds(); Insets in = null; if (!fsSupported) { in = Toolkit.getDefaultToolkit().getScreenInsets(gc); r = new Rectangle(in.left, in.top, r.width - (in.left + in.right), r.height - (in.top + in.bottom)); } BufferedImage bImg = robot.createScreenCapture(r); // Check that all four corners and middle pixel match the window's // fill color boolean colorCorrect = true; colorCorrect &= checkColor(0, 0, bImg); colorCorrect &= checkColor(0, bImg.getHeight() - 1, bImg); colorCorrect &= checkColor(bImg.getWidth() - 1, 0, bImg); colorCorrect &= checkColor(bImg.getWidth() - 1, bImg.getHeight() - 1, bImg); colorCorrect &= checkColor(bImg.getWidth() / 2, bImg.getHeight() / 2, bImg); if (!colorCorrect) { System.err.println("Test failed for mode: fsSupported="+fsSupported); if (in != null) { System.err.println("screen insets : " + in); } System.err.println("screen shot rect: " + r); String name = "FSFrame_fs_"+ (fsSupported?"supported":"not_supported")+".png"; try { ImageIO.write(bImg, "png", new File(name)); System.out.println("Dumped screen shot to " + name); } catch (IOException ignored) {} throw new RuntimeException("Some pixel colors not correct; FS window may not" + " have been displayed correctly"); } } void checkFSFunctionality() { GraphicsDevice gd = getGraphicsConfiguration().getDevice(); try { // None of these should throw an exception final boolean fs = gd.isFullScreenSupported(); System.out.println("FullscreenSupported: " + (fs ? "yes" : "no")); gd.setFullScreenWindow(this); // Give the system time to set the FS window and display it // properly robot.delay(2000); // See if FS window got displayed correctly try { EventQueue.invokeAndWait(this::repaint); } catch (InvocationTargetException | InterruptedException ex) { ex.printStackTrace(); } robot.waitForIdle(500); checkFSDisplay(fs); } finally { // reset window gd.setFullScreenWindow(null); // Give the system time to set the FS window and display it // properly robot.delay(2000); } } public static void main(String[] args) throws Exception { try { frame = new FSFrame(); frame.setUndecorated(true); frame.setSize(500, 500); frame.setVisible(true); robot = new Robot(frame.getGraphicsConfiguration().getDevice()); robot.waitForIdle(1000); frame.checkFSFunctionality(); System.out.println("PASS"); } finally { frame.dispose(); } } }