|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package com.oracle.svm.integrationtest; |
| 26 | + |
| 27 | +import java.awt.AWTError; |
| 28 | +import java.awt.Dimension; |
| 29 | +import java.awt.GraphicsEnvironment; |
| 30 | +import java.awt.HeadlessException; |
| 31 | +import java.awt.Toolkit; |
| 32 | +import java.awt.image.BufferedImage; |
| 33 | +import java.io.ByteArrayOutputStream; |
| 34 | + |
| 35 | +import javax.imageio.ImageIO; |
| 36 | + |
| 37 | +import org.junit.Assert; |
| 38 | +import org.junit.Assume; |
| 39 | +import org.junit.Test; |
| 40 | + |
| 41 | +public class NonHeadlessJavaDesktopTest { |
| 42 | + @Test |
| 43 | + public void nonHeadlessJavaDesktopSmokeTest() throws Exception { |
| 44 | + String osName = System.getProperty("os.name", ""); |
| 45 | + Assume.assumeTrue(osName.startsWith("Linux")); |
| 46 | + |
| 47 | + String display = System.getenv("DISPLAY"); |
| 48 | + Assume.assumeTrue(display != null && !display.isEmpty()); |
| 49 | + |
| 50 | + System.clearProperty("java.awt.headless"); |
| 51 | + Toolkit toolkit; |
| 52 | + Dimension screenSize; |
| 53 | + try { |
| 54 | + Assume.assumeFalse(GraphicsEnvironment.isHeadless()); |
| 55 | + toolkit = Toolkit.getDefaultToolkit(); |
| 56 | + screenSize = toolkit.getScreenSize(); |
| 57 | + } catch (AWTError | HeadlessException e) { |
| 58 | + Assume.assumeNoException(e); |
| 59 | + return; |
| 60 | + } |
| 61 | + Assert.assertTrue("Invalid screen width: " + screenSize.width, screenSize.width > 0); |
| 62 | + Assert.assertTrue("Invalid screen height: " + screenSize.height, screenSize.height > 0); |
| 63 | + |
| 64 | + BufferedImage image = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB); |
| 65 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 66 | + Assert.assertTrue("No PNG writer available", ImageIO.write(image, "png", output)); |
| 67 | + |
| 68 | + byte[] bytes = output.toByteArray(); |
| 69 | + Assert.assertTrue("PNG output is empty", bytes.length > 8); |
| 70 | + Assert.assertEquals((byte) 0x89, bytes[0]); |
| 71 | + Assert.assertEquals((byte) 'P', bytes[1]); |
| 72 | + Assert.assertEquals((byte) 'N', bytes[2]); |
| 73 | + Assert.assertEquals((byte) 'G', bytes[3]); |
| 74 | + } |
| 75 | +} |
0 commit comments