--- old/test/jdk/java/awt/Graphics/LCDTextAndGraphicsState.java 2018-05-21 18:25:36.000000000 +0530 +++ new/test/jdk/java/awt/Graphics/LCDTextAndGraphicsState.java 2018-05-21 18:25:36.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -23,17 +23,86 @@ /** * @test - * @bug 6576507 + * @bug 6576507 8202841 * @summary Both lines of text should be readable - * @run main/manual=yesno LCDTextAndGraphicsState + * @run main/manual LCDTextAndGraphicsState */ -import java.awt.*; -import java.awt.geom.*; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Color; +import java.awt.RenderingHints; +import java.awt.AlphaComposite; +import java.awt.GradientPaint; +import java.awt.Shape; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.TextArea; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.RoundRectangle2D; public class LCDTextAndGraphicsState extends Component { String text = "This test passes only if this text appears SIX TIMES"; + private static Button passButton; + private static Button failButton; + private static TextArea instructions; + private static Frame frame; + private static Frame instructionFrame; + private static Thread mainThread = null; + private static int sleepTime = 300000; + private static int sleepLoopTime = 1000; + private static volatile boolean continueTest = true; + + public void createAndShowInstructionFrame() { + passButton = new Button("Pass"); + passButton.setEnabled(true); + + failButton = new Button("Fail"); + failButton.setEnabled(true); + + instructions = new TextArea(5, 60); + instructions.setText(" This is a manual test\n\n" + + " 1) Press PASS if both lines of text are readable and appear 6 times\n" + + " 2) Press FAIL otherwise"); + + instructionFrame = new Frame("Test Instructions"); + instructionFrame.add(passButton); + instructionFrame.add(failButton); + instructionFrame.add(instructions); + instructionFrame.setSize(200,200); + instructionFrame.setLayout(new FlowLayout()); + instructionFrame.pack(); + instructionFrame.setVisible(true); + + passButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + dispose(); + continueTest = false; + } + }); + + failButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + dispose(); + continueTest = false; + throw new RuntimeException("Both lines of text are not readable or do not appear SIX TIMES !!!"); + } + }); + } + + private static void dispose() { + frame.dispose(); + instructionFrame.dispose(); + } + public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g.create(); @@ -82,11 +151,32 @@ return new Dimension(500,600); } + public void createAndShowFrame() { + frame = new Frame("Composite and Text Test"); + frame.add(new LCDTextAndGraphicsState(), BorderLayout.CENTER); + frame.setLocationRelativeTo(instructionFrame); + frame.pack(); + frame.setVisible(true); + } + public static void main(String[] args) throws Exception { - Frame f = new Frame("Composite and Text Test"); - f.add(new LCDTextAndGraphicsState(), BorderLayout.CENTER); - f.pack(); - f.setVisible(true); + mainThread = Thread.currentThread(); + LCDTextAndGraphicsState lcdTest = new LCDTextAndGraphicsState(); + lcdTest.createAndShowInstructionFrame(); + lcdTest.createAndShowFrame(); + + int remainingSleepTime = sleepTime; + while(remainingSleepTime > 0 && continueTest) { + mainThread.sleep(sleepLoopTime); + remainingSleepTime -= sleepLoopTime; + } + + if (continueTest) { + lcdTest.dispose(); + throw new RuntimeException("Timed out after " + (sleepTime - remainingSleepTime) / 1000 + + " seconds"); + } } } +