Path: blob/master/test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java
41154 views
/*1* Copyright (c) 2016, 2018, 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 8022810 819661627* @summary Cannot list all the available display modes on Ubuntu linux in case28* of two screen devices29* @run main CompareToXrandrTest30*/3132import java.awt.GraphicsEnvironment;33import java.awt.GraphicsDevice;34import java.io.BufferedReader;35import java.io.File;36import java.io.InputStreamReader;37import java.util.Arrays;38import java.util.Set;39import java.util.regex.Matcher;40import java.util.regex.Pattern;41import java.util.stream.Collectors;4243public class CompareToXrandrTest {4445public static void main(String[] args) throws Exception {46if (!new File("/usr/bin/xrandr").exists()) {47System.out.println("No xrandr tool to compare");48return;49}5051try (BufferedReader reader = new BufferedReader(new InputStreamReader(52Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) {53Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");5455for (GraphicsDevice d : GraphicsEnvironment56.getLocalGraphicsEnvironment().getScreenDevices()) {5758Set<String> xrandrModes = reader.lines().map(pattern::matcher)59.filter(Matcher::find).map(m -> m.group(1))60.collect(Collectors.toSet());6162Set<String> javaModes = Arrays.stream(d.getDisplayModes())63.map(m -> m.getWidth() + "x" + m.getHeight())64.collect(Collectors.toSet());6566if (!xrandrModes.equals(javaModes)) {67throw new RuntimeException("Failed");68} else {69System.out.println("Device " + d + ": " + javaModes.size() +70" modes found.");71}72}73}74}75}767778