Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/GetSizeTest/GetSizeTest.java
47525 views
/*1* Copyright (c) 1999, 2014, 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*/22/*23@test24@bug 425563125@summary Solaris: Size returned by Choice.getSize() does not match actual size26@author Andrei Dmitriev : area=Choice27run main GetSizeTest.html28*/2930import java.awt.*;31import java.awt.event.*;3233public class GetSizeTest {3435static String []s = {"Choice 1",36"Choice 2",37"unselected choices",38"what choices do I have?",39"Will I pick the same thing in the future?",40};41static boolean passed = false;42static Robot robot = null;4344public static void main(String args[])45{46try {47robot = new Robot();48robot.setAutoDelay(50);4950Frame f = new Frame("choice test");5152Panel p = new Panel();53p.setLayout(null);5455Choice c = new Choice();56for (int i = 0; i < s.length; i++)57c.addItem(s[i]);5859c.addMouseListener(new MouseAdapter() {60public void mouseReleased(MouseEvent e) {61System.err.println("Test passed");62passed = true;63}64});6566p.add(c);6768f.add(p);6970f.setSize(300, 300);7172f.addWindowListener(new WindowAdapter() {73public void windowClosing(WindowEvent we) {74System.err.println("Test passed");75passed = true;76}77});7879f.setVisible(true);8081c.setSize(200, 200);82f.validate();8384robot.waitForIdle();8586Point pt = c.getLocationOnScreen();87robot.mouseMove(pt.x + c.getWidth() - 10, pt.y + c.getHeight() / 2);88robot.waitForIdle();89robot.mousePress(InputEvent.BUTTON2_MASK);90robot.mouseRelease(InputEvent.BUTTON2_MASK);91robot.waitForIdle();92} catch (Throwable e) {93if (robot == null){94throw new RuntimeException( "Test failed.Unable to initialize Robot "+e);95}96throw new RuntimeException( "Test failed due to thrown exception "+e);97}98if (!passed) {99throw new RuntimeException( "Timeout. Choice component size is not actual size." );100}101System.err.println("Test passed.");102}103}104105106