Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/PaintAll/PaintAll.java
47311 views
/*1* Copyright (c) 2011, 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*/2223import java.awt.Button;24import java.awt.Canvas;25import java.awt.Checkbox;26import java.awt.Choice;27import java.awt.Component;28import java.awt.Container;29import java.awt.Dimension;30import java.awt.Frame;31import java.awt.Graphics;32import java.awt.GridLayout;33import java.awt.Label;34import java.awt.List;35import java.awt.Panel;36import java.awt.ScrollPane;37import java.awt.Scrollbar;38import java.awt.TextArea;39import java.awt.TextField;40import java.awt.Toolkit;41import java.awt.image.BufferedImage;4243/*44@test45@bug 659691546@summary Test Component.paintAll() method47@author [email protected]: area=awt.component48@library ../../../../lib/testlibrary/49@build ExtendedRobot50@run main PaintAll51*/52public class PaintAll {5354private static volatile boolean lwPainted;55private static volatile boolean buttonPainted;56private static volatile boolean canvasPainted;57private static volatile boolean checkboxPainted;58private static volatile boolean choicePainted;59private static volatile boolean containerPainted;60private static volatile boolean framePainted;61private static volatile boolean labelPainted;62private static volatile boolean listPainted;63private static volatile boolean panelPainted;64private static volatile boolean scrollbarPainted;65private static volatile boolean scrollPanePainted;66private static volatile boolean textAreaPainted;67private static volatile boolean textFieldPainted;68private static ExtendedRobot robot = null;6970private static final Button buttonStub = new Button() {71@Override72public void paint(final Graphics g) {73buttonPainted = true;74}75};7677private static final Canvas canvasStub = new Canvas() {78@Override79public void paint(final Graphics g) {80canvasPainted = true;81}82};8384private static final Checkbox checkboxStub = new Checkbox() {85@Override86public void paint(final Graphics g) {87checkboxPainted = true;88}89};9091private static final Choice choiceStub = new Choice() {92@Override93public void paint(final Graphics g) {94choicePainted = true;95}96};9798private static final Component lwComponentStub = new Component() {99@Override100public void paint(final Graphics g) {101lwPainted = true;102}103};104105private static final Container containerStub = new Container() {106@Override107public void paint(final Graphics g) {108containerPainted = true;109}110};111112private static final Frame frame = new Frame() {113@Override114public void paint(final Graphics g) {115super.paint(g);116framePainted = true;117}118};119120private static final Label labelStub = new Label() {121@Override122public void paint(final Graphics g) {123labelPainted = true;124}125};126127private static final List listStub = new List() {128@Override129public void paint(final Graphics g) {130listPainted = true;131}132};133134private static final Panel panelStub = new Panel() {135@Override136public void paint(final Graphics g) {137panelPainted = true;138}139};140141private static final Scrollbar scrollbarStub = new Scrollbar() {142@Override143public void paint(final Graphics g) {144scrollbarPainted = true;145}146};147148private static final ScrollPane scrollPaneStub = new ScrollPane() {149@Override150public void paint(final Graphics g) {151scrollPanePainted = true;152}153};154155private static final TextArea textAreaStub = new TextArea() {156@Override157public void paint(final Graphics g) {158textAreaPainted = true;159}160};161162private static final TextField textFieldStub = new TextField() {163@Override164public void paint(final Graphics g) {165textFieldPainted = true;166}167};168169public static void main(final String[] args) throws Exception {170//Frame initialisation171final BufferedImage graphicsProducer =172new BufferedImage(BufferedImage.TYPE_INT_ARGB, 1, 1);173174final Graphics g = graphicsProducer.getGraphics();175176frame.setLayout(new GridLayout());177frame.add(buttonStub);178frame.add(canvasStub);179frame.add(checkboxStub);180frame.add(choiceStub);181frame.add(lwComponentStub);182frame.add(containerStub);183frame.add(labelStub);184frame.add(listStub);185frame.add(panelStub);186frame.add(scrollbarStub);187frame.add(scrollPaneStub);188frame.add(textAreaStub);189frame.add(textFieldStub);190frame.setSize(new Dimension(500, 500));191frame.setLocationRelativeTo(null);192frame.setVisible(true);193sleep();194195//Check results.196validation();197198//Reset all flags to 'false'.199initPaintedFlags();200201//Tested method.202frame.paintAll(g);203sleep();204205//Check results.206validation();207cleanup();208}209210private static void initPaintedFlags() {211lwPainted = false;212buttonPainted = false;213canvasPainted = false;214checkboxPainted = false;215choicePainted = false;216containerPainted = false;217framePainted = false;218labelPainted = false;219listPainted = false;220panelPainted = false;221scrollbarPainted = false;222scrollPanePainted = false;223textAreaPainted = false;224textFieldPainted = false;225}226227private static void validation() {228if (!buttonPainted) {229fail("Paint is not called a Button "230+ "when paintAll() invoked on a parent");231}232if (!canvasPainted) {233fail("Paint is not called a Canvas "234+ "when paintAll() invoked on a parent");235}236if (!checkboxPainted) {237fail("Paint is not called a Checkbox "238+ "when paintAll() invoked on a parent");239}240if (!choicePainted) {241fail("Paint is not called a Choice "242+ "when paintAll() invoked on a parent");243}244if (!lwPainted) {245fail("Paint is not called on a lightweight"246+ " subcomponent when paintAll() invoked on a parent");247}248if (!containerPainted) {249fail("Paint is not called on a Container"250+ " subcomponent when paintAll() invoked on a parent");251}252if (!labelPainted) {253fail("Paint is not called on a Label"254+ " subcomponent when paintAll() invoked on a parent");255}256if (!listPainted) {257fail("Paint is not called on a List"258+ " subcomponent when paintAll() invoked on a parent");259}260if (!panelPainted) {261fail("Paint is not called on a Panel"262+ " subcomponent when paintAll() invoked on a parent");263}264if (!scrollbarPainted) {265fail("Paint is not called on a Scrollbar"266+ " subcomponent when paintAll() invoked on a parent");267}268if (!scrollPanePainted) {269fail("Paint is not called on a ScrollPane"270+ " subcomponent when paintAll() invoked on a parent");271}272if (!textAreaPainted) {273fail("Paint is not called on a TextArea"274+ " subcomponent when paintAll() invoked on a parent");275}276if (!textFieldPainted) {277fail("Paint is not called on a TextField"278+ " subcomponent when paintAll() invoked on a parent");279}280if (!framePainted) {281fail("Paint is not called on a Frame when paintAll()");282}283}284285private static void sleep() {286if(robot == null) {287try {288robot = new ExtendedRobot();289}catch(Exception ex) {290ex.printStackTrace();291throw new RuntimeException("Unexpected failure");292}293}294robot.waitForIdle(500);295}296297private static void fail(final String message) {298cleanup();299throw new RuntimeException(message);300}301302private static void cleanup() {303frame.dispose();304}305}306307308