Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/PrintJob/PrintCheckboxTest/PrintCheckboxManualTest.java
38828 views
/*1* Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 5045936 505517126@summary Tests that there is no ClassCastException thrown in printing27checkbox and scrollbar with XAWT28@author [email protected]29@run applet/manual=yesno PrintCheckboxManualTest.html30*/3132// Note there is no @ in front of test above. This is so that the33// harness will not mistake this file as a test file. It should34// only see the html file as a test file. (the harness runs all35// valid test files, so it would run this test twice if this file36// were valid as well as the html file.)37// Also, note the area= after Your Name in the author tag. Here, you38// should put which functional area the test falls in. See the39// AWT-core home page -> test areas and/or -> AWT team for a list of40// areas.41424344import java.awt.*;45import java.awt.event.*;464748//Manual tests should run as applet tests if possible because they49// get their environments cleaned up, including AWT threads, any50// test created threads, and any system resources used by the test51// such as file descriptors. (This is normally not a problem as52// main tests usually run in a separate VM, however on some platforms53// such as the Mac, separate VMs are not possible and non-applet54// tests will cause problems). Also, you don't have to worry about55// synchronisation stuff in Applet tests the way you do in main56// tests...575859public class PrintCheckboxManualTest extends Panel60{61//Declare things used in the test, like buttons and labels here62Frame f;6364public static void main(String[] args) {65PrintCheckboxManualTest a = new PrintCheckboxManualTest();6667a.init();68a.start();69}7071public void init()72{73//Create instructions for the user here, as well as set up74// the environment -- set the layout manager, add buttons,75// etc.76this.setLayout (new BorderLayout ());7778String[] instructions =79{80"Linux or Solaris with XToolkit ONLY!",81"1. Click the 'Print' button on the frame",82"2. Select a printer in the print dialog and proceed",83"3. If the frame with checkbox and button on it is printed successfully test PASSED else FAILED"84};85Sysout.createDialogWithInstructions( instructions );8687}//End init()8889public void start ()90{91//Get things going. Request focus, set size, et cetera92setSize (200,200);93setVisible(true);94validate();9596//What would normally go into main() will probably go here.97//Use System.out.println for diagnostic messages that you want98// to read after the test is done.99//Use Sysout.println for messages you want the tester to read.100101f = new Frame("Print checkbox");102f.setLayout(new GridLayout(2, 2));103f.setSize(200, 100);104105Checkbox ch = new Checkbox("123");106ch.setState(true);107f.add(ch);108109Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL);110f.add(sb);111112Button b = new Button("Print");113b.addActionListener(new ActionListener()114{115public void actionPerformed(ActionEvent ev)116{117PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(f, "PrintCheckboxManualTest", null);118if (pj != null)119{120try121{122Graphics g = pj.getGraphics();123f.printAll(g);124g.dispose();125pj.end();126Sysout.println("Test PASSED");127}128catch (ClassCastException cce)129{130Sysout.println("Test FAILED: ClassCastException");131// throw new RuntimeException("Test FAILED: ClassCastException", cce);132}133catch (Exception e)134{135Sysout.println("Test FAILED: unknown Exception");136// throw new Error("Test FAILED: unknown exception", e);137}138}139}140});141f.add(b);142143f.setVisible(true);144}// start()145146//The rest of this class is the actions which perform the test...147148//Use Sysout.println to communicate with the user NOT System.out!!149//Sysout.println ("Something Happened!");150151}152153/* Place other classes related to the test after this line */154155156157158159/****************************************************160Standard Test Machinery161DO NOT modify anything below -- it's a standard162chunk of code whose purpose is to make user163interaction uniform, and thereby make it simpler164to read and understand someone else's test.165****************************************************/166167/**168This is part of the standard test machinery.169It creates a dialog (with the instructions), and is the interface170for sending text messages to the user.171To print the instructions, send an array of strings to Sysout.createDialog172WithInstructions method. Put one line of instructions per array entry.173To display a message for the tester to see, simply call Sysout.println174with the string to be displayed.175This mimics System.out.println but works within the test harness as well176as standalone.177*/178179class Sysout180{181private static TestDialog dialog;182183public static void createDialogWithInstructions( String[] instructions )184{185dialog = new TestDialog( new Frame(), "Instructions" );186dialog.printInstructions( instructions );187dialog.setVisible(true);188println( "Any messages for the tester will display here." );189}190191public static void createDialog( )192{193dialog = new TestDialog( new Frame(), "Instructions" );194String[] defInstr = { "Instructions will appear here. ", "" } ;195dialog.printInstructions( defInstr );196dialog.setVisible(true);197println( "Any messages for the tester will display here." );198}199200201public static void printInstructions( String[] instructions )202{203dialog.printInstructions( instructions );204}205206207public static void println( String messageIn )208{209dialog.displayMessage( messageIn );210}211212}// Sysout class213214/**215This is part of the standard test machinery. It provides a place for the216test instructions to be displayed, and a place for interactive messages217to the user to be displayed.218To have the test instructions displayed, see Sysout.219To have a message to the user be displayed, see Sysout.220Do not call anything in this dialog directly.221*/222class TestDialog extends Dialog223{224225TextArea instructionsText;226TextArea messageText;227int maxStringLength = 80;228229//DO NOT call this directly, go through Sysout230public TestDialog( Frame frame, String name )231{232super( frame, name );233int scrollBoth = TextArea.SCROLLBARS_BOTH;234instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );235add( "North", instructionsText );236237messageText = new TextArea( "", 5, maxStringLength, scrollBoth );238add("Center", messageText);239240pack();241242setVisible(true);243}// TestDialog()244245//DO NOT call this directly, go through Sysout246public void printInstructions( String[] instructions )247{248//Clear out any current instructions249instructionsText.setText( "" );250251//Go down array of instruction strings252253String printStr, remainingStr;254for( int i=0; i < instructions.length; i++ )255{256//chop up each into pieces maxSringLength long257remainingStr = instructions[ i ];258while( remainingStr.length() > 0 )259{260//if longer than max then chop off first max chars to print261if( remainingStr.length() >= maxStringLength )262{263//Try to chop on a word boundary264int posOfSpace = remainingStr.265lastIndexOf( ' ', maxStringLength - 1 );266267if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;268269printStr = remainingStr.substring( 0, posOfSpace + 1 );270remainingStr = remainingStr.substring( posOfSpace + 1 );271}272//else just print273else274{275printStr = remainingStr;276remainingStr = "";277}278279instructionsText.append( printStr + "\n" );280281}// while282283}// for284285}//printInstructions()286287//DO NOT call this directly, go through Sysout288public void displayMessage( String messageIn )289{290messageText.append( messageIn + "\n" );291System.out.println(messageIn);292}293294}// TestDialog class295296297