1 /*
   2  * Copyright (c) 2020, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.Frame;
  25 import java.awt.Robot;
  26 import java.awt.*;
  27 import java.awt.event.InputEvent;
  28 import java.awt.event.KeyEvent;
  29 import java.util.concurrent.TimeUnit;
  30 
  31 import jdk.test.lib.process.OutputAnalyzer;
  32 import jdk.test.lib.process.ProcessTools;
  33 
  34 /**
  35  * @test
  36  * @bug 8226806
  37  * @key headful
  38  * @library /test/lib
  39  * @summary checks for unexpected output in stderr and stdout
  40  */
  41 public final class NonEmptyErrorStream {
  42 
  43     public static void main(String[] args) throws Exception {
  44         if (args.length == 0) {
  45             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  46                     NonEmptyErrorStream.class.getSimpleName(),"run");
  47             Process p = pb.start();
  48             OutputAnalyzer output = new OutputAnalyzer(p);
  49             p.waitFor(20, TimeUnit.SECONDS);
  50             p.destroy();
  51             output.shouldHaveExitValue(0);
  52             output.stdoutShouldBeEmpty();
  53             output.stderrShouldBeEmpty();
  54             return;
  55         }
  56         Frame frame = new Frame();
  57         frame.setSize(400, 300);
  58         frame.setLocationRelativeTo(null);
  59         frame.setVisible(true);
  60 
  61         Robot robot = new Robot();
  62         robot.setAutoDelay(50);
  63         robot.waitForIdle();
  64         frame.toFront();
  65 
  66         Rectangle rect = frame.getBounds();
  67         int x = (int) rect.getCenterX();
  68         int y = (int) rect.getCenterY();
  69 
  70         for (int i = 0; i < 20; i++) {
  71             robot.getPixelColor(x, y);
  72             robot.createScreenCapture(rect);
  73         }
  74         for (int i = 0; i < 20; i++) {
  75             robot.mouseMove(x + 50, y + 50);
  76             robot.mouseMove(x - 50, y - 50);
  77         }
  78         for (int i = 0; i < 20; i++) {
  79             robot.keyPress(KeyEvent.VK_ESCAPE);
  80             robot.keyRelease(KeyEvent.VK_ESCAPE);
  81         }
  82         for (int i = 0; i < 20; i++) {
  83             robot.mousePress(InputEvent.BUTTON1_MASK);
  84             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  85         }
  86         robot.waitForIdle();
  87         frame.dispose();
  88     }
  89 }