jdk/test/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java
author serb
Fri, 17 Apr 2015 16:54:13 +0300
changeset 30469 bac0a7ff7e1e
parent 28087 622b2f420bc3
child 36511 9d0388c6b336
permissions -rw-r--r--
8074028: Remove API references to java.awt.peer Reviewed-by: alanb, ant, yan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     1
/*
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     4
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     8
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    13
 * accompanied this code).
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    14
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    18
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    21
 * questions.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    22
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    23
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    24
import java.awt.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    25
import java.awt.event.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    26
import java.awt.peer.ComponentPeer;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    27
import java.lang.reflect.Constructor;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    29
import java.lang.reflect.Method;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    30
import java.util.ArrayList;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    31
import javax.swing.*;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
    32
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
    33
import sun.awt.AWTAccessor;
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
    34
import sun.awt.EmbeddedFrame;
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    35
import java.io.*;
25129
3961e8fcb668 8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests
yan
parents: 24539
diff changeset
    36
import test.java.awt.regtesthelpers.Util;
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    37
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    38
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    39
 * <p>This class provides basis for AWT Mixing testing.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    40
 * <p>It provides all standard test machinery and should be used by
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    41
 * extending and overriding next methods:
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    42
 * <li> {@link OverlappingTestBase#prepareControls()} - setup UI components
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    43
 * <li> {@link OverlappingTestBase#performTest()} -  run particular test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    44
 * Those methods would be run in the loop for each AWT component.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    45
 * <p>Current AWT component should be added to the tested UI by {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) ()}.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    46
 * There AWT components are prepared to be tested as being overlayed by other (e.g. Swing) components - they are colored to
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    47
 * {@link OverlappingTestBase#AWT_BACKGROUND_COLOR} and throws failure on catching mouse event.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    48
 * <p> Validation of component being overlayed should be tested by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    49
 * See each method javadoc for more details.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    50
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    51
 * <p>Due to test machinery limitations all test should be run from their own main() by calling next coe
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    52
 * <code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    53
 *     public static void main(String args[]) throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    54
 *        instance = new YourTestInstance();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    55
 *        OverlappingTestBase.doMain(args);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    56
 *     }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    57
 * </code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    58
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    59
 * @author Sergey Grinev
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    60
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    61
public abstract class OverlappingTestBase {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    62
    // working variables
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    63
    private static volatile boolean wasHWClicked = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    64
    private static volatile boolean passed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    65
    // constants
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    66
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    67
     * Default color for AWT component used for validate correct drawing of overlapping. <b>Never</b> use it for lightweight components.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    68
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    69
    protected static final Color AWT_BACKGROUND_COLOR = new Color(21, 244, 54);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    70
    protected static Color AWT_VERIFY_COLOR = AWT_BACKGROUND_COLOR;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    71
    protected static final int ROBOT_DELAY = 500;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    72
    private static final String[] simpleAwtControls = {"Button", "Checkbox", "Label", "TextArea"};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    73
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    74
     * Generic strings array. To be used for population of List based controls.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    75
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    76
    protected static final String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Rhynocephalia Granda", "Bear", "Tiger", "Mustang"};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    77
    // "properties"
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    78
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    79
     * Tests customization. Set this variable to test only control from java.awt
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    80
     * <p>Usage of this variable should be marked with CR being the reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    81
     * <p>Do not use this variable simultaneously with {@link OverlappingTestBase#skipClassNames}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    82
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    83
    protected String onlyClassName = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    84
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    85
     * For customizing tests. List classes' simple names to skip them from testings.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    86
     * <p>Usage of this variable should be marked with CR being the reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    87
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    88
    protected String[] skipClassNames = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    89
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    90
     * Set to false to avoid event delivery validation
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    91
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    92
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    93
    protected boolean useClickValidation = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    94
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    95
     * Set to false if test doesn't supposed to verify EmbeddedFrame
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    96
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    97
    protected boolean testEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    98
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    99
     * Set this variable to true if testing embedded frame is impossible (on Mac, for instance, for now).
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   100
     * The testEmbeddedFrame is explicitly set to true in dozen places.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   101
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   102
    protected boolean skipTestingEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   103
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   104
    public static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("os x");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   105
    private boolean isFrameBorderCalculated;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   106
    private int borderShift;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   107
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   108
    {    if (Toolkit.getDefaultToolkit().getClass().getName().matches(".*L.*Toolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   109
             // No EmbeddedFrame in LWToolkit/LWCToolkit, yet
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   110
             // And it should be programmed some other way, too, in any case
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   111
             System.err.println("skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   112
             skipTestingEmbeddedFrame = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   113
         }else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   114
             System.err.println("do not skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   115
         }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   116
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   117
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   118
    protected int frameBorderCounter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   119
        if (!isFrameBorderCalculated) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   120
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   121
                new FrameBorderCounter(); // force compilation by jtreg
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   122
                String JAVA_HOME = System.getProperty("java.home");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   123
                Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   124
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   125
                    p.waitFor();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   126
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   127
                    e.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   128
                    throw new RuntimeException(e);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   129
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   130
                if (p.exitValue() != 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   131
                    throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream()));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   132
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   133
                borderShift = Integer.parseInt(readInputStream(p.getInputStream()).trim());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   134
                isFrameBorderCalculated = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   135
            } catch (IOException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   136
                e.printStackTrace();
25129
3961e8fcb668 8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests
yan
parents: 24539
diff changeset
   137
                throw new RuntimeException("Problem calculating a native border size");
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   138
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   139
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   140
        return borderShift;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   141
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   142
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   143
    public void getVerifyColor() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   144
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   145
            final int size = 200;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   146
            final Point[] p = new Point[1];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   147
            SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   148
                public void run(){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   149
                    JFrame frame = new JFrame("set back");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   150
                    frame.getContentPane().setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   151
                    frame.setSize(size, size);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   152
                    frame.setUndecorated(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   153
                    frame.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   154
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   155
                    p[0] = frame.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   156
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   157
            });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   158
            Robot robot = new Robot();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   159
            robot.waitForIdle();
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   160
            Thread.sleep(ROBOT_DELAY);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   161
            AWT_VERIFY_COLOR = robot.getPixelColor(p[0].x+size/2, p[0].y+size/2);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   162
            System.out.println("Color will be compared with " + AWT_VERIFY_COLOR + " instead of " + AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   163
        } catch (Exception e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   164
            System.err.println("Cannot get verify color: "+e.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   165
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   166
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   167
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   168
    private String readInputStream(InputStream is) throws IOException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   169
        byte[] buffer = new byte[4096];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   170
        int len = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   171
        StringBuilder sb = new StringBuilder();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   172
        try (InputStreamReader isr = new InputStreamReader(is)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   173
            while ((len = is.read(buffer)) > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   174
                sb.append(new String(buffer, 0, len));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   175
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   176
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   177
        return sb.toString();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   178
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   179
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   180
    private void setupControl(final Component control) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   181
        if (useClickValidation) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   182
            control.addMouseListener(new MouseAdapter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   183
                @Override
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   184
                public void mouseClicked(MouseEvent e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   185
                    System.err.println("ERROR: " + control.getClass() + " received mouse click.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   186
                    wasHWClicked = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   187
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   188
            });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   189
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   190
        control.setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   191
        control.setForeground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   192
        control.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   193
        control.setFocusable(false);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   194
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   195
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   196
    private void addAwtControl(java.util.List<Component> container, final Component control) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   197
        String simpleName = control.getClass().getSimpleName();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   198
        if (onlyClassName != null && !simpleName.equals(onlyClassName)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   199
            return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   200
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   201
        if (skipClassNames != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   202
            for (String skipMe : skipClassNames) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   203
                if (simpleName.equals(skipMe)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   204
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   205
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   206
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   207
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   208
        setupControl(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   209
        container.add(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   210
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   211
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   212
    private void addSimpleAwtControl(java.util.List<Component> container, String className) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   213
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   214
            Class definition = Class.forName("java.awt." + className);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   215
            Constructor constructor = definition.getConstructor(new Class[]{String.class});
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   216
            java.awt.Component component = (java.awt.Component) constructor.newInstance(new Object[]{"AWT Component " + className});
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   217
            addAwtControl(container, component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   218
        } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   219
            System.err.println(ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   220
            fail("Setup error, this jdk doesn't have awt conrol " + className);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   221
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   222
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   223
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   224
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   225
     * Adds current AWT control to container
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   226
     * <p>N.B.: if testEmbeddedFrame == true this method will also add EmbeddedFrame over Canvas
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   227
     * and it should be called <b>after</b> Frame.setVisible(true) call
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   228
     * @param container container to hold AWT component
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   229
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   230
    protected final void propagateAWTControls(Container container) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   231
        if (currentAwtControl != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   232
            container.add(currentAwtControl);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   233
        } else { // embedded frame
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   234
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   235
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   236
                //create embedder
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   237
                Canvas embedder = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   238
                embedder.setBackground(Color.RED);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   239
                embedder.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   240
                container.add(embedder);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   241
                container.setVisible(true); // create peer
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   242
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   243
                long frameWindow = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   244
                String getWindowMethodName = "getHWnd";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   245
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   246
                    getWindowMethodName = "getWindow";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   247
                }
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
   248
                ComponentPeer peer = AWTAccessor.getComponentAccessor()
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
   249
                                                .getPeer(embedder);
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28087
diff changeset
   250
                //  System.err.println("Peer: " + peer);
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   251
                Method getWindowMethod = peer.getClass().getMethod(getWindowMethodName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   252
                frameWindow = (Long) getWindowMethod.invoke(peer);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   253
//                System.err.println("frame peer ID: " + frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   254
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   255
                String eframeClassName = "sun.awt.windows.WEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   256
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   257
                    eframeClassName = "sun.awt.X11.XEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   258
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   259
                Class eframeClass = Class.forName(eframeClassName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   260
                Constructor eframeCtor = eframeClass.getConstructor(long.class);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   261
                EmbeddedFrame eframe = (EmbeddedFrame) eframeCtor.newInstance(frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   262
                setupControl(eframe);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   263
                eframe.setSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   264
                eframe.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   265
//                System.err.println(eframe.getSize());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   266
            } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   267
                ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   268
                fail("Failed to instantiate EmbeddedFrame: " + ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   269
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   270
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   271
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   272
    private static final Font hugeFont = new Font("Arial", Font.BOLD, 70);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   273
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   274
    private java.util.List<Component> getAWTControls() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   275
        java.util.List<Component> components = new ArrayList<Component>();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   276
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   277
        for (String clazz : simpleAwtControls) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   278
            addSimpleAwtControl(components, clazz);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   279
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   280
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   281
        TextField tf = new TextField();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   282
        tf.setFont(hugeFont);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   283
        addAwtControl(components, tf);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   284
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   285
        // more complex controls
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   286
        Choice c = new Choice();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   287
        for (int i = 0; i < petStrings.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   288
            c.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   289
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   290
        addAwtControl(components, c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   291
        c.setPreferredSize(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   292
        c.setFont(hugeFont); // to make control bigger as setPrefferedSize don't do his job here
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   293
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   294
        List l = new List(petStrings.length);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   295
        for (int i = 0; i < petStrings.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   296
            l.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   297
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   298
        addAwtControl(components, l);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   299
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   300
        Canvas canvas = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   301
        canvas.setSize(100, 200);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   302
        addAwtControl(components, canvas);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   303
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   304
        Scrollbar sb = new Scrollbar(Scrollbar.VERTICAL, 500, 1, 0, 500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   305
        addAwtControl(components, sb);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   306
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   307
        Scrollbar sb2 = new Scrollbar(Scrollbar.HORIZONTAL, 500, 1, 0, 500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   308
        addAwtControl(components, sb2);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   309
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   310
        return components;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   311
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   312
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   313
     * Default shift for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   314
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   315
    protected static Point shift = new Point(16, 16);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   316
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   317
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   318
     * Verifies point using specified AWT Robot. Supposes <code>defaultShift == true</code> for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) }.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   319
     * This method is used to verify controls by providing just their plain screen coordinates.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   320
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   321
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   322
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   323
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   324
    protected void clickAndBlink(Robot robot, Point lLoc) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   325
        clickAndBlink(robot, lLoc, true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   326
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   327
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   328
     * Default failure message for color check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   329
     * @see OverlappingTestBase#performTest()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   330
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   331
    protected String failMessageColorCheck = "The LW component did not pass pixel color check and is overlapped";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   332
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   333
     * Default failure message event check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   334
     * @see OverlappingTestBase#performTest()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   335
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   336
    protected String failMessage = "The LW component did not received the click.";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   337
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   338
    private static boolean isValidForPixelCheck(Component component) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   339
        if ((component instanceof java.awt.Scrollbar) || isMac && (component instanceof java.awt.Button)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   340
            return false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   341
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   342
        return true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   343
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   344
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   345
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   346
     * Preliminary validation - should be run <b>before</b> overlapping happens to ensure test is correct.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   347
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   348
     * @param lLoc point to validate to be <b>of</b> {@link OverlappingTestBase#AWT_BACKGROUND_COLOR}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   349
     * @param component tested component, should be pointed out as not all components are valid for pixel check.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   350
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   351
    protected void pixelPreCheck(Robot robot, Point lLoc, Component component) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   352
        if (isValidForPixelCheck(component)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   353
            int tries = 10;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   354
            Color c = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   355
            while (tries-- > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   356
                c = robot.getPixelColor(lLoc.x, lLoc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   357
                System.out.println("Precheck. color: "+c+" compare with "+AWT_VERIFY_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   358
                if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   359
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   360
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   361
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   362
                    Thread.sleep(100);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   363
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   364
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   365
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   366
            System.err.println(lLoc + ": " + c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   367
            fail("Dropdown test setup failure, colored part of AWT component is not located at click area");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   368
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   369
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   370
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   371
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   372
     * Verifies point using specified AWT Robot.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   373
     * <p>Firstly, verifies point by color pixel check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   374
     * <p>Secondly, verifies event delivery by mouse click
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   375
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   376
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   377
     * @param defaultShift if true verified position will be shifted by {@link OverlappingTestBase#shift }.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   378
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   379
    protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   380
        Point loc = lLoc.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   381
        //check color
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   382
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   383
        try{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   384
            Thread.sleep(500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   385
        }catch(Exception exx){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   386
            exx.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   387
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   388
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   389
        if (defaultShift) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   390
            loc.translate(shift.x, shift.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   391
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   392
        if (!(System.getProperty("os.name").toLowerCase().contains("os x"))) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   393
            Color c = robot.getPixelColor(loc.x, loc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   394
            System.out.println("C&B. color: "+c+" compare with "+AWT_VERIFY_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   395
            if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   396
                fail(failMessageColorCheck);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   397
                passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   398
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   399
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   400
            // perform click
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   401
            Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   402
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   403
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   404
        robot.mouseMove(loc.x, loc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   405
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   406
        robot.mousePress(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   407
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   408
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   409
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   410
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   411
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   412
     * This method should be overriden with code which setups UI for testing.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   413
     * Code in this method <b>will</b> be called only from AWT thread so Swing operations can be called directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   414
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   415
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   416
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   417
    protected abstract void prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   418
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   419
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   420
     * This method should be overriden with test execution. It will <b>not</b> be called from AWT thread so all Swing operations should be treated accordingly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   421
     * @return true if test passed. Otherwise fail with default fail message.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   422
     * @see {@link OverlappingTestBase#failMessage} default fail message
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   423
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   424
    protected abstract boolean performTest();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   425
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   426
     * This method can be overriden with cleanup routines. It will be called from AWT thread so all Swing operations should be treated accordingly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   427
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   428
    protected void cleanup() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   429
        // intentionally do nothing
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   430
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   431
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   432
     * Currect tested AWT Control. Usually shouldn't be accessed directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   433
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   434
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   435
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   436
    protected Component currentAwtControl;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   437
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   438
    private void testComponent(Component component) throws InterruptedException, InvocationTargetException {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   439
        Robot robot = null;
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   440
        try {
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   441
            robot = new Robot();
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   442
        }catch(Exception ignorex) {
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   443
        }
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   444
        currentAwtControl = component;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   445
        System.out.println("Testing " + currentAwtControl.getClass().getSimpleName());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   446
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   447
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   448
                prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   449
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   450
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   451
        if (component != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   452
            Util.waitTillShown(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   453
        }
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   454
        Util.waitForIdle(robot);
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   455
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   456
            Thread.sleep(500); // wait for graphic effects on systems like Win7
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   457
        } catch (InterruptedException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   458
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   459
        if (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   460
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   461
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   462
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   463
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   464
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   465
                cleanup();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   466
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   467
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   468
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   469
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   470
    private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   471
        Robot robot = null;
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   472
        try {
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   473
            robot = new Robot();
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   474
        }catch(Exception ignorex) {
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   475
        }
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   476
        System.out.println("Testing EmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   477
        currentAwtControl = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   478
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   479
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   480
                prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   481
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   482
        });
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 25129
diff changeset
   483
        Util.waitForIdle(robot);
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   484
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   485
            Thread.sleep(500); // wait for graphic effects on systems like Win7
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   486
        } catch (InterruptedException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   487
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   488
        if (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   489
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   490
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   491
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   492
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   493
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   494
                cleanup();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   495
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   496
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   497
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   498
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   499
    private void testAwtControls() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   500
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   501
            for (Component component : getAWTControls()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   502
                testComponent(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   503
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   504
            if (testEmbeddedFrame && !skipTestingEmbeddedFrame) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   505
                testEmbeddedFrame();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   506
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   507
        } catch (InvocationTargetException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   508
            ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   509
            fail(ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   510
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   511
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   512
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   513
     * Used by standard test machinery. See usage at {@link OverlappingTestBase }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   514
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   515
    protected static OverlappingTestBase instance;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   516
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   517
    protected OverlappingTestBase() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   518
        getVerifyColor();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   519
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   520
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   521
    /*****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   522
     * Standard Test Machinery Section
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   523
     * DO NOT modify anything in this section -- it's a
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   524
     * standard chunk of code which has all of the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   525
     * synchronisation necessary for the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   526
     * By keeping it the same in all tests, it is easier
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   527
     * to read and understand someone else's test, as
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   528
     * well as insuring that all tests behave correctly
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   529
     * with the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   530
     * There is a section following this for test-
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   531
     * classes
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   532
     ******************************************************/
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   533
    private static void init() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   534
        //*** Create instructions for the user here ***
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   535
        //System.setProperty("sun.awt.disableMixing", "true");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   536
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   537
        String[] instructions = {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   538
            "This is an AUTOMATIC test, simply wait until it is done.",
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   539
            "The result (passed or failed) will be shown in the",
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   540
            "message window below."
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   541
        };
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   542
        Sysout.createDialog();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   543
        Sysout.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   544
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   545
        instance.testAwtControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   546
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   547
        if (wasHWClicked) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   548
            fail("HW component received the click.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   549
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   550
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   551
        if (passed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   552
            pass();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   553
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   554
    }//End  init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   555
    private static boolean theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   556
    private static boolean testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   557
    private static String failureMessage = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   558
    private static Thread mainThread = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   559
    private static int sleepTime = 300000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   560
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   561
    // Not sure about what happens if multiple of this test are
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   562
    //  instantiated in the same VM.  Being static (and using
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   563
    //  static vars), it aint gonna work.  Not worrying about
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   564
    //  it for now.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   565
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   566
     * Starting point for test runs. See usage at {@link OverlappingTestBase }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   567
     * @param args regular main args, not used.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   568
     * @throws InterruptedException
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   569
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   570
    public static void doMain(String args[]) throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   571
        mainThread = Thread.currentThread();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   572
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   573
            init();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   574
        } catch (TestPassedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   575
            //The test passed, so just return from main and harness will
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   576
            // interepret this return as a pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   577
            return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   578
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   579
        //At this point, neither test pass nor test fail has been
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   580
        // called -- either would have thrown an exception and ended the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   581
        // test, so we know we have multiple threads.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   582
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   583
        //Test involves other threads, so sleep and wait for them to
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   584
        // called pass() or fail()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   585
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   586
            Thread.sleep(sleepTime);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   587
            //Timed out, so fail the test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   588
            throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   589
        } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   590
            //The test harness may have interrupted the test.  If so, rethrow the exception
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   591
            // so that the harness gets it and deals with it.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   592
            if (!testGeneratedInterrupt) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   593
                throw e;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   594
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   595
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   596
            //reset flag in case hit this code more than once for some reason (just safety)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   597
            testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   598
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   599
            if (theTestPassed == false) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   600
                throw new RuntimeException(failureMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   601
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   602
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   603
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   604
    }//main
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   605
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   606
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   607
     * Test will fail if not passed after this timeout. Default timeout is 300 seconds.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   608
     * @param seconds timeout in seconds
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   609
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   610
    public static synchronized void setTimeoutTo(int seconds) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   611
        sleepTime = seconds * 1000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   612
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   613
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   614
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   615
     * Set test as passed. Usually shoudn't be called directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   616
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   617
    public static synchronized void pass() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   618
        Sysout.println("The test passed.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   619
        Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   620
        //first check if this is executing in main thread
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   621
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   622
            //Still in the main thread, so set the flag just for kicks,
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   623
            // and throw a test passed exception which will be caught
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   624
            // and end the test.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   625
            theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   626
            throw new TestPassedException();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   627
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   628
        theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   629
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   630
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   631
    }//pass()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   632
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   633
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   634
     * Fail test generic message.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   635
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   636
    public static synchronized void fail() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   637
        //test writer didn't specify why test failed, so give generic
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   638
        fail("it just plain failed! :-)");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   639
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   640
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   641
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   642
     * Fail test providing specific reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   643
     * @param whyFailed reason
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   644
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   645
    public static synchronized void fail(String whyFailed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   646
        Sysout.println("The test failed: " + whyFailed);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   647
        Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   648
        //check if this called from main thread
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   649
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   650
            //If main thread, fail now 'cause not sleeping
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   651
            throw new RuntimeException(whyFailed);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   652
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   653
        theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   654
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   655
        failureMessage = whyFailed;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   656
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   657
    }//fail()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   658
}// class LWComboBox
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   659
class TestPassedException extends RuntimeException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   660
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   661
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   662
//*********** End Standard Test Machinery Section **********
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   663
//************ Begin classes defined for the test ****************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   664
// if want to make listeners, here is the recommended place for them, then instantiate
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   665
//  them in init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   666
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   667
/* Example of a class which may be written as part of a test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   668
class NewClass implements anInterface
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   669
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   670
static int newVar = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   671
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   672
public void eventDispatched(AWTEvent e)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   673
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   674
//Counting events to see if we get enough
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   675
eventCount++;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   676
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   677
if( eventCount == 20 )
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   678
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   679
//got enough events, so pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   680
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   681
LWComboBox.pass();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   682
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   683
else if( tries == 20 )
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   684
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   685
//tried too many times without getting enough events so fail
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   686
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   687
LWComboBox.fail();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   688
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   689
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   690
}// eventDispatched()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   691
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   692
}// NewClass class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   693
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   694
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   695
//************** End classes defined for the test *******************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   696
/****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   697
Standard Test Machinery
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   698
DO NOT modify anything below -- it's a standard
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   699
chunk of code whose purpose is to make user
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   700
interaction uniform, and thereby make it simpler
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   701
to read and understand someone else's test.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   702
 ****************************************************/
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   703
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   704
This is part of the standard test machinery.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   705
It creates a dialog (with the instructions), and is the interface
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   706
for sending text messages to the user.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   707
To print the instructions, send an array of strings to Sysout.createDialog
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   708
WithInstructions method.  Put one line of instructions per array entry.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   709
To display a message for the tester to see, simply call Sysout.println
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   710
with the string to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   711
This mimics System.out.println but works within the test harness as well
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   712
as standalone.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   713
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   714
class Sysout {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   715
    private static TestDialog dialog;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   716
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   717
    public static void createDialogWithInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   718
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   719
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   720
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   721
        println("Any messages for the tester will display here.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   722
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   723
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   724
    public static void createDialog() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   725
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   726
        String[] defInstr = {"Instructions will appear here. ", ""};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   727
        dialog.printInstructions(defInstr);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   728
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   729
        println("Any messages for the tester will display here.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   730
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   731
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   732
    public static void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   733
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   734
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   735
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   736
    public static void println(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   737
        dialog.displayMessage(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   738
        System.out.println(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   739
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   740
}// Sysout  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   741
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   742
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   743
This is part of the standard test machinery.  It provides a place for the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   744
test instructions to be displayed, and a place for interactive messages
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   745
to the user to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   746
To have the test instructions displayed, see Sysout.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   747
To have a message to the user be displayed, see Sysout.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   748
Do not call anything in this dialog directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   749
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   750
class TestDialog extends Dialog {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   751
    TextArea instructionsText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   752
    TextArea messageText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   753
    int maxStringLength = 80;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   754
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   755
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   756
    public TestDialog(Frame frame, String name) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   757
        super(frame, name);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   758
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   759
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   760
        add("North", instructionsText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   761
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   762
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   763
        add("Center", messageText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   764
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   765
        pack();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   766
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   767
       //setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   768
    }// TestDialog()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   769
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   770
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   771
    public void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   772
        //Clear out any current instructions
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   773
        instructionsText.setText("");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   774
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   775
        //Go down array of instruction strings
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   776
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   777
        String printStr, remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   778
        for (int i = 0; i < instructions.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   779
            //chop up each into pieces maxSringLength long
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   780
            remainingStr = instructions[i];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   781
            while (remainingStr.length() > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   782
                //if longer than max then chop off first max chars to print
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   783
                if (remainingStr.length() >= maxStringLength) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   784
                    //Try to chop on a word boundary
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   785
                    int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   786
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   787
                    if (posOfSpace <= 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   788
                        posOfSpace = maxStringLength - 1;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   789
                    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   790
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   791
                    printStr = remainingStr.substring(0, posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   792
                    remainingStr = remainingStr.substring(posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   793
                } //else just print
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   794
                else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   795
                    printStr = remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   796
                    remainingStr = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   797
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   798
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   799
                instructionsText.append(printStr + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   800
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   801
            }// while
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   802
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   803
        }// for
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   804
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   805
    }//printInstructions()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   806
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   807
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   808
    public void displayMessage(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   809
        messageText.append(messageIn + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   810
        System.out.println(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   811
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   812
}// TestDialog  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   813