changeset 50697:9822dd521c15

8196616: ava/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java fails Reviewed-by: prr, mhalder
author pbansal
date Tue, 15 May 2018 18:03:31 +0530
parents 23a8ccafa7ba
children d93ae85b18c1
files test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java
diffstat 1 files changed, 19 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java	Tue May 15 11:34:25 2018 +0530
+++ b/test/jdk/java/awt/GraphicsDevice/DisplayModes/CompareToXrandrTest.java	Tue May 15 18:03:31 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -24,7 +24,7 @@
 /**
  * @test
  * @key headful
- * @bug 8022810
+ * @bug 8022810 8196616
  * @summary Cannot list all the available display modes on Ubuntu linux in case
  *          of two screen devices
  * @run main CompareToXrandrTest
@@ -49,28 +49,27 @@
             return;
         }
 
-        BufferedReader reader = new BufferedReader(new InputStreamReader(
-                Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()));
-        reader.readLine();
-        reader.readLine();
-        Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(
+                Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) {
+            Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
 
-        for (GraphicsDevice d : GraphicsEnvironment
-                            .getLocalGraphicsEnvironment().getScreenDevices()) {
+            for (GraphicsDevice d : GraphicsEnvironment
+                    .getLocalGraphicsEnvironment().getScreenDevices()) {
 
-            Set<String> xrandrModes = reader.lines().map(pattern::matcher)
-                    .takeWhile(Matcher::find).map(m -> m.group(1))
-                            .collect(Collectors.toSet());
+                Set<String> xrandrModes = reader.lines().map(pattern::matcher)
+                        .filter(Matcher::find).map(m -> m.group(1))
+                        .collect(Collectors.toSet());
 
-            Set<String> javaModes = Arrays.stream(d.getDisplayModes())
-                    .map(m -> m.getWidth() + "x" + m.getHeight())
-                            .collect(Collectors.toSet());
+                Set<String> javaModes = Arrays.stream(d.getDisplayModes())
+                        .map(m -> m.getWidth() + "x" + m.getHeight())
+                        .collect(Collectors.toSet());
 
-            if (!xrandrModes.equals(javaModes)) {
-                throw new RuntimeException("Failed");
-            } else {
-                System.out.println("Device " + d + ": " + javaModes.size() +
-                                                               " modes found.");
+                if (!xrandrModes.equals(javaModes)) {
+                    throw new RuntimeException("Failed");
+                } else {
+                    System.out.println("Device " + d + ": " + javaModes.size() +
+                            " modes found.");
+                }
             }
         }
     }