Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Paint/ExposeOnEDT.java
47490 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324import java.awt.*;2526/**27* @test28* @bug 709042429* @author Sergey Bylokhov30* @library ../../../lib/testlibrary/31* @build ExtendedRobot32* @run main ExposeOnEDT33*/34public final class ExposeOnEDT {3536private static ExtendedRobot robot = null;37private static final Button buttonStub = new Button() {38@Override39public void paint(final Graphics g) {40buttonPainted = true;41if (!EventQueue.isDispatchThread()) {42throw new RuntimeException("Wrong thread");43}44}45};46private static final Canvas canvasStub = new Canvas() {47@Override48public void paint(final Graphics g) {49canvasPainted = true;50if (!EventQueue.isDispatchThread()) {51throw new RuntimeException("Wrong thread");52}53}54};55private static final Checkbox checkboxStub = new Checkbox() {56@Override57public void paint(final Graphics g) {58checkboxPainted = true;59if (!EventQueue.isDispatchThread()) {60throw new RuntimeException("Wrong thread");61}62}63};64private static final Choice choiceStub = new Choice() {65@Override66public void paint(final Graphics g) {67choicePainted = true;68if (!EventQueue.isDispatchThread()) {69throw new RuntimeException("Wrong thread");70}71}72};73private static final Component lwComponentStub = new Component() {74@Override75public void paint(final Graphics g) {76lwPainted = true;77if (!EventQueue.isDispatchThread()) {78throw new RuntimeException("Wrong thread");79}80}81};82private static final Container containerStub = new Container() {83@Override84public void paint(final Graphics g) {85containerPainted = true;86if (!EventQueue.isDispatchThread()) {87throw new RuntimeException("Wrong thread");88}89}90};91private static final Frame frame = new Frame() {92@Override93public void paint(final Graphics g) {94super.paint(g);95framePainted = true;96if (!EventQueue.isDispatchThread()) {97throw new RuntimeException("Wrong thread");98}99}100};101private static final Label labelStub = new Label() {102@Override103public void paint(final Graphics g) {104labelPainted = true;105if (!EventQueue.isDispatchThread()) {106throw new RuntimeException("Wrong thread");107}108}109};110private static final List listStub = new List() {111@Override112public void paint(final Graphics g) {113listPainted = true;114if (!EventQueue.isDispatchThread()) {115throw new RuntimeException("Wrong thread");116}117}118};119private static final Panel panelStub = new Panel() {120@Override121public void paint(final Graphics g) {122panelPainted = true;123if (!EventQueue.isDispatchThread()) {124throw new RuntimeException("Wrong thread");125}126}127};128private static final Scrollbar scrollbarStub = new Scrollbar() {129@Override130public void paint(final Graphics g) {131scrollbarPainted = true;132if (!EventQueue.isDispatchThread()) {133throw new RuntimeException("Wrong thread");134}135}136};137private static final ScrollPane scrollPaneStub = new ScrollPane() {138@Override139public void paint(final Graphics g) {140scrollPanePainted = true;141if (!EventQueue.isDispatchThread()) {142throw new RuntimeException("Wrong thread");143}144}145};146private static final TextArea textAreaStub = new TextArea() {147@Override148public void paint(final Graphics g) {149textAreaPainted = true;150if (!EventQueue.isDispatchThread()) {151throw new RuntimeException("Wrong thread");152}153}154};155private static final TextField textFieldStub = new TextField() {156@Override157public void paint(final Graphics g) {158textFieldPainted = true;159if (!EventQueue.isDispatchThread()) {160throw new RuntimeException("Wrong thread");161}162}163};164private static volatile boolean lwPainted;165private static volatile boolean buttonPainted;166private static volatile boolean canvasPainted;167private static volatile boolean checkboxPainted;168private static volatile boolean choicePainted;169private static volatile boolean containerPainted;170private static volatile boolean framePainted;171private static volatile boolean labelPainted;172private static volatile boolean listPainted;173private static volatile boolean panelPainted;174private static volatile boolean scrollbarPainted;175private static volatile boolean scrollPanePainted;176private static volatile boolean textAreaPainted;177private static volatile boolean textFieldPainted;178179public static void main(final String[] args) throws Exception {180//Frame initialisation181frame.setLayout(new GridLayout());182frame.setSize(new Dimension(200, 200));183frame.setLocationRelativeTo(null);184frame.setVisible(true);185sleep();186187frame.add(buttonStub);188frame.add(canvasStub);189frame.add(checkboxStub);190frame.add(choiceStub);191frame.add(lwComponentStub);192frame.add(containerStub);193frame.add(labelStub);194frame.add(listStub);195frame.add(panelStub);196frame.add(scrollbarStub);197frame.add(scrollPaneStub);198frame.add(textAreaStub);199frame.add(textFieldStub);200frame.validate();201sleep();202203// Force expose event from the native system.204initPaintedFlags();205frame.setSize(300, 300);206frame.validate();207sleep();208209//Check results.210validation();211212cleanup();213}214215private static void initPaintedFlags() {216lwPainted = false;217buttonPainted = false;218canvasPainted = false;219checkboxPainted = false;220choicePainted = false;221containerPainted = false;222framePainted = false;223labelPainted = false;224listPainted = false;225panelPainted = false;226scrollbarPainted = false;227scrollPanePainted = false;228textAreaPainted = false;229textFieldPainted = false;230}231232private static void validation() {233if (!buttonPainted) {234fail("Paint is not called a Button ");235}236if (!canvasPainted) {237fail("Paint is not called a Canvas ");238}239if (!checkboxPainted) {240fail("Paint is not called a Checkbox ");241}242if (!choicePainted) {243fail("Paint is not called a Choice ");244}245if (!lwPainted) {246fail("Paint is not called on a lightweight");247}248if (!containerPainted) {249fail("Paint is not called on a Container");250}251if (!labelPainted) {252fail("Paint is not called on a Label");253}254if (!listPainted) {255fail("Paint is not called on a List");256}257if (!panelPainted) {258fail("Paint is not called on a Panel");259}260if (!scrollbarPainted) {261fail("Paint is not called on a Scrollbar");262}263if (!scrollPanePainted) {264fail("Paint is not called on a ScrollPane");265}266if (!textAreaPainted) {267fail("Paint is not called on a TextArea");268}269if (!textFieldPainted) {270fail("Paint is not called on a TextField");271}272if (!framePainted) {273fail("Paint is not called on a Frame when paintAll()");274}275}276277private static void sleep() {278if(robot == null) {279try {280robot = new ExtendedRobot();281}catch(Exception ex) {282ex.printStackTrace();283throw new RuntimeException("Unexpected failure");284}285}286robot.waitForIdle(1000);287}288289private static void fail(final String message) {290cleanup();291throw new RuntimeException(message);292}293294private static void cleanup() {295frame.dispose();296}297}298299300