< prev index next >

test/jdk/java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 417             fail(ex.getMessage());
 418         }
 419     }
 420 
 421     /*****************************************************
 422      * Standard Test Machinery Section
 423      * DO NOT modify anything in this section -- it's a
 424      * standard chunk of code which has all of the
 425      * synchronisation necessary for the test harness.
 426      * By keeping it the same in all tests, it is easier
 427      * to read and understand someone else's test, as
 428      * well as insuring that all tests behave correctly
 429      * with the test harness.
 430      * There is a section following this for test-
 431      * classes
 432      ******************************************************/
 433     private static void init() throws InterruptedException {
 434         //*** Create instructions for the user here ***
 435         //System.setProperty("sun.awt.disableMixing", "true");
 436 
 437         String[] instructions = {
 438             "This is an AUTOMATIC test, simply wait until it is done.",
 439             "The result (passed or failed) will be shown in the",
 440             "message window below."
 441         };
 442         Sysout.createDialog();
 443         Sysout.printInstructions(instructions);
 444 
 445         HierarchyBoundsListenerMixingTest instance = new HierarchyBoundsListenerMixingTest();
 446 
 447         instance.invoke();
 448 
 449         pass();
 450     }//End  init()
 451     private static boolean theTestPassed = false;
 452     private static boolean testGeneratedInterrupt = false;
 453     private static String failureMessage = "";
 454     private static Thread mainThread = null;
 455     private static int sleepTime = 300000;
 456 
 457     // Not sure about what happens if multiple of this test are
 458     //  instantiated in the same VM.  Being static (and using
 459     //  static vars), it aint gonna work.  Not worrying about
 460     //  it for now.
 461     public static void main(String args[]) throws InterruptedException {
 462         mainThread = Thread.currentThread();
 463         try {
 464             init();


 482             // so that the harness gets it and deals with it.
 483             if (!testGeneratedInterrupt) {
 484                 throw e;
 485             }
 486 
 487             //reset flag in case hit this code more than once for some reason (just safety)
 488             testGeneratedInterrupt = false;
 489 
 490             if (theTestPassed == false) {
 491                 throw new RuntimeException(failureMessage);
 492             }
 493         }
 494 
 495     }//main
 496 
 497     public static synchronized void setTimeoutTo(int seconds) {
 498         sleepTime = seconds * 1000;
 499     }
 500 
 501     public static synchronized void pass() {
 502         Sysout.println("The test passed.");
 503         Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
 504         //first check if this is executing in main thread
 505         if (mainThread == Thread.currentThread()) {
 506             //Still in the main thread, so set the flag just for kicks,
 507             // and throw a test passed exception which will be caught
 508             // and end the test.
 509             theTestPassed = true;
 510             throw new TestPassedException();
 511         }
 512         theTestPassed = true;
 513         testGeneratedInterrupt = true;
 514         mainThread.interrupt();
 515     }//pass()
 516 
 517     public static synchronized void fail() {
 518         //test writer didn't specify why test failed, so give generic
 519         fail("it just plain failed! :-)");
 520     }
 521 
 522     public static synchronized void fail(String whyFailed) {
 523         Sysout.println("The test failed: " + whyFailed);
 524         Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
 525         //check if this called from main thread
 526         if (mainThread == Thread.currentThread()) {
 527             //If main thread, fail now 'cause not sleeping
 528             throw new RuntimeException(whyFailed);
 529         }
 530         theTestPassed = false;
 531         testGeneratedInterrupt = true;
 532         failureMessage = whyFailed;
 533         mainThread.interrupt();
 534     }//fail()
 535 }// class LWComboBox
 536 class TestPassedException extends RuntimeException {
 537 }
 538 
 539 //*********** End Standard Test Machinery Section **********
 540 //************ Begin classes defined for the test ****************
 541 // if want to make listeners, here is the recommended place for them, then instantiate
 542 //  them in init()
 543 
 544 /* Example of a class which may be written as part of a test
 545 class NewClass implements anInterface
 546 {
 547 static int newVar = 0;
 548 
 549 public void eventDispatched(AWTEvent e)
 550 {
 551 //Counting events to see if we get enough
 552 eventCount++;
 553 
 554 if( eventCount == 20 )
 555 {
 556 //got enough events, so pass
 557 
 558 LWComboBox.pass();
 559 }
 560 else if( tries == 20 )
 561 {
 562 //tried too many times without getting enough events so fail
 563 
 564 LWComboBox.fail();
 565 }
 566 
 567 }// eventDispatched()
 568 
 569 }// NewClass class
 570 
 571  */
 572 //************** End classes defined for the test *******************
 573 /****************************************************
 574 Standard Test Machinery
 575 DO NOT modify anything below -- it's a standard
 576 chunk of code whose purpose is to make user
 577 interaction uniform, and thereby make it simpler
 578 to read and understand someone else's test.
 579  ****************************************************/
 580 /**
 581 This is part of the standard test machinery.
 582 It creates a dialog (with the instructions), and is the interface
 583 for sending text messages to the user.
 584 To print the instructions, send an array of strings to Sysout.createDialog
 585 WithInstructions method.  Put one line of instructions per array entry.
 586 To display a message for the tester to see, simply call Sysout.println
 587 with the string to be displayed.
 588 This mimics System.out.println but works within the test harness as well
 589 as standalone.
 590  */
 591 class Sysout {
 592 
 593     private static TestDialog dialog;
 594 
 595     public static void createDialogWithInstructions(String[] instructions) {
 596         dialog = new TestDialog(new Frame(), "Instructions");
 597         dialog.printInstructions(instructions);
 598         //dialog.setVisible(true);
 599         println("Any messages for the tester will display here.");
 600     }
 601 
 602     public static void createDialog() {
 603         dialog = new TestDialog(new Frame(), "Instructions");
 604         String[] defInstr = {"Instructions will appear here. ", ""};
 605         dialog.printInstructions(defInstr);
 606         //dialog.setVisible(true);
 607         println("Any messages for the tester will display here.");
 608     }
 609 
 610     public static void printInstructions(String[] instructions) {
 611         dialog.printInstructions(instructions);
 612     }
 613 
 614     public static void println(String messageIn) {
 615         dialog.displayMessage(messageIn);
 616         System.out.println(messageIn);
 617     }
 618 }// Sysout  class
 619 
 620 /**
 621 This is part of the standard test machinery.  It provides a place for the
 622 test instructions to be displayed, and a place for interactive messages
 623 to the user to be displayed.
 624 To have the test instructions displayed, see Sysout.
 625 To have a message to the user be displayed, see Sysout.
 626 Do not call anything in this dialog directly.
 627  */
 628 class TestDialog extends Dialog {
 629 
 630     TextArea instructionsText;
 631     TextArea messageText;
 632     int maxStringLength = 80;
 633 
 634     //DO NOT call this directly, go through Sysout
 635     public TestDialog(Frame frame, String name) {
 636         super(frame, name);
 637         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 638         instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
 639         add("North", instructionsText);
 640 
 641         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 642         add("Center", messageText);
 643 
 644         pack();
 645 
 646         //setVisible(true);
 647     }// TestDialog()
 648 
 649     //DO NOT call this directly, go through Sysout
 650     public void printInstructions(String[] instructions) {
 651         //Clear out any current instructions
 652         instructionsText.setText("");
 653 
 654         //Go down array of instruction strings
 655 
 656         String printStr, remainingStr;
 657         for (int i = 0; i < instructions.length; i++) {
 658             //chop up each into pieces maxSringLength long
 659             remainingStr = instructions[i];
 660             while (remainingStr.length() > 0) {
 661                 //if longer than max then chop off first max chars to print
 662                 if (remainingStr.length() >= maxStringLength) {
 663                     //Try to chop on a word boundary
 664                     int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
 665 
 666                     if (posOfSpace <= 0) {
 667                         posOfSpace = maxStringLength - 1;
 668                     }
 669 
 670                     printStr = remainingStr.substring(0, posOfSpace + 1);
 671                     remainingStr = remainingStr.substring(posOfSpace + 1);
 672                 } //else just print
 673                 else {
 674                     printStr = remainingStr;
 675                     remainingStr = "";
 676                 }
 677 
 678                 instructionsText.append(printStr + "\n");
 679 
 680             }// while
 681 
 682         }// for
 683 
 684     }//printInstructions()
 685 
 686     //DO NOT call this directly, go through Sysout
 687     public void displayMessage(String messageIn) {
 688         messageText.append(messageIn + "\n");
 689         System.out.println(messageIn);
 690     }
 691 }// TestDialog  class
 692 
   1 /*
   2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 417             fail(ex.getMessage());
 418         }
 419     }
 420 
 421     /*****************************************************
 422      * Standard Test Machinery Section
 423      * DO NOT modify anything in this section -- it's a
 424      * standard chunk of code which has all of the
 425      * synchronisation necessary for the test harness.
 426      * By keeping it the same in all tests, it is easier
 427      * to read and understand someone else's test, as
 428      * well as insuring that all tests behave correctly
 429      * with the test harness.
 430      * There is a section following this for test-
 431      * classes
 432      ******************************************************/
 433     private static void init() throws InterruptedException {
 434         //*** Create instructions for the user here ***
 435         //System.setProperty("sun.awt.disableMixing", "true");
 436 








 437         HierarchyBoundsListenerMixingTest instance = new HierarchyBoundsListenerMixingTest();
 438 
 439         instance.invoke();
 440 
 441         pass();
 442     }//End  init()
 443     private static boolean theTestPassed = false;
 444     private static boolean testGeneratedInterrupt = false;
 445     private static String failureMessage = "";
 446     private static Thread mainThread = null;
 447     private static int sleepTime = 300000;
 448 
 449     // Not sure about what happens if multiple of this test are
 450     //  instantiated in the same VM.  Being static (and using
 451     //  static vars), it aint gonna work.  Not worrying about
 452     //  it for now.
 453     public static void main(String args[]) throws InterruptedException {
 454         mainThread = Thread.currentThread();
 455         try {
 456             init();


 474             // so that the harness gets it and deals with it.
 475             if (!testGeneratedInterrupt) {
 476                 throw e;
 477             }
 478 
 479             //reset flag in case hit this code more than once for some reason (just safety)
 480             testGeneratedInterrupt = false;
 481 
 482             if (theTestPassed == false) {
 483                 throw new RuntimeException(failureMessage);
 484             }
 485         }
 486 
 487     }//main
 488 
 489     public static synchronized void setTimeoutTo(int seconds) {
 490         sleepTime = seconds * 1000;
 491     }
 492 
 493     public static synchronized void pass() {
 494         System.out.println("The test passed.");
 495         System.out.println("The test is over, hit  Ctl-C to stop Java VM");
 496         //first check if this is executing in main thread
 497         if (mainThread == Thread.currentThread()) {
 498             //Still in the main thread, so set the flag just for kicks,
 499             // and throw a test passed exception which will be caught
 500             // and end the test.
 501             theTestPassed = true;
 502             throw new TestPassedException();
 503         }
 504         theTestPassed = true;
 505         testGeneratedInterrupt = true;
 506         mainThread.interrupt();
 507     }//pass()
 508 
 509     public static synchronized void fail() {
 510         //test writer didn't specify why test failed, so give generic
 511         fail("it just plain failed! :-)");
 512     }
 513 
 514     public static synchronized void fail(String whyFailed) {
 515         System.out.println("The test failed: " + whyFailed);
 516         System.out.println("The test is over, hit  Ctl-C to stop Java VM");
 517         //check if this called from main thread
 518         if (mainThread == Thread.currentThread()) {
 519             //If main thread, fail now 'cause not sleeping
 520             throw new RuntimeException(whyFailed);
 521         }
 522         theTestPassed = false;
 523         testGeneratedInterrupt = true;
 524         failureMessage = whyFailed;
 525         mainThread.interrupt();
 526     }//fail()
 527 }// class LWComboBox
 528 class TestPassedException extends RuntimeException {
 529 }



























































































































































< prev index next >