jdk/test/java/awt/event/InvocationEvent/InvocationEventTest.java
changeset 4264 40c232605c68
child 5506 202f599c92aa
equal deleted inserted replaced
4263:db2d1f69a60e 4264:40c232605c68
       
     1 /*
       
     2  * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /*
       
    25   @test
       
    26   @bug 6852111
       
    27   @summary Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
       
    28   @author dmitry.cherepanov@sun.com: area=awt.event
       
    29   @run main InvocationEventTest
       
    30 */
       
    31 
       
    32 /**
       
    33  * InvocationEventTest.java
       
    34  *
       
    35  * summary: Tests new isDispatched method of the InvocationEvent class
       
    36  */
       
    37 
       
    38 import java.awt.*;
       
    39 import java.awt.event.*;
       
    40 
       
    41 public class InvocationEventTest
       
    42 {
       
    43     public static void main(String []s) throws Exception
       
    44     {
       
    45         Toolkit tk = Toolkit.getDefaultToolkit();
       
    46         Runnable runnable = new Runnable() {
       
    47             public void run() {
       
    48             }
       
    49         };
       
    50         Object lock = new Object();
       
    51         InvocationEvent event = new InvocationEvent(tk, runnable, lock, true);
       
    52 
       
    53         if (event.isDispatched()) {
       
    54             throw new RuntimeException(" Initially, the event shouldn't be dispatched ");
       
    55         }
       
    56 
       
    57         synchronized(lock) {
       
    58             tk.getSystemEventQueue().postEvent(event);
       
    59             while(!event.isDispatched()) {
       
    60                 lock.wait();
       
    61             }
       
    62         }
       
    63 
       
    64         if(!event.isDispatched()) {
       
    65             throw new RuntimeException(" Finally, the event should be dispatched ");
       
    66         }
       
    67     }
       
    68 }