File: OverlappingTestBase.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (670 lines) | stat: -rw-r--r-- 27,520 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/*
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import java.awt.*;
import java.awt.event.*;
import java.awt.peer.ComponentPeer;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javax.swing.*;

import sun.awt.AWTAccessor;
import sun.awt.EmbeddedFrame;
import java.io.*;
import test.java.awt.regtesthelpers.Util;

/**
 * <p>This class provides basis for AWT Mixing testing.
 * <p>It provides all standard test machinery and should be used by
 * extending and overriding next methods:
 * <li> {@link OverlappingTestBase#prepareControls()} - setup UI components
 * <li> {@link OverlappingTestBase#performTest()} -  run particular test
 * Those methods would be run in the loop for each AWT component.
 * <p>Current AWT component should be added to the tested UI by {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) ()}.
 * There AWT components are prepared to be tested as being overlayed by other (e.g. Swing) components - they are colored to
 * {@link OverlappingTestBase#AWT_BACKGROUND_COLOR} and throws failure on catching mouse event.
 * <p> Validation of component being overlayed should be tested by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
 * See each method javadoc for more details.
 *
 * <p>Due to test machinery limitations all test should be run from their own main() by calling next coe
 * <code>
 *     public static void main(String args[]) throws InterruptedException {
 *        instance = new YourTestInstance();
 *        OverlappingTestBase.doMain(args);
 *     }
 * </code>
 *
 * @author Sergey Grinev
 */
public abstract class OverlappingTestBase {
    // working variables
    private static volatile boolean wasHWClicked = false;
    private static volatile boolean passed = true;
    // constants
    /**
     * Default color for AWT component used for validate correct drawing of overlapping. <b>Never</b> use it for lightweight components.
     */
    protected static final Color AWT_BACKGROUND_COLOR = new Color(21, 244, 54);
    protected static Color AWT_VERIFY_COLOR = AWT_BACKGROUND_COLOR;
    protected static final int ROBOT_DELAY = 500;
    private static final String[] simpleAwtControls = {"Button", "Checkbox", "Label", "TextArea"};
    /**
     * Generic strings array. To be used for population of List based controls.
     */
    protected static final String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Rhynocephalia Granda", "Bear", "Tiger", "Mustang"};
    // "properties"
    /**
     * Tests customization. Set this variable to test only control from java.awt
     * <p>Usage of this variable should be marked with CR being the reason.
     * <p>Do not use this variable simultaneously with {@link OverlappingTestBase#skipClassNames}
     */
    protected String onlyClassName = null;
    /**
     * For customizing tests. List classes' simple names to skip them from testings.
     * <p>Usage of this variable should be marked with CR being the reason.
     */
    protected String[] skipClassNames = null;
    /**
     * Set to false to avoid event delivery validation
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
     */
    protected boolean useClickValidation = true;
    /**
     * Set to false if test doesn't supposed to verify EmbeddedFrame
     */
    protected boolean testEmbeddedFrame = false;
    /**
     * Set this variable to true if testing embedded frame is impossible (on Mac, for instance, for now).
     * The testEmbeddedFrame is explicitly set to true in dozen places.
     */
    protected boolean skipTestingEmbeddedFrame = false;

    public static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("os x");
    private boolean isFrameBorderCalculated;
    private int borderShift;

    {    if (Toolkit.getDefaultToolkit().getClass().getName().matches(".*L.*Toolkit")) {
             // No EmbeddedFrame in LWToolkit/LWCToolkit, yet
             // And it should be programmed some other way, too, in any case
             //System.err.println("skipTestingEmbeddedFrame");
             //skipTestingEmbeddedFrame = true;
         }else {
             System.err.println("do not skipTestingEmbeddedFrame");
         }
    }

    protected int frameBorderCounter() {
        if (!isFrameBorderCalculated) {
            try {
                new FrameBorderCounter(); // force compilation by jtreg
                String JAVA_HOME = System.getProperty("java.home");
                Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
                try {
                    p.waitFor();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
                if (p.exitValue() != 0) {
                    throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream()));
                }
                borderShift = Integer.parseInt(readInputStream(p.getInputStream()).trim());
                isFrameBorderCalculated = true;
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException("Problem calculating a native border size");
            }
        }
        return borderShift;
    }

    public void getVerifyColor() {
        try {
            final int size = 200;
            final Point[] p = new Point[1];
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run(){
                    JFrame frame = new JFrame("set back");
                    frame.getContentPane().setBackground(AWT_BACKGROUND_COLOR);
                    frame.setSize(size, size);
                    frame.setUndecorated(true);
                    frame.setVisible(true);
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                    p[0] = frame.getLocation();
                }
            });
            Robot robot = new Robot();
            robot.waitForIdle();
            Thread.sleep(ROBOT_DELAY);
            AWT_VERIFY_COLOR = robot.getPixelColor(p[0].x+size/2, p[0].y+size/2);
            System.out.println("Color will be compared with " + AWT_VERIFY_COLOR + " instead of " + AWT_BACKGROUND_COLOR);
        } catch (Exception e) {
            System.err.println("Cannot get verify color: "+e.getMessage());
        }
    }

    private String readInputStream(InputStream is) throws IOException {
        byte[] buffer = new byte[4096];
        int len = 0;
        StringBuilder sb = new StringBuilder();
        try (InputStreamReader isr = new InputStreamReader(is)) {
            while ((len = is.read(buffer)) > 0) {
                sb.append(new String(buffer, 0, len));
            }
        }
        return sb.toString();
    }

    private void setupControl(final Component control) {
        if (useClickValidation) {
            control.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    System.err.println("ERROR: " + control.getClass() + " received mouse click.");
                    wasHWClicked = true;
                }
            });
        }
        control.setBackground(AWT_BACKGROUND_COLOR);
        control.setForeground(AWT_BACKGROUND_COLOR);
        control.setPreferredSize(new Dimension(150, 150));
        control.setFocusable(false);
    }

    private void addAwtControl(java.util.List<Component> container, final Component control) {
        String simpleName = control.getClass().getSimpleName();
        if (onlyClassName != null && !simpleName.equals(onlyClassName)) {
            return;
        }
        if (skipClassNames != null) {
            for (String skipMe : skipClassNames) {
                if (simpleName.equals(skipMe)) {
                    return;
                }
            }
        }
        setupControl(control);
        container.add(control);
    }

    private void addSimpleAwtControl(java.util.List<Component> container, String className) {
        try {
            Class definition = Class.forName("java.awt." + className);
            Constructor constructor = definition.getConstructor(new Class[]{String.class});
            java.awt.Component component = (java.awt.Component) constructor.newInstance(new Object[]{"AWT Component " + className});
            addAwtControl(container, component);
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
            fail("Setup error, this jdk doesn't have awt conrol " + className);
        }
    }

    /**
     * Adds current AWT control to container
     * <p>N.B.: if testEmbeddedFrame == true this method will also add EmbeddedFrame over Canvas
     * and it should be called <b>after</b> Frame.setVisible(true) call
     * @param container container to hold AWT component
     */
    protected final void propagateAWTControls(Container container) {
        if (currentAwtControl != null) {
            container.add(currentAwtControl);
        } else { // embedded frame
            try {

                //create embedder
                Canvas embedder = new Canvas();
                embedder.setBackground(Color.RED);
                embedder.setPreferredSize(new Dimension(150, 150));
                container.add(embedder);
                container.setVisible(true); // create peer

                long frameWindow = 0;
                String getWindowMethodName = null;
                String eframeClassName = null;
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
                    java.awt.Helper.addExports("sun.awt.X11", OverlappingTestBase.class.getModule());
                    getWindowMethodName = "getWindow";
                    eframeClassName = "sun.awt.X11.XEmbeddedFrame";
                }else if (Toolkit.getDefaultToolkit().getClass().getName().contains(".WToolkit")) {
                    java.awt.Helper.addExports("sun.awt.windows", OverlappingTestBase.class.getModule());
                    getWindowMethodName = "getHWnd";
                    eframeClassName = "sun.awt.windows.WEmbeddedFrame";
                }else if (isMac) {
                    java.awt.Helper.addExports("sun.lwawt", OverlappingTestBase.class.getModule());
                    java.awt.Helper.addExports("sun.lwawt.macosx", OverlappingTestBase.class.getModule());
                    eframeClassName = "sun.lwawt.macosx.CViewEmbeddedFrame";
                }

                ComponentPeer peer = AWTAccessor.getComponentAccessor()
                                                .getPeer(embedder);
                if (!isMac) {
                    Method getWindowMethod = peer.getClass().getMethod(getWindowMethodName);
                    frameWindow = (Long) getWindowMethod.invoke(peer);
                } else {
                    Method m_getPlatformWindowMethod = peer.getClass().getMethod("getPlatformWindow");
                    Object platformWindow = m_getPlatformWindowMethod.invoke(peer);
                    Class classPlatformWindow = Class.forName("sun.lwawt.macosx.CPlatformWindow");

                    Method m_getContentView = classPlatformWindow.getMethod("getContentView");
                    Object contentView = m_getContentView.invoke(platformWindow);
                    Class classContentView = Class.forName("sun.lwawt.macosx.CPlatformView");

                    Method m_getAWTView = classContentView.getMethod("getAWTView");
                    frameWindow = (Long) m_getAWTView.invoke(contentView);
                }

                Class eframeClass = Class.forName(eframeClassName);
                Constructor eframeCtor = eframeClass.getConstructor(long.class);
                EmbeddedFrame eframe = (EmbeddedFrame) eframeCtor.newInstance(frameWindow);
                setupControl(eframe);
                eframe.setSize(new Dimension(150, 150));
                eframe.setVisible(true);
//                System.err.println(eframe.getSize());
            } catch (Exception ex) {
                ex.printStackTrace();
                fail("Failed to instantiate EmbeddedFrame: " + ex.getMessage());
            }
        }
    }
    private static final Font hugeFont = new Font("Arial", Font.BOLD, 70);

    private java.util.List<Component> getAWTControls() {
        java.util.List<Component> components = new ArrayList<Component>();

        for (String clazz : simpleAwtControls) {
            addSimpleAwtControl(components, clazz);
        }

        TextField tf = new TextField();
        tf.setFont(hugeFont);
        addAwtControl(components, tf);

        // more complex controls
        Choice c = new Choice();
        for (int i = 0; i < petStrings.length; i++) {
            c.add(petStrings[i]);
        }
        addAwtControl(components, c);
        c.setPreferredSize(null);
        c.setFont(hugeFont); // to make control bigger as setPrefferedSize don't do his job here

        List l = new List(petStrings.length);
        for (int i = 0; i < petStrings.length; i++) {
            l.add(petStrings[i]);
        }
        addAwtControl(components, l);

        Canvas canvas = new Canvas();
        canvas.setSize(100, 200);
        addAwtControl(components, canvas);

        Scrollbar sb = new Scrollbar(Scrollbar.VERTICAL, 500, 1, 0, 500);
        addAwtControl(components, sb);

        Scrollbar sb2 = new Scrollbar(Scrollbar.HORIZONTAL, 500, 1, 0, 500);
        addAwtControl(components, sb2);

        return components;
    }
    /**
     * Default shift for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
     */
    protected static Point shift = new Point(16, 16);

    /**
     * Verifies point using specified AWT Robot. Supposes <code>defaultShift == true</code> for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) }.
     * This method is used to verify controls by providing just their plain screen coordinates.
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
     * @param lLoc point to verify
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
     */
    protected void clickAndBlink(Robot robot, Point lLoc) {
        clickAndBlink(robot, lLoc, true);
    }
    /**
     * Default failure message for color check
     * @see OverlappingTestBase#performTest()
     */
    protected String failMessageColorCheck = "The LW component did not pass pixel color check and is overlapped";
    /**
     * Default failure message event check
     * @see OverlappingTestBase#performTest()
     */
    protected String failMessage = "The LW component did not received the click.";

    private static boolean isValidForPixelCheck(Component component) {
        if ((component instanceof java.awt.Scrollbar) || isMac && (component instanceof java.awt.Button)) {
            return false;
        }
        return true;
    }

    /**
     * Preliminary validation - should be run <b>before</b> overlapping happens to ensure test is correct.
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
     * @param lLoc point to validate to be <b>of</b> {@link OverlappingTestBase#AWT_BACKGROUND_COLOR}
     * @param component tested component, should be pointed out as not all components are valid for pixel check.
     */
    protected void pixelPreCheck(Robot robot, Point lLoc, Component component) {
        if (isValidForPixelCheck(component)) {
            int tries = 10;
            Color c = null;
            while (tries-- > 0) {
                c = robot.getPixelColor(lLoc.x, lLoc.y);
                System.out.println("Precheck. color: "+c+" compare with "+AWT_VERIFY_COLOR);
                if (c.equals(AWT_VERIFY_COLOR)) {
                    return;
                }
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            System.err.println(lLoc + ": " + c);
            fail("Dropdown test setup failure, colored part of AWT component is not located at click area");
        }
    }

    /**
     * Verifies point using specified AWT Robot.
     * <p>Firstly, verifies point by color pixel check
     * <p>Secondly, verifies event delivery by mouse click
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
     * @param lLoc point to verify
     * @param defaultShift if true verified position will be shifted by {@link OverlappingTestBase#shift }.
     */
    protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) {
        Point loc = lLoc.getLocation();
        //check color
        Util.waitForIdle(robot);
        try{
            Thread.sleep(500);
        }catch(Exception exx){
            exx.printStackTrace();
        }

        if (defaultShift) {
            loc.translate(shift.x, shift.y);
        }
        if (!(System.getProperty("os.name").toLowerCase().contains("os x"))) {
            Color c = robot.getPixelColor(loc.x, loc.y);
            System.out.println("C&B. color: "+c+" compare with "+AWT_VERIFY_COLOR);
            if (c.equals(AWT_VERIFY_COLOR)) {
                fail(failMessageColorCheck);
                passed = false;
            }

            // perform click
            Util.waitForIdle(robot);
        }

        robot.mouseMove(loc.x, loc.y);

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Util.waitForIdle(robot);
    }

    /**
     * This method should be overriden with code which setups UI for testing.
     * Code in this method <b>will</b> be called only from AWT thread so Swing operations can be called directly.
     *
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
     */
    protected abstract void prepareControls();

    /**
     * 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.
     * @return true if test passed. Otherwise fail with default fail message.
     * @see {@link OverlappingTestBase#failMessage} default fail message
     */
    protected abstract boolean performTest();
    /**
     * This method can be overriden with cleanup routines. It will be called from AWT thread so all Swing operations should be treated accordingly.
     */
    protected void cleanup() {
        // intentionally do nothing
    }
    /**
     * Currect tested AWT Control. Usually shouldn't be accessed directly.
     *
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
     */
    protected Component currentAwtControl;

    private void testComponent(Component component) throws InterruptedException, InvocationTargetException {
        Robot robot = null;
        try {
            robot = new Robot();
        }catch(Exception ignorex) {
        }
        currentAwtControl = component;
        System.out.println("Testing " + currentAwtControl.getClass().getSimpleName());
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                prepareControls();
            }
        });
        if (component != null) {
            Util.waitTillShown(component);
        }
        Util.waitForIdle(robot);
        try {
            Thread.sleep(500); // wait for graphic effects on systems like Win7
        } catch (InterruptedException ex) {
        }
        if (!instance.performTest()) {
            fail(failMessage);
            passed = false;
        }
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                cleanup();
            }
        });
    }

    private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException {
        Robot robot = null;
        try {
            robot = new Robot();
        }catch(Exception ignorex) {
        }
        System.out.println("Testing EmbeddedFrame");
        currentAwtControl = null;
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                prepareControls();
            }
        });
        Util.waitForIdle(robot);
        try {
            Thread.sleep(500); // wait for graphic effects on systems like Win7
        } catch (InterruptedException ex) {
        }
        if (!instance.performTest()) {
            fail(failMessage);
            passed = false;
        }
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                cleanup();
            }
        });
    }

    private void testAwtControls() throws InterruptedException {
        try {
            for (Component component : getAWTControls()) {
                testComponent(component);
            }
            if (testEmbeddedFrame && !skipTestingEmbeddedFrame) {
                testEmbeddedFrame();
            }
        } catch (InvocationTargetException ex) {
            ex.printStackTrace();
            fail(ex.getMessage());
        }
    }
    /**
     * Used by standard test machinery. See usage at {@link OverlappingTestBase }
     */
    protected static OverlappingTestBase instance;

    protected OverlappingTestBase() {
        getVerifyColor();
    }

    /*****************************************************
     * Standard Test Machinery Section
     * DO NOT modify anything in this section -- it's a
     * standard chunk of code which has all of the
     * synchronisation necessary for the test harness.
     * By keeping it the same in all tests, it is easier
     * to read and understand someone else's test, as
     * well as insuring that all tests behave correctly
     * with the test harness.
     * There is a section following this for test-
     * classes
     ******************************************************/
    private static void init() throws InterruptedException {
        //System.setProperty("sun.awt.disableMixing", "true");

        instance.testAwtControls();

        if (wasHWClicked) {
            fail("HW component received the click.");
            passed = false;
        }
        if (passed) {
            pass();
        }
    }//End  init()
    private static boolean theTestPassed = false;
    private static boolean testGeneratedInterrupt = false;
    private static String failureMessage = "";
    private static Thread mainThread = null;
    private static int sleepTime = 300000;

    // Not sure about what happens if multiple of this test are
    //  instantiated in the same VM.  Being static (and using
    //  static vars), it aint gonna work.  Not worrying about
    //  it for now.
    /**
     * Starting point for test runs. See usage at {@link OverlappingTestBase }
     * @param args regular main args, not used.
     * @throws InterruptedException
     */
    public static void doMain(String args[]) throws InterruptedException {
        mainThread = Thread.currentThread();
        try {
            init();
        } catch (TestPassedException e) {
            //The test passed, so just return from main and harness will
            // interepret this return as a pass
            return;
        }
        //At this point, neither test pass nor test fail has been
        // called -- either would have thrown an exception and ended the
        // test, so we know we have multiple threads.

        //Test involves other threads, so sleep and wait for them to
        // called pass() or fail()
        try {
            Thread.sleep(sleepTime);
            //Timed out, so fail the test
            throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds");
        } catch (InterruptedException e) {
            //The test harness may have interrupted the test.  If so, rethrow the exception
            // so that the harness gets it and deals with it.
            if (!testGeneratedInterrupt) {
                throw e;
            }

            //reset flag in case hit this code more than once for some reason (just safety)
            testGeneratedInterrupt = false;

            if (theTestPassed == false) {
                throw new RuntimeException(failureMessage);
            }
        }

    }//main

    /**
     * Test will fail if not passed after this timeout. Default timeout is 300 seconds.
     * @param seconds timeout in seconds
     */
    public static synchronized void setTimeoutTo(int seconds) {
        sleepTime = seconds * 1000;
    }

    /**
     * Set test as passed. Usually shoudn't be called directly.
     */
    public static synchronized void pass() {
        System.out.println("The test passed.");
        System.out.println("The test is over, hit  Ctl-C to stop Java VM");
        //first check if this is executing in main thread
        if (mainThread == Thread.currentThread()) {
            //Still in the main thread, so set the flag just for kicks,
            // and throw a test passed exception which will be caught
            // and end the test.
            theTestPassed = true;
            throw new TestPassedException();
        }
        theTestPassed = true;
        testGeneratedInterrupt = true;
        mainThread.interrupt();
    }//pass()

    /**
     * Fail test generic message.
     */
    public static synchronized void fail() {
        //test writer didn't specify why test failed, so give generic
        fail("it just plain failed! :-)");
    }

    /**
     * Fail test providing specific reason.
     * @param whyFailed reason
     */
    public static synchronized void fail(String whyFailed) {
        System.out.println("The test failed: " + whyFailed);
        System.out.println("The test is over, hit  Ctl-C to stop Java VM");
        //check if this called from main thread
        if (mainThread == Thread.currentThread()) {
            //If main thread, fail now 'cause not sleeping
            throw new RuntimeException(whyFailed);
        }
        theTestPassed = false;
        testGeneratedInterrupt = true;
        failureMessage = whyFailed;
        mainThread.interrupt();
    }//fail()
}// class LWComboBox
class TestPassedException extends RuntimeException {
}