1 /*
   2   test
   3   @bug 4255631
   4   @summary Solaris: Size returned by Choice.getSize() does not match actual size
   5   @author Andrei Dmitriev : area=Choice
   6   run applet GetSizeTest.html
   7 */
   8 
   9 import java.awt.*;
  10 import java.awt.event.*;
  11 import java.applet.*;
  12 import sun.awt.SunToolkit;
  13 
  14 public class GetSizeTest extends Applet {
  15 
  16     String []s = {      "Choice 1",
  17                         "Choice 2",
  18                         "unselected choices",
  19                         "what choices do I have?",
  20                         "Will I pick the same thing in the future?",
  21                 };
  22     boolean passed = false;
  23     Robot robot = null;
  24 
  25     public void init() {
  26         try {
  27             robot = new Robot();
  28 
  29             Frame f = new Frame("choice test");
  30 
  31             Panel p = new Panel();
  32             p.setLayout(null);
  33 
  34             Choice c = new Choice();
  35             for (int i = 0; i < s.length; i++)
  36                     c.addItem(s[i]);
  37 
  38             c.addMouseListener(new MouseAdapter() {
  39                 public void mouseReleased(MouseEvent e) {
  40                     System.err.println("Test passed");
  41                     passed = true;
  42                 }
  43             });
  44 
  45             p.add(c);
  46 
  47             f.add(p);
  48 
  49             f.setSize(300, 300);
  50 
  51             f.addWindowListener(new WindowAdapter() {
  52                 public void windowClosing(WindowEvent we) {
  53                     System.err.println("Test passed");
  54                     passed = true;
  55                 }
  56             });
  57 
  58             f.setVisible(true);
  59 
  60             c.setSize(200, 200);
  61             f.validate();
  62             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  63 
  64             robot.waitForIdle();
  65 
  66             Point pt = c.getLocationOnScreen();
  67             robot.mouseMove(pt.x + c.getWidth() - 10, pt.y + c.getHeight() / 2);
  68             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  69             robot.mousePress(InputEvent.BUTTON2_MASK);
  70             robot.mouseRelease(InputEvent.BUTTON2_MASK);
  71             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  72         } catch (Throwable e) {
  73             if (robot == null){
  74                 throw new RuntimeException( "Test failed.Unable to initialize Robot "+e);
  75             }
  76             throw new RuntimeException( "Test failed due to thrown exception "+e);
  77         }
  78         if (!passed) {
  79             throw new RuntimeException( "Timeout. Choice component size is not actual size." );
  80         }
  81         System.err.println("Test passed.");
  82     }
  83 }