jdk/test/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java
author yan
Tue, 29 Apr 2014 14:32:38 +0400
changeset 24539 f0250a79028b
child 25129 3961e8fcb668
permissions -rw-r--r--
8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk Reviewed-by: anthony, pchelko
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
/*
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    32
import sun.awt.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    33
import java.io.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    34
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    35
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    36
 * <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
    37
 * <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
    38
 * extending and overriding next methods:
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    39
 * <li> {@link OverlappingTestBase#prepareControls()} - setup UI components
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    40
 * <li> {@link OverlappingTestBase#performTest()} -  run particular test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    41
 * 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
    42
 * <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
    43
 * 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
    44
 * {@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
    45
 * <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
    46
 * See each method javadoc for more details.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    47
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    48
 * <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
    49
 * <code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    50
 *     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
    51
 *        instance = new YourTestInstance();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    52
 *        OverlappingTestBase.doMain(args);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    53
 *     }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    54
 * </code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    55
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    56
 * @author Sergey Grinev
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    57
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    58
public abstract class OverlappingTestBase {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    59
    // working variables
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    60
    private static volatile boolean wasHWClicked = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    61
    private static volatile boolean passed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    62
    // constants
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    63
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    64
     * 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
    65
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    66
    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
    67
    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
    68
    protected static final int ROBOT_DELAY = 500;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    69
    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
    70
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    71
     * 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
    72
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    73
    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
    74
    // "properties"
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
     * 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
    77
     * <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
    78
     * <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
    79
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    80
    protected String onlyClassName = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    81
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    82
     * 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
    83
     * <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
    84
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    85
    protected String[] skipClassNames = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    86
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    87
     * 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
    88
     * @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
    89
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    90
    protected boolean useClickValidation = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    91
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    92
     * 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
    93
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    94
    protected boolean testEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    95
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    96
     * 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
    97
     * 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
    98
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    99
    protected boolean skipTestingEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   100
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   101
    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
   102
    private boolean isFrameBorderCalculated;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   103
    private int borderShift;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   104
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   105
    {    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
   106
             // No EmbeddedFrame in LWToolkit/LWCToolkit, yet
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   107
             // 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
   108
             System.err.println("skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   109
             skipTestingEmbeddedFrame = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   110
         }else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   111
             System.err.println("do not skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   112
         }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   113
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   114
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   115
    protected int frameBorderCounter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   116
        if (!isFrameBorderCalculated) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   117
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   118
                new FrameBorderCounter(); // force compilation by jtreg
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   119
                String JAVA_HOME = System.getProperty("java.home");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   120
                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
   121
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   122
                    p.waitFor();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   123
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   124
                    e.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   125
                    throw new RuntimeException(e);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   126
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   127
                if (p.exitValue() != 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   128
                    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
   129
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   130
                borderShift = Integer.parseInt(readInputStream(p.getInputStream()).trim());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   131
                isFrameBorderCalculated = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   132
            } catch (IOException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   133
                e.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   134
                System.exit(1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   135
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   136
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   137
        return borderShift;
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
    public void getVerifyColor() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   141
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   142
            final int size = 200;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   143
            final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   144
            final Point[] p = new Point[1];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   145
            SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   146
                public void run(){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   147
                    JFrame frame = new JFrame("set back");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   148
                    frame.getContentPane().setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   149
                    frame.setSize(size, size);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   150
                    frame.setUndecorated(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   151
                    frame.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   152
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   153
                    p[0] = frame.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   154
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   155
            });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   156
            Robot robot = new Robot();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   157
            toolkit.realSync();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   158
            Thread.sleep(ROBOT_DELAY);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   159
            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
   160
            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
   161
        } catch (Exception e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   162
            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
   163
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   164
    }
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
    private String readInputStream(InputStream is) throws IOException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   167
        byte[] buffer = new byte[4096];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   168
        int len = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   169
        StringBuilder sb = new StringBuilder();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   170
        try (InputStreamReader isr = new InputStreamReader(is)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   171
            while ((len = is.read(buffer)) > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   172
                sb.append(new String(buffer, 0, len));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   173
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   174
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   175
        return sb.toString();
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
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   178
    private void setupControl(final Component control) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   179
        if (useClickValidation) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   180
            control.addMouseListener(new MouseAdapter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   181
                @Override
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   182
                public void mouseClicked(MouseEvent e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   183
                    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
   184
                    wasHWClicked = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   185
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   186
            });
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
        control.setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   189
        control.setForeground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   190
        control.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   191
        control.setFocusable(false);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   192
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   193
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   194
    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
   195
        String simpleName = control.getClass().getSimpleName();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   196
        if (onlyClassName != null && !simpleName.equals(onlyClassName)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   197
            return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   198
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   199
        if (skipClassNames != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   200
            for (String skipMe : skipClassNames) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   201
                if (simpleName.equals(skipMe)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   202
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   203
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   204
            }
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
        setupControl(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   207
        container.add(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   208
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   209
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   210
    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
   211
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   212
            Class definition = Class.forName("java.awt." + className);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   213
            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
   214
            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
   215
            addAwtControl(container, component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   216
        } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   217
            System.err.println(ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   218
            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
   219
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   220
    }
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
     * Adds current AWT control to container
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   224
     * <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
   225
     * 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
   226
     * @param container container to hold AWT component
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   227
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   228
    protected final void propagateAWTControls(Container container) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   229
        if (currentAwtControl != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   230
            container.add(currentAwtControl);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   231
        } else { // embedded frame
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   232
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   233
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   234
                //create embedder
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   235
                Canvas embedder = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   236
                embedder.setBackground(Color.RED);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   237
                embedder.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   238
                container.add(embedder);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   239
                container.setVisible(true); // create peer
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   240
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   241
                long frameWindow = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   242
                String getWindowMethodName = "getHWnd";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   243
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   244
                    getWindowMethodName = "getWindow";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   245
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   246
                ComponentPeer peer = embedder.getPeer();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   247
//                System.err.println("Peer: " + peer);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   248
                Method getWindowMethod = peer.getClass().getMethod(getWindowMethodName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   249
                frameWindow = (Long) getWindowMethod.invoke(peer);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   250
//                System.err.println("frame peer ID: " + frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   251
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   252
                String eframeClassName = "sun.awt.windows.WEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   253
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   254
                    eframeClassName = "sun.awt.X11.XEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   255
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   256
                Class eframeClass = Class.forName(eframeClassName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   257
                Constructor eframeCtor = eframeClass.getConstructor(long.class);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   258
                EmbeddedFrame eframe = (EmbeddedFrame) eframeCtor.newInstance(frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   259
                setupControl(eframe);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   260
                eframe.setSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   261
                eframe.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   262
//                System.err.println(eframe.getSize());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   263
            } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   264
                ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   265
                fail("Failed to instantiate EmbeddedFrame: " + ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   266
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   267
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   268
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   269
    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
   270
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   271
    private java.util.List<Component> getAWTControls() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   272
        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
   273
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   274
        for (String clazz : simpleAwtControls) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   275
            addSimpleAwtControl(components, clazz);
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
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   278
        TextField tf = new TextField();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   279
        tf.setFont(hugeFont);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   280
        addAwtControl(components, tf);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   281
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   282
        // more complex controls
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   283
        Choice c = new Choice();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   284
        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
   285
            c.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   286
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   287
        addAwtControl(components, c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   288
        c.setPreferredSize(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   289
        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
   290
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   291
        List l = new List(petStrings.length);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   292
        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
   293
            l.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   294
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   295
        addAwtControl(components, l);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   296
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   297
        Canvas canvas = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   298
        canvas.setSize(100, 200);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   299
        addAwtControl(components, canvas);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   300
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   301
        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
   302
        addAwtControl(components, sb);
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 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
   305
        addAwtControl(components, sb2);
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
        return components;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   308
    }
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
     * 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
   311
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   312
    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
   313
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
     * 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
   316
     * 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
   317
     * @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
   318
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   319
     * @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
   320
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   321
    protected void clickAndBlink(Robot robot, Point lLoc) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   322
        clickAndBlink(robot, lLoc, true);
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
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   325
     * Default failure message for color check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   326
     * @see OverlappingTestBase#performTest()
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
    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
   329
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   330
     * Default failure message event check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   331
     * @see OverlappingTestBase#performTest()
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
    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
   334
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   335
    private static boolean isValidForPixelCheck(Component component) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   336
        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
   337
            return false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   338
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   339
        return true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   340
    }
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
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   343
     * 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
   344
     * @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
   345
     * @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
   346
     * @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
   347
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   348
    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
   349
        if (isValidForPixelCheck(component)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   350
            int tries = 10;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   351
            Color c = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   352
            while (tries-- > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   353
                c = robot.getPixelColor(lLoc.x, lLoc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   354
                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
   355
                if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   356
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   357
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   358
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   359
                    Thread.sleep(100);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   360
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   361
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   362
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   363
            System.err.println(lLoc + ": " + c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   364
            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
   365
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   366
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   367
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
     * Verifies point using specified AWT Robot.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   370
     * <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
   371
     * <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
   372
     * @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
   373
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   374
     * @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
   375
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   376
    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
   377
        Point loc = lLoc.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   378
        //check color
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   379
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   380
        try{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   381
            Thread.sleep(500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   382
        }catch(Exception exx){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   383
            exx.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   384
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   385
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   386
        if (defaultShift) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   387
            loc.translate(shift.x, shift.y);
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 (!(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
   390
            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
   391
            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
   392
            if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   393
                fail(failMessageColorCheck);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   394
                passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   395
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   396
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   397
            // perform click
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   398
            Util.waitForIdle(robot);
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
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   401
        robot.mouseMove(loc.x, loc.y);
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
        robot.mousePress(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   404
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   405
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   406
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   407
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   408
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   409
     * 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
   410
     * 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
   411
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   412
     * @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
   413
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   414
    protected abstract void prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   415
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
     * 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
   418
     * @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
   419
     * @see {@link OverlappingTestBase#failMessage} default fail message
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   420
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   421
    protected abstract boolean performTest();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   422
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   423
     * 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
   424
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   425
    protected void cleanup() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   426
        // intentionally do nothing
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
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   429
     * 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
   430
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   431
     * @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
   432
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   433
    protected Component currentAwtControl;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   434
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   435
    private void testComponent(Component component) throws InterruptedException, InvocationTargetException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   436
        currentAwtControl = component;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   437
        System.out.println("Testing " + currentAwtControl.getClass().getSimpleName());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   438
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   439
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   440
                prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   441
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   442
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   443
        if (component != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   444
            Util.waitTillShown(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   445
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   446
        Util.waitForIdle(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   447
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   448
            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
   449
        } catch (InterruptedException ex) {
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 (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   452
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   453
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   454
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   455
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   456
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   457
                cleanup();
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
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   460
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   461
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   462
    private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   463
        System.out.println("Testing EmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   464
        currentAwtControl = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   465
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   466
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   467
                prepareControls();
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
        Util.waitForIdle(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   471
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   472
            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
   473
        } catch (InterruptedException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   474
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   475
        if (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   476
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   477
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   478
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   479
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   480
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   481
                cleanup();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   482
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   483
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   484
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   485
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   486
    private void testAwtControls() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   487
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   488
            for (Component component : getAWTControls()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   489
                testComponent(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   490
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   491
            if (testEmbeddedFrame && !skipTestingEmbeddedFrame) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   492
                testEmbeddedFrame();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   493
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   494
        } catch (InvocationTargetException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   495
            ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   496
            fail(ex.getMessage());
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
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   500
     * 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
   501
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   502
    protected static OverlappingTestBase instance;
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
    protected OverlappingTestBase() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   505
        getVerifyColor();
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
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   508
    /*****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   509
     * Standard Test Machinery Section
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   510
     * 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
   511
     * 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
   512
     * synchronisation necessary for the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   513
     * 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
   514
     * 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
   515
     * 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
   516
     * with the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   517
     * 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
   518
     * classes
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
    private static void init() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   521
        //*** Create instructions for the user here ***
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   522
        //System.setProperty("sun.awt.disableMixing", "true");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   523
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   524
        String[] instructions = {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   525
            "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
   526
            "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
   527
            "message window below."
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   528
        };
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   529
        Sysout.createDialog();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   530
        Sysout.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   531
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   532
        instance.testAwtControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   533
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   534
        if (wasHWClicked) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   535
            fail("HW component received the click.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   536
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   537
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   538
        if (passed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   539
            pass();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   540
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   541
    }//End  init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   542
    private static boolean theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   543
    private static boolean testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   544
    private static String failureMessage = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   545
    private static Thread mainThread = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   546
    private static int sleepTime = 300000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   547
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   548
    // 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
   549
    //  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
   550
    //  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
   551
    //  it for now.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   552
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   553
     * 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
   554
     * @param args regular main args, not used.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   555
     * @throws InterruptedException
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   556
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   557
    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
   558
        mainThread = Thread.currentThread();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   559
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   560
            init();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   561
        } catch (TestPassedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   562
            //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
   563
            // interepret this return as a pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   564
            return;
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
        //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
   567
        // 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
   568
        // 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
   569
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   570
        //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
   571
        // called pass() or fail()
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
            Thread.sleep(sleepTime);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   574
            //Timed out, so fail the test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   575
            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
   576
        } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   577
            //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
   578
            // 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
   579
            if (!testGeneratedInterrupt) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   580
                throw e;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   581
            }
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
            //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
   584
            testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   585
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   586
            if (theTestPassed == false) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   587
                throw new RuntimeException(failureMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   588
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   589
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   590
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   591
    }//main
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   592
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   593
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   594
     * 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
   595
     * @param seconds timeout in seconds
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   596
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   597
    public static synchronized void setTimeoutTo(int seconds) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   598
        sleepTime = seconds * 1000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   599
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   600
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
     * 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
   603
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   604
    public static synchronized void pass() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   605
        Sysout.println("The test passed.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   606
        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
   607
        //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
   608
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   609
            //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
   610
            // 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
   611
            // and end the test.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   612
            theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   613
            throw new TestPassedException();
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
        theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   616
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   617
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   618
    }//pass()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   619
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   620
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   621
     * Fail test generic message.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   622
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   623
    public static synchronized void fail() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   624
        //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
   625
        fail("it just plain failed! :-)");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   626
    }
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
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   629
     * Fail test providing specific reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   630
     * @param whyFailed reason
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   631
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   632
    public static synchronized void fail(String whyFailed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   633
        Sysout.println("The test failed: " + whyFailed);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   634
        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
   635
        //check if this called from main thread
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   636
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   637
            //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
   638
            throw new RuntimeException(whyFailed);
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
        theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   641
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   642
        failureMessage = whyFailed;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   643
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   644
    }//fail()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   645
}// class LWComboBox
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   646
class TestPassedException extends RuntimeException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   647
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   648
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   649
//*********** End Standard Test Machinery Section **********
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   650
//************ Begin classes defined for the test ****************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   651
// 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
   652
//  them in init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   653
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   654
/* 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
   655
class NewClass implements anInterface
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   656
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   657
static int newVar = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   658
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   659
public void eventDispatched(AWTEvent e)
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
//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
   662
eventCount++;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   663
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   664
if( eventCount == 20 )
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   665
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   666
//got enough events, so pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   667
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   668
LWComboBox.pass();
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
else if( tries == 20 )
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
//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
   673
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   674
LWComboBox.fail();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   675
}
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
}// eventDispatched()
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
}// NewClass class
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
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   682
//************** End classes defined for the test *******************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   683
/****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   684
Standard Test Machinery
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   685
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
   686
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
   687
interaction uniform, and thereby make it simpler
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   688
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
   689
 ****************************************************/
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   690
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   691
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
   692
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
   693
for sending text messages to the user.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   694
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
   695
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
   696
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
   697
with the string to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   698
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
   699
as standalone.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   700
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   701
class Sysout {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   702
    private static TestDialog dialog;
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
    public static void createDialogWithInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   705
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   706
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   707
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   708
        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
   709
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   710
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   711
    public static void createDialog() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   712
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   713
        String[] defInstr = {"Instructions will appear here. ", ""};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   714
        dialog.printInstructions(defInstr);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   715
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   716
        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
   717
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   718
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   719
    public static void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   720
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   721
    }
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
    public static void println(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   724
        dialog.displayMessage(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   725
        System.out.println(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   726
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   727
}// Sysout  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   728
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   729
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   730
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
   731
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
   732
to the user to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   733
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
   734
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
   735
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
   736
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   737
class TestDialog extends Dialog {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   738
    TextArea instructionsText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   739
    TextArea messageText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   740
    int maxStringLength = 80;
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
    //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
   743
    public TestDialog(Frame frame, String name) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   744
        super(frame, name);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   745
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   746
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   747
        add("North", instructionsText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   748
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   749
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   750
        add("Center", messageText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   751
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   752
        pack();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   753
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   754
       //setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   755
    }// TestDialog()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   756
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   757
    //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
   758
    public void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   759
        //Clear out any current instructions
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   760
        instructionsText.setText("");
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
        //Go down array of instruction strings
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   763
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   764
        String printStr, remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   765
        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
   766
            //chop up each into pieces maxSringLength long
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   767
            remainingStr = instructions[i];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   768
            while (remainingStr.length() > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   769
                //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
   770
                if (remainingStr.length() >= maxStringLength) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   771
                    //Try to chop on a word boundary
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   772
                    int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   773
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   774
                    if (posOfSpace <= 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   775
                        posOfSpace = maxStringLength - 1;
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
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   778
                    printStr = remainingStr.substring(0, posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   779
                    remainingStr = remainingStr.substring(posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   780
                } //else just print
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   781
                else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   782
                    printStr = remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   783
                    remainingStr = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   784
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   785
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   786
                instructionsText.append(printStr + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   787
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   788
            }// while
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
        }// for
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   791
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   792
    }//printInstructions()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   793
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   794
    //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
   795
    public void displayMessage(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   796
        messageText.append(messageIn + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   797
        System.out.println(messageIn);
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
}// TestDialog  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   800