< prev index next >

test/jdk/java/awt/Clipboard/HTMLTransferTest/HTMLTransferTest.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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  */


  52             HTMLFlavors = new DataFlavor[] {
  53                 new DataFlavor("text/html; document=selection; Class=" + InputStream.class.getName() + "; charset=UTF-8"),
  54                 new DataFlavor("text/html; document=selection; Class=" + String.class.getName() + "; charset=UTF-8")
  55             };
  56             SyncFlavor = new DataFlavor(
  57                 "application/x-java-serialized-object; class="
  58                 + SyncMessage.class.getName()
  59                 + "; charset=UTF-8"
  60             );
  61         }catch(Exception e){
  62             e.printStackTrace();
  63         }
  64     }
  65 
  66     private THTMLProducer imPr;
  67     private int returnCode = CODE_NOT_RETURNED;
  68 
  69     public void init() {
  70         initImpl();
  71 
  72         String[] instructions =
  73         {
  74             "This is an AUTOMATIC test",
  75             "simply wait until it is done"
  76         };
  77         Sysout.createDialog( );
  78         Sysout.printInstructions( instructions );
  79 
  80     } // init()
  81 
  82     private void initImpl() {
  83         imPr = new THTMLProducer();
  84         imPr.begin();
  85     }
  86 
  87 
  88     public void start() {
  89         try {
  90             String stFormats = "";
  91 
  92             String iniMsg = "Testing formats from the list:\n";
  93             for (int i = 0; i < HTMLTransferTest.HTMLFlavors.length; i++) {
  94                 stFormats += "\"" + HTMLTransferTest.HTMLFlavors[i].getMimeType() + "\"\n";
  95             }
  96             Sysout.println(iniMsg + stFormats);
  97             System.err.println("===>" + iniMsg + stFormats);
  98 
  99             String javaPath = System.getProperty("java.home", "");
 100             String cmd = javaPath + File.separator + "bin" + File.separator
 101                 + "java -cp " + System.getProperty("test.classes", ".") +
 102                 //+ "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 "
 103                 " THTMLConsumer"
 104                 //+ stFormats
 105                 ;
 106 
 107             Process process = Runtime.getRuntime().exec(cmd);
 108             ProcessResults pres = ProcessResults.doWaitFor(process);
 109             returnCode = pres.exitValue;
 110 
 111             if (pres.stderr != null && pres.stderr.length() > 0) {
 112                 System.err.println("========= Child VM System.err ========");
 113                 System.err.print(pres.stderr);
 114                 System.err.println("======================================");
 115             }
 116 


 632      * @param flavor the requested flavor for the data
 633      * @return the data in the requested flavor, as outlined above
 634      * @throws UnsupportedFlavorException if the requested data flavor is
 635      *         not equivalent to <code>HTMLTransferTest.HTMLFlavors</code>
 636      * @throws IOException if an IOException occurs while retrieving the data.
 637      *         By default, <code>HTMLSelection</code> never throws
 638      *         this exception, but a subclass may.
 639      * @throws NullPointerException if flavor is <code>null</code>
 640      */
 641     public Object getTransferData(DataFlavor flavor)
 642         throws UnsupportedFlavorException, IOException
 643     {
 644         if (flavor.equals(m_flavor)) {
 645             return (Object)m_data;
 646         } else {
 647             throw new UnsupportedFlavorException(flavor);
 648         }
 649     }
 650 
 651 } // class HTMLSelection
 652 
 653 
 654 /****************************************************
 655  Standard Test Machinery
 656  DO NOT modify anything below -- it's a standard
 657   chunk of code whose purpose is to make user
 658   interaction uniform, and thereby make it simpler
 659   to read and understand someone else's test.
 660  ****************************************************/
 661 class Sysout
 662  {
 663    private static TestDialog dialog;
 664 
 665    public static void createDialogWithInstructions( String[] instructions )
 666     {
 667       dialog = new TestDialog( new Frame(), "Instructions" );
 668       dialog.printInstructions( instructions );
 669       dialog.show();
 670       println( "Any messages for the tester will display here." );
 671     }
 672 
 673    public static void createDialog( )
 674     {
 675       dialog = new TestDialog( new Frame(), "Instructions" );
 676       String[] defInstr = { "Instructions will appear here. ", "" } ;
 677       dialog.printInstructions( defInstr );
 678       dialog.show();
 679       println( "Any messages for the tester will display here." );
 680     }
 681 
 682 
 683    public static void printInstructions( String[] instructions )
 684     {
 685       dialog.printInstructions( instructions );
 686     }
 687 
 688 
 689    public static void println( String messageIn )
 690     {
 691       dialog.displayMessage( messageIn );
 692     }
 693 
 694  }// Sysout  class
 695 
 696 class TestDialog extends Dialog
 697  {
 698 
 699    TextArea instructionsText;
 700    TextArea messageText;
 701    int maxStringLength = 80;
 702 
 703    //DO NOT call this directly, go through Sysout
 704    public TestDialog( Frame frame, String name )
 705     {
 706       super( frame, name );
 707       int scrollBoth = TextArea.SCROLLBARS_BOTH;
 708       instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
 709       add( "North", instructionsText );
 710 
 711       messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
 712       add("South", messageText);
 713 
 714       pack();
 715 
 716       show();
 717     }// TestDialog()
 718 
 719    //DO NOT call this directly, go through Sysout
 720    public void printInstructions( String[] instructions )
 721     {
 722       //Clear out any current instructions
 723       instructionsText.setText( "" );
 724 
 725       //Go down array of instruction strings
 726 
 727       String printStr, remainingStr;
 728       for( int i=0; i < instructions.length; i++ )
 729        {
 730          //chop up each into pieces maxSringLength long
 731          remainingStr = instructions[ i ];
 732          while( remainingStr.length() > 0 )
 733           {
 734             //if longer than max then chop off first max chars to print
 735             if( remainingStr.length() >= maxStringLength )
 736              {
 737                //Try to chop on a word boundary
 738                int posOfSpace = remainingStr.
 739                   lastIndexOf(' ', maxStringLength - 1);
 740 
 741                if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
 742 
 743                printStr = remainingStr.substring( 0, posOfSpace + 1 );
 744                remainingStr = remainingStr.substring( posOfSpace + 1 );
 745              }
 746             //else just print
 747             else
 748              {
 749                printStr = remainingStr;
 750                remainingStr = "";
 751              }
 752 
 753             instructionsText.append( printStr + "\n" );
 754 
 755           }// while
 756 
 757        }// for
 758 
 759     }//printInstructions()
 760 
 761    //DO NOT call this directly, go through Sysout
 762    public void displayMessage( String messageIn )
 763     {
 764       messageText.append( messageIn + "\n" );
 765     }
 766 
 767  }// TestDialog  class
   1 /*
   2  * Copyright (c) 2015, 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  */


  52             HTMLFlavors = new DataFlavor[] {
  53                 new DataFlavor("text/html; document=selection; Class=" + InputStream.class.getName() + "; charset=UTF-8"),
  54                 new DataFlavor("text/html; document=selection; Class=" + String.class.getName() + "; charset=UTF-8")
  55             };
  56             SyncFlavor = new DataFlavor(
  57                 "application/x-java-serialized-object; class="
  58                 + SyncMessage.class.getName()
  59                 + "; charset=UTF-8"
  60             );
  61         }catch(Exception e){
  62             e.printStackTrace();
  63         }
  64     }
  65 
  66     private THTMLProducer imPr;
  67     private int returnCode = CODE_NOT_RETURNED;
  68 
  69     public void init() {
  70         initImpl();
  71 








  72     } // init()
  73 
  74     private void initImpl() {
  75         imPr = new THTMLProducer();
  76         imPr.begin();
  77     }
  78 
  79 
  80     public void start() {
  81         try {
  82             String stFormats = "";
  83 
  84             String iniMsg = "Testing formats from the list:\n";
  85             for (int i = 0; i < HTMLTransferTest.HTMLFlavors.length; i++) {
  86                 stFormats += "\"" + HTMLTransferTest.HTMLFlavors[i].getMimeType() + "\"\n";
  87             }
  88             System.out.println(iniMsg + stFormats);
  89             System.err.println("===>" + iniMsg + stFormats);
  90 
  91             String javaPath = System.getProperty("java.home", "");
  92             String cmd = javaPath + File.separator + "bin" + File.separator
  93                 + "java -cp " + System.getProperty("test.classes", ".") +
  94                 //+ "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 "
  95                 " THTMLConsumer"
  96                 //+ stFormats
  97                 ;
  98 
  99             Process process = Runtime.getRuntime().exec(cmd);
 100             ProcessResults pres = ProcessResults.doWaitFor(process);
 101             returnCode = pres.exitValue;
 102 
 103             if (pres.stderr != null && pres.stderr.length() > 0) {
 104                 System.err.println("========= Child VM System.err ========");
 105                 System.err.print(pres.stderr);
 106                 System.err.println("======================================");
 107             }
 108 


 624      * @param flavor the requested flavor for the data
 625      * @return the data in the requested flavor, as outlined above
 626      * @throws UnsupportedFlavorException if the requested data flavor is
 627      *         not equivalent to <code>HTMLTransferTest.HTMLFlavors</code>
 628      * @throws IOException if an IOException occurs while retrieving the data.
 629      *         By default, <code>HTMLSelection</code> never throws
 630      *         this exception, but a subclass may.
 631      * @throws NullPointerException if flavor is <code>null</code>
 632      */
 633     public Object getTransferData(DataFlavor flavor)
 634         throws UnsupportedFlavorException, IOException
 635     {
 636         if (flavor.equals(m_flavor)) {
 637             return (Object)m_data;
 638         } else {
 639             throw new UnsupportedFlavorException(flavor);
 640         }
 641     }
 642 
 643 } // class HTMLSelection




















































































































< prev index next >