test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java
changeset 50148 9822dd521c15
parent 47216 71c04702a3d5
equal deleted inserted replaced
50147:23a8ccafa7ba 50148:9822dd521c15
     1 /*
     1 /*
     2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @key headful
    26  * @key headful
    27  * @bug 8022810
    27  * @bug 8022810 8196616
    28  * @summary Cannot list all the available display modes on Ubuntu linux in case
    28  * @summary Cannot list all the available display modes on Ubuntu linux in case
    29  *          of two screen devices
    29  *          of two screen devices
    30  * @run main CompareToXrandrTest
    30  * @run main CompareToXrandrTest
    31  */
    31  */
    32 
    32 
    47         if (!new File("/usr/bin/xrandr").exists()) {
    47         if (!new File("/usr/bin/xrandr").exists()) {
    48             System.out.println("No xrandr tool to compare");
    48             System.out.println("No xrandr tool to compare");
    49             return;
    49             return;
    50         }
    50         }
    51 
    51 
    52         BufferedReader reader = new BufferedReader(new InputStreamReader(
    52         try (BufferedReader reader = new BufferedReader(new InputStreamReader(
    53                 Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()));
    53                 Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) {
    54         reader.readLine();
    54             Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
    55         reader.readLine();
       
    56         Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
       
    57 
    55 
    58         for (GraphicsDevice d : GraphicsEnvironment
    56             for (GraphicsDevice d : GraphicsEnvironment
    59                             .getLocalGraphicsEnvironment().getScreenDevices()) {
    57                     .getLocalGraphicsEnvironment().getScreenDevices()) {
    60 
    58 
    61             Set<String> xrandrModes = reader.lines().map(pattern::matcher)
    59                 Set<String> xrandrModes = reader.lines().map(pattern::matcher)
    62                     .takeWhile(Matcher::find).map(m -> m.group(1))
    60                         .filter(Matcher::find).map(m -> m.group(1))
    63                             .collect(Collectors.toSet());
    61                         .collect(Collectors.toSet());
    64 
    62 
    65             Set<String> javaModes = Arrays.stream(d.getDisplayModes())
    63                 Set<String> javaModes = Arrays.stream(d.getDisplayModes())
    66                     .map(m -> m.getWidth() + "x" + m.getHeight())
    64                         .map(m -> m.getWidth() + "x" + m.getHeight())
    67                             .collect(Collectors.toSet());
    65                         .collect(Collectors.toSet());
    68 
    66 
    69             if (!xrandrModes.equals(javaModes)) {
    67                 if (!xrandrModes.equals(javaModes)) {
    70                 throw new RuntimeException("Failed");
    68                     throw new RuntimeException("Failed");
    71             } else {
    69                 } else {
    72                 System.out.println("Device " + d + ": " + javaModes.size() +
    70                     System.out.println("Device " + d + ": " + javaModes.size() +
    73                                                                " modes found.");
    71                             " modes found.");
       
    72                 }
    74             }
    73             }
    75         }
    74         }
    76     }
    75     }
    77 }
    76 }