Path: blob/master/test/jdk/java/awt/Choice/GetSizeTest/GetSizeTest.java
41152 views
/*1* Copyright (c) 1999, 2020, 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@key headful25@bug 425563126@summary Solaris: Size returned by Choice.getSize() does not match actual size27@author Andrei Dmitriev : area=Choice28run main GetSizeTest.html29*/3031import java.awt.Choice;32import java.awt.Frame;33import java.awt.Panel;34import java.awt.Point;35import java.awt.Robot;36import java.awt.event.InputEvent;37import java.awt.event.MouseAdapter;38import java.awt.event.MouseEvent;3940public class GetSizeTest {4142static String []s = {"Choice 1",43"Choice 2",44"unselected choices",45"what choices do I have?",46"Will I pick the same thing in the future?",47};48static volatile boolean passed = false;4950public static void main(String args[]) throws Exception {51Frame f = null;52try {53Robot robot = new Robot();54robot.setAutoDelay(150);5556f = new Frame("choice test");5758Panel p = new Panel();59p.setLayout(null);6061Choice c = new Choice();62for (int i = 0; i < s.length; i++)63c.addItem(s[i]);6465c.addMouseListener(new MouseAdapter() {66public void mouseReleased(MouseEvent e) {67System.err.println("Test passed");68passed = true;69}70});7172p.add(c);7374f.add(p);7576f.setSize(300, 300);77f.setLocationRelativeTo(null);78f.setVisible(true);7980c.setSize(200, 200);81f.validate();8283robot.waitForIdle();8485Point pt = c.getLocationOnScreen();86robot.mouseMove(pt.x + c.getWidth() - 10, pt.y + c.getHeight() / 2);87robot.waitForIdle();88robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);89robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);90robot.waitForIdle();91} finally {92if (f != null) {93f.dispose();94}95}96if (!passed) {97throw new RuntimeException( "Timeout. Choice component size is not actual size." );98}99System.err.println("Test passed.");100}101}102103104