/*
test AttributeChange_NativeTest 1.1 99/07/23
@summary Create PrintJob with properties set to all legal values and check
if the properties are reflected in the native print dialog.
@author N.S.Rammohan(rammohan@siptech.co.in) : area=AWTPrintTesting
@run applet/manual=done AttributeChange_NativeTest.html
*/
// Note there is no @ in front of test above. This is so that the
// harness will not mistake this file as a test file. It should
// only see the html file as a test file. (the harness runs all
// valid test files, so it would run this test twice if this file
// were valid as well as the html file.)
// Also, note the area= after Your Name in the author tag. Here, you
// should put which functional area the test falls in. See the
// AWT-core home page -> test areas and/or -> AWT team for a list of
// areas.
// Note also the 'ManualDoneTest.html' in the run tag. This should
// be changed to the name of the test.
/**
* AttributeChange_NativeTest.java
*
* summary: Create PrintJob with properties set to all legal values and check
* if the properties are reflected in the native print dialog.
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
//Manual tests should run as applet tests if possible because they
// get their environments cleaned up, including AWT threads, any
// test created threads, and any system resources used by the test
// such as file descriptors. (This is normally not a problem as
// main tests usually run in a separate VM, however on some platforms
// such as the Mac, separate VMs are not possible and non-applet
// tests will cause problems). Also, you don't have to worry about
// synchronisation stuff in Applet tests they way you do in main
// tests...
public class AttributeChange_NativeTest extends Applet {
//Declare things used in the test, like buttons and labels here
private Frame testFrame;
public void init() {
//Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
this.setLayout (new BorderLayout ());
// Embed your instructions here.
String[][] instructionsSet=null;
if(isSolaris()) {
instructionsSet = new String[][] {
{
"The Native dialog is not present in Solaris so try",
"Runing the another testcase by name ",
"AttributeChange_CommonTest.html to test the attribute",
"testing. Now click the done button to exit from this "+
"testcase "
}};
}
else {
instructionsSet = new String[][] {
{
"Note : Incase of Assertion failure user can enter any remarks"
+" by pressing 'Assertion Fail Remarks'.",
"The testing involves four assertion checks. After you press "+
"Assertion Pass ",
"or Assertion Fail the instructions in the instruction "+
"dialog is changed",
"Proceed with the testing until you get a 'Testcase completed'"
+"message in the message window",
"PLEASE DON'T FORGET TO ENTER THE REMARKS IN CASE OF"+
" ASSERTION FAILURE",
" ",
"1. Since the PrintDialog is modal, pl. keep the"+
" instructions from 2 to 6",
" visible and then click the 'print' button in the"+
" TestFrame.",
" A native printdialog will appear.",
"2. See if the collate option is not selected and number of "+
"copies is set to 2",
"3. See the PrintRange is set to 'All', 'Pages from' is set"+
" to 2 and 'to' is set to 5",
"4. See if the 'print to file' option is not checked",
"5. Now click the properties button in the dialog and see "+
" papersize is set",
" to A4 and orientation is set to Portrait. Now cancel the "+
" properties dialog",
"6. If any one of the above values are not set then cancel the"
+" printdialog and ",
" press 'Assertion Fail' button in the instruction dialog."
+" Click the",
" 'Assertion Fail Remarks' button and enter your comments"+
" on attributes",
" that are not set to the given values. Else cancel the "+
"PrintDialog and press",
" 'Assertion Pass' button."
},
{
"1. Since the PrintDialog is modal, pl. keep the"+
" instructions from 2 to 6",
" visible and then click the 'print' button in the"+
" TestFrame.",
" A native printdialog will appear.",
"2. See if the collate option is checked",
"3. See the PrintRange is set to 'Selection'",
"4. Now click the properties button in the dialog and see "+
" papersize is set",
" to executive and orientation is set to Landscape.",
" Cancel the Properties dialog",
"5. See if the print to file option is checked."+
" Now click the ok button",
" in the print dialog. Print to file dialog incase of",
" windows or file dialog in case of Solaris should appear"+
" with the file name 'test'",
"6. If any one of the above values are not set, or if the "+
"file dialog",
" doesn't appear, press 'Assertion Fail' button in the"+
"instruction dialog",
" and click the 'Assertion Fail Remarks' button",
" and enter your comments on attributes that are not set to"
+" the given values",
" else Press 'Assertion Pass' button."
},
{
"1. Since the PrintDialog is modal, pl. keep the"+
" instructions from 2 to 5",
" visible and then click the 'print' button in the"+
" TestFrame.",
" A native printdialog will appear.",
"2. Now click the properties button in the dialog and see"+
" if the papersize",
" displays letter. Click the cancel button of"+
" properties dialog",
"3. See if the print range is set to 'Pages'",
"4. See if the from page is set to 1 and topage is set to 9",
" If the from and to pages are not set to 1 and 9"+
" respectively, use the",
" following while entering Assertionfailure remarks",
" 'setPageRanges method is not given priority when'",
" 'setFromPage and setToPage are used'",
"5. If any one of the above values are not set then cancel the"
+" printdialog and press",
" 'Assertion Fail' button in the instruction dialog and"+
" click the",
" 'Assertion Fail Remarks' button and enter your comments"+
" on attributes",
" that are not set to the given values. Else Cancel "+
" the PrintDialog and press 'Assertion Pass' button."
},
{
"1. Click the button titled 'print ' in the TestFrame ",
" A native printdialog will appear.",
"2. Now click the properties button in the print dialog. ",
" If the papersize is not set to 'legal', cancel"+
" the properties",
" dialog and cancel the printdialog and"+
" press 'Assertion Fail' button.",
" else cancel the printdialog and press "+
"'Assertion Pass' button."
}};
}
// Embed your exceptions here, correspondingly for the number of
// instructions. Make sure your exception messages doesn't contain
// any non-printable characters like '\n'
String[] exceptionsSet =
{
"One/some of the attributes are not set properly. Pl. refer "+
"to user remarks for details ",
"One/some of the attributes are not set properly. Pl. refer "+
"to user remarks for details ",
"One/some of the attributes are not set properly. Pl. refer "+
"to user remarks for details ",
"Paper size is not set to legal "
};
Sysout.setInstructionsWithExceptions(instructionsSet,exceptionsSet);
testFrame=new TestFrame();
//For avoiding the overlapping of InstructionDialog and the Main Applet
Container cont= this.getParent();
while(!((cont = cont.getParent() ) instanceof Frame ) ) ;
cont.setSize(300,450);
cont.setLocation(600,50);
cont.invalidate();
cont.validate();
this.invalidate();
this.validate();
}//End init()
private boolean isSolaris() {
return (((System.getProperty("os.name")).toLowerCase().
indexOf("sun"))>-1);
}
public void start (){
//Get things going. Request focus, set size, et cetera
setSize (200,200);
setVisible(true);
testFrame.pack();
testFrame.setLocation(0,400);
testFrame.setVisible(true);
}
public void destroy() {
if(Sysout.failStatus()) {
String failMsg = Sysout.getFailureMessages();
failMsg = failMsg.replace('\n',' ');
throw new RuntimeException(failMsg);
}
}
//The rest of this class is the actions which perform the test...
}// class PrintDialogTest
// class testframe starts here
class TestFrame extends Frame implements ActionListener{
private Button print;
private Panel ButtonPanel;
private int assertion_count=0;
public TestFrame() {
super("TestFrame");
ButtonPanel = new Panel();
print = new Button("print");
print.addActionListener(this);
ButtonPanel.add(print);
add(ButtonPanel);
}
public void actionPerformed(ActionEvent event) {
if(((Button) event.getSource()).getActionCommand().equals
("print")) {
showDialog(assertion_count++);
}
}
private void showDialog(int assertion_count) {
JobAttributes job = new JobAttributes();
PageAttributes page = new PageAttributes();
job.setDialog(JobAttributes.DialogType.NATIVE);
switch(assertion_count) {
case 0: {
job.setMultipleDocumentHandling(JobAttributes.
MultipleDocumentHandlingType.
SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
job.setDefaultSelection(JobAttributes.
DefaultSelectionType.ALL);
job.setDestination(JobAttributes.DestinationType.PRINTER);
job.setCopies(2);
job.setFromPage(2);
job.setToPage(5);
page.setMedia(PageAttributes.MediaType.A4);
page.setOrientationRequested(PageAttributes.
OrientationRequestedType.PORTRAIT);
break;
}
case 1: {
job.setMultipleDocumentHandling(JobAttributes.
MultipleDocumentHandlingType.
SEPARATE_DOCUMENTS_COLLATED_COPIES);
job.setDefaultSelection(JobAttributes.
DefaultSelectionType.SELECTION);
job.setDestination(JobAttributes.DestinationType.FILE);
job.setFileName("test");
page.setMedia(PageAttributes.MediaType.EXECUTIVE);
page.setOrientationRequested(PageAttributes.
OrientationRequestedType.LANDSCAPE);
break;
}
case 2: {
job.setDefaultSelection(JobAttributes.
DefaultSelectionType.RANGE);
job.setDestination(JobAttributes.DestinationType.FILE);
job.setFileName("test");
job.setPageRanges(new int[][]{new int[]{1,3},new int[]{8,9}});
job.setFromPage(4);
job.setToPage(6);
page.setMedia(PageAttributes.MediaType.LETTER);
break;
}
case 3: {
page.setMedia(PageAttributes.MediaType.LEGAL);
break;
}
}
Toolkit tk = Toolkit.getDefaultToolkit();
// seeting this dialog to native pritdialog
if (tk != null) {
PrintJob pj = tk.getPrintJob(this,"testing the attribute "+
"setting ",job,page);
}
}
}
/****************************************************
Standard Test Machinery
DO NOT modify anything below -- it's a standard
chunk of code whose purpose is to make user
interaction uniform, and thereby make it simpler
to read and understand someone else's test.
****************************************************/
/**
This is part of the standard test machinery.
It creates a dialog (with the instructions), and is the interface
for sending text messages to the user.
To print the instructions, send an array of strings to Sysout.createDialog
WithInstructions method. Put one line of instructions per array entry.
To display a message for the tester to see, simply call Sysout.println
with the string to be displayed.
This mimics System.out.println but works within the test harness as well
as standalone.
*/
class Sysout
{
private static TestDialog dialog;
public static void createDialogWithInstructions( String[] instructions )
{
dialog = new TestDialog( new Frame(), "Instructions" );
dialog.printInstructions( instructions );
dialog.show();
println( "Any messages for the tester will display here." );
}
public static void createDialog( )
{
dialog = new TestDialog( new Frame(), "Instructions" );
String[] defInstr = { "Instructions will appear here. ", "" } ;
dialog.printInstructions( defInstr );
dialog.show();
println( "Any messages for the tester will display here." );
}
public static void printInstructions( String[] instructions )
{
dialog.printInstructions( instructions );
}
public static void println( String messageIn )
{
dialog.displayMessage( messageIn );
}
public static void setInstructionsWithExceptions(String
instructionsSet[][],String exceptionsSet[]) {
createDialogWithInstructions(instructionsSet[0]);
dialog.setInstructions(instructionsSet);
dialog.setExceptionMessages(exceptionsSet);
}
public static String getFailureMessages() {
return dialog.failureMessages;
}
public static boolean failStatus() {
return dialog.failStatus;
}
}// Sysout class
/**
This is part of the standard test machinery. It provides a place for the
test instructions to be displayed, and a place for interactive messages
to the user to be displayed.
To have the test instructions displayed, see Sysout.
To have a message to the user be displayed, see Sysout.
Do not call anything in this dialog directly.
*/
class TestDialog extends Dialog
{
TextArea instructionsText;
TextArea messageText;
int maxStringLength = 80;
Panel assertPanel;
Button assertPass,assertFail,remarks;
HandleAssert handleAssert;
boolean failStatus=false;
int instructionCounter=0;
String instructions[][];
int exceptionCounter=0;
String exceptionMessages[];
String failureMessages="
";
String remarksMessage=null;
RemarksDialog remarksDialog;
//DO NOT call this directly, go through Sysout
public TestDialog( Frame frame, String name )
{
super( frame, name );
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
add( "North", instructionsText );
//messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
//height of the messageText is reduced to avoid overlapping of windows.
messageText = new TextArea( "", 4, maxStringLength, scrollBoth );
add("Center", messageText);
assertPanel = new Panel(new FlowLayout());
assertPass=new Button("Assertion Pass");
assertPass.setName("Assertion Pass");
assertFail=new Button("Assertion Fail");
assertFail.setName("Assertion Fail");
remarks = new Button("Assertion Fail Remarks");
remarks.setEnabled(false);
remarks.setName("Assertion Remarks");
assertPanel.add(assertPass);
assertPanel.add(assertFail);
assertPanel.add(remarks);
handleAssert = new HandleAssert();
assertPass.addActionListener(handleAssert);
assertFail.addActionListener(handleAssert);
remarks.addActionListener(handleAssert);
add("South",assertPanel);
pack();
show();
}// TestDialog()
//DO NOT call this directly, go through Sysout
public void printInstructions( String[] instructions )
{
//Clear out any current instructions
instructionsText.setText( "" );
//Go down array of instruction strings
String printStr, remainingStr;
for( int i=0; i < instructions.length; i++ )
{
//chop up each into pieces maxSringLength long
remainingStr = instructions[ i ];
while( remainingStr.length() > 0 )
{
//if longer than max then chop off first max chars to print
if( remainingStr.length() >= maxStringLength )
{
//Try to chop on a word boundary
int posOfSpace = remainingStr.
lastIndexOf( ' ', maxStringLength - 1 );
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
printStr = remainingStr.substring( 0, posOfSpace + 1 );
remainingStr = remainingStr.substring( posOfSpace + 1 );
}
//else just print
else
{
printStr = remainingStr;
remainingStr = "";
}
instructionsText.append( printStr + "\n" );
}// while
}// for
}//printInstructions()
//DO NOT call this directly, go through Sysout
public void displayMessage( String messageIn )
{
messageText.append( messageIn + "\n" );
}
public void emptyMessage() {
messageText.setText("");
}
public void setInstructions(String insStr[][]) {
instructions=insStr;
}
public void setExceptionMessages(String exceptionMessages[]) {
this.exceptionMessages=exceptionMessages;
}
class HandleAssert implements ActionListener {
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==remarks) {
remarksDialog = new RemarksDialog(TestDialog.this,
"Assertion Remarks Dialog",true);
remarks.setEnabled(false);
if(remarksMessage!=null)
failureMessages+=". User Remarks : "+remarksMessage;
}
else {
if(instructionCounter"+
exceptionMessages[exceptionCounter];
}
}
exceptionCounter++;
}
}
}
class RemarksDialog extends Dialog implements ActionListener{
Panel rootPanel,remarksPanel;
TextArea textarea;
Button addRemarks,cancelRemarks;
public RemarksDialog(Dialog owner,String title,boolean modal) {
super(owner,title,modal);
rootPanel = new Panel(new BorderLayout());
remarksPanel = new Panel(new FlowLayout());
textarea = new TextArea(5,30);
addRemarks=new Button("Add Remarks");
addRemarks.addActionListener(this);
cancelRemarks = new Button("Cancel Remarks");
cancelRemarks.addActionListener(this);
remarksPanel.add(addRemarks);
remarksPanel.add(cancelRemarks);
rootPanel.add(textarea,"Center");
rootPanel.add(remarksPanel,"South");
add(rootPanel);
setBounds(150,150,400,200);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
remarksMessage=null;
if(ae.getSource()==addRemarks) {
String msg = textarea.getText().trim();
if (msg.length()>0)
remarksMessage=msg;
}
dispose();
}
}
}// TestDialog class