Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EventQueue/PostEventOrderingTest/PostEventOrderingTest.java
38828 views
/*1* Copyright (c) 2012, 2013, 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*/2223/**24* @test PostEventOrderingTest.java25* @bug 4171596 669958926* @summary Checks that the posting of events between the PostEventQueue27* @summary and the EventQueue maintains proper ordering.28* @run main PostEventOrderingTest29* @author fredx30*/3132import java.awt.*;33import java.awt.event.*;34import sun.awt.AppContext;35import sun.awt.SunToolkit;3637public class PostEventOrderingTest {38static boolean testPassed = true;3940public static void main(String[] args) throws Throwable {41EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();42for (int i = 0; i < 100; i++) {43for (int j = 0; j < 100; j++) {44q.postEvent(new PostActionEvent());45for (int k = 0; k < 10; k++) {46SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());47}48}49for (int k = 0; k < 100; k++) {50SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());51}52}5354for (;;) {55Thread.currentThread().sleep(100);56if (q.peekEvent() == null) {57Thread.currentThread().sleep(100);58if (q.peekEvent() == null)59break;60}61}6263if (!testPassed) {64throw new Exception("PostEventOrderingTest FAILED -- events dispatched out of order.");65} else {66System.out.println("PostEventOrderingTest passed!");67}68}69}7071class PostActionEvent extends ActionEvent implements ActiveEvent {72static int counter = 0;73static int mostRecent = -1;7475int myval;7677public PostActionEvent() {78super("", ACTION_PERFORMED, "" + counter);79myval = counter++;80}8182public void dispatch() {83//System.out.println("myval = "+myval+", mostRecent = "+mostRecent+", diff = "+(myval-mostRecent)+".");84if ((myval - mostRecent) != 1)85PostEventOrderingTest.testPassed = false;86mostRecent = myval;87}88}899091