test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java
author pbansal
Tue, 15 May 2018 18:03:31 +0530
changeset 50148 9822dd521c15
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails Reviewed-by: prr, mhalder
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     1
/*
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     4
 *
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     7
 * published by the Free Software Foundation.
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     8
 *
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    13
 * accompanied this code).
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    14
 *
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    18
 *
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    21
 * questions.
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    22
 */
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    23
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    24
/**
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    25
 * @test
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 39556
diff changeset
    26
 * @key headful
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    27
 * @bug 8022810 8196616
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    28
 * @summary Cannot list all the available display modes on Ubuntu linux in case
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    29
 *          of two screen devices
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    30
 * @run main CompareToXrandrTest
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    31
 */
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    32
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    33
import java.awt.GraphicsEnvironment;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    34
import java.awt.GraphicsDevice;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    35
import java.io.BufferedReader;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    36
import java.io.File;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    37
import java.io.InputStreamReader;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    38
import java.util.Arrays;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    39
import java.util.Set;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    40
import java.util.regex.Matcher;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    41
import java.util.regex.Pattern;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    42
import java.util.stream.Collectors;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    43
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    44
public class CompareToXrandrTest {
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    45
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    47
        if (!new File("/usr/bin/xrandr").exists()) {
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    48
            System.out.println("No xrandr tool to compare");
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    49
            return;
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    50
        }
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    51
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    52
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    53
                Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) {
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    54
            Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    55
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    56
            for (GraphicsDevice d : GraphicsEnvironment
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    57
                    .getLocalGraphicsEnvironment().getScreenDevices()) {
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    58
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    59
                Set<String> xrandrModes = reader.lines().map(pattern::matcher)
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    60
                        .filter(Matcher::find).map(m -> m.group(1))
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    61
                        .collect(Collectors.toSet());
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    62
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    63
                Set<String> javaModes = Arrays.stream(d.getDisplayModes())
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    64
                        .map(m -> m.getWidth() + "x" + m.getHeight())
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    65
                        .collect(Collectors.toSet());
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    66
50148
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    67
                if (!xrandrModes.equals(javaModes)) {
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    68
                    throw new RuntimeException("Failed");
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    69
                } else {
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    70
                    System.out.println("Device " + d + ": " + javaModes.size() +
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    71
                            " modes found.");
9822dd521c15 8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails
pbansal
parents: 47216
diff changeset
    72
                }
39556
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    73
            }
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    74
        }
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    75
    }
50963eeaefca 8022810: Cannot list all the available display modes on Ubuntu linux in case of two screen devices
ssadetsky
parents:
diff changeset
    76
}