Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6527316

java incorrectly claims to support Copies attribute when printing a postscript file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 1.4.0, 7
    • client-libs
    • 2d
    • b17
    • generic, sparc
    • linux, solaris_9
    • Verified

      Java Version: 1.7.0-ea-b08, 1.6.0-b106, and 1.6.0_01-b04
      Platform: linux cinnabar
      host name: jfcsqe-jupiter.sfbay with cups 1.1.22 installed

      Problems:
      We have a test case as attached, it Prints a file after setting the Copies attribute. The test sets the copies attribute to 2. So for each print out, 2 copies of the file must be printed, the jpeg , gif, png, x-sun-raster, tiff, pdf files all got 2 copies print out, but postscript file only got one copy print out.
      It happens only in linux and with ps file, solaris-sparc 10 with CUPS installed is ok, meaning print out 2 copies of ps file.
      It is not a regression, since it has the same problem with previous release.

      The test case is as following:
      ================================
      import javasoft.clientsqe.tonga.*;
      import javax.print.*;
      import javax.print.attribute.standard.*;
      import javax.print.attribute.*;
      import java.io.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.net.URL;
      import java.util.Map;

      public class PrintDocCopiesTest extends AbstractTongaManualTest {

          private String fileNameKey = "FileName_";
          private String destFileNameKey = "Destination_";
          private String docFlavorKey = "DocFlavor_";
          private String mimeTypeKey = "DocFlavor_MimeType_";
          private String classNameKey = "DocFlavor_ClassName_";

          private DocFlavor docFlavor = null;
          private String fileName = null;
          private TestProperties props = null;

          private Frame frame = null;
          private Button button = null;
          private ImageCanvas imageCanvas = null;

          public void init(Map map) {
              
          }

          public void doTest(TestProperties props) {

              this.props = props;

              String fileNameStr = (String) props.get(fileNameKey + props.getIndex());
              String destFileNameStr = (String) props.get(destFileNameKey + props.getIndex());
              String docFlavorStr = (String) props.get(docFlavorKey + props.getIndex());
              String mimeType = (String) props.get(mimeTypeKey + props.getIndex());
              String className = (String) props.get(classNameKey + props.getIndex());

              Sysout.println("DocFlavor " + mimeType + " " + className);

              if(mimeType != null && className != null) {
                  docFlavor = new DocFlavor(mimeType, className);
              }

              if(docFlavor == null) {
                  Sysout.println("DocFlavor not set !!! - Check resources file - PrintDocCopiesTest");
                  Sysout.println("Please press \"Assertion Fail\" button to goto next test.");
                  return;
              }

              URL url = getClass().getResource(fileNameStr);
              if(url == null) {
                  Sysout.println("Image - " + fileNameStr + " - not found !!! - Check resources file - PrintDocCopiesTest");
                  Sysout.println("Please press \"Assertion Fail\" button to goto next test.");
                  return;
              }

              if(frame == null) {
                  
                  frame = new Frame();
                  frame.setSize(400, 200);
                  frame.setLocation(50, 400);

                  button = new Button("Print");
                  frame.add(button, BorderLayout.SOUTH);
                  button.addActionListener(new ButtonHandler());

                  imageCanvas = new ImageCanvas();
                  frame.add(imageCanvas);

                  frame.setVisible(true);
              }

              fileName = url.getPath();

              frame.setTitle("Test Frame - " + docFlavor.toString());

              try {
                  Image image = javax.imageio.ImageIO.read(url);
                  if(image != null) {
                      imageCanvas.setImage(image);
                  }
                  else {
                      imageCanvas.setImage(null);
                      imageCanvas.setString(docFlavor.toString());
                  }
              }
              catch(java.io.IOException ioe) {
                  Sysout.println("IOException thrown while trying to load image - " + fileName);
                  Sysout.println("Please press \"Assertion Fail\" button to goto next test.");
                  props.setException(ioe);
                  return;
              }
          }

          private class ButtonHandler implements ActionListener {
              public void actionPerformed(ActionEvent ae) {
                  doTest(docFlavor, fileName, props);
              }
          }

          private void doTest(DocFlavor docFlavor, String fileName, TestProperties props) {

              PrintService[] service = PrintServiceLookup.lookupPrintServices(docFlavor, null);

              if (service.length == 0) {
                  Sysout.println("No PrintService support " + docFlavor.toString() + " Flavor.");
                  Sysout.println("Please press \"Assertion Pass\" button to goto next test.");
                  return;
              }

              PrintService printService = service[0];
              Sysout.println("PrintService which supports " + docFlavor + " : " + printService.getName());

              boolean supported = printService.isDocFlavorSupported(docFlavor);
              if ( ! supported ) {
                  Sysout.println("FAIL : isDocFlavorSupported returned FALSE for\n" +
                                 "supported " + docFlavor + " for PrintService " + printService.getName());
                  Sysout.println("Please press \"Assertion Fail\" button to goto next test.");
                  return;
              }

              Copies copies = new Copies(2);
              
              boolean isValueSupported =
                  printService.isAttributeValueSupported(copies, docFlavor, null);

              if( ! isValueSupported) {
                  Sysout.println(copies.getClass().getName() + " attribute is not supported by PrintService " +
                                 printService.getName() + " for " + docFlavor.toString() + " Flavor.");
                  Sysout.println("Please press \"Assertion Pass\" button to goto next test.");
                  return;
              }

              HashPrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
              printRequestAttributeSet.add(copies);

              DocPrintJob printJob = printService.createPrintJob();
              PrintDoc printDoc = new PrintDoc(docFlavor, fileName);

              try {
                  printJob.print(printDoc, printRequestAttributeSet);
              } catch (Exception e) {
                  e.printStackTrace();
                  props.setException(e);
                  Sysout.println("FAIL : Exception thrown while trying to print\n " + e.toString());
                  Sysout.println("Please press \"Assertion Fail\" button to goto next test.");
              }
          }

          public void destroy() {
              if(frame != null) {
                  frame.dispose();
              }
          }

          public String getTestName() {
              return "PrintDocCopiesTest";
          }
      }

      The log file is as following:
      DocFlavor image/jpeg [B
      DocFlavor image/gif [B
      DocFlavor image/png [B
      DocFlavor image/x-bitmap [B
      PrintService which supports image/x-bitmap; class="[B" : clientsqe1
      DocFlavor instanceof DocFlavor.BYTE_ARRAY
      PrintDoc initialized for : image/x-bitmap; class="[B" : /.automount/sqe1/root/quality2/2d/Mustang_2d_ws/2d/data/2D_PrintingTiger/images/duke.bmp
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getStreamForBytes called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      DocFlavor image/x-sun-raster [B
      PrintService which supports image/x-sun-raster; class="[B" : clientsqe1
      DocFlavor instanceof DocFlavor.BYTE_ARRAY
      PrintDoc initialized for : image/x-sun-raster; class="[B" : /.automount/sqe1/root/quality2/2d/Mustang_2d_ws/2d/data/2D_PrintingTiger/images/duke.sr
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getStreamForBytes called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      DocFlavor image/tiff [B
      PrintService which supports image/tiff; class="[B" : clientsqe1
      DocFlavor instanceof DocFlavor.BYTE_ARRAY
      PrintDoc initialized for : image/tiff; class="[B" : /.automount/sqe1/root/quality2/2d/Mustang_2d_ws/2d/data/2D_PrintingTiger/images/duke.tiff
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getStreamForBytes called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      DocFlavor application/pdf [B
      PrintService which supports application/pdf; class="[B" : clientsqe1
      DocFlavor instanceof DocFlavor.BYTE_ARRAY
      PrintDoc initialized for : application/pdf; class="[B" : /.automount/sqe1/root/quality2/2d/Mustang_2d_ws/2d/data/2D_PrintingTiger/data.pdf
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getStreamForBytes called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      DocFlavor application/postscript [B
      PrintService which supports application/postscript; class="[B" : clientsqe1
      DocFlavor instanceof DocFlavor.BYTE_ARRAY
      PrintDoc initialized for : application/postscript; class="[B" : /.automount/sqe1/root/quality2/2d/Mustang_2d_ws/2d/data/2D_PrintingTiger/data.ps
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getStreamForBytes called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      getPrintData called for DocFlavor.BYTE_ARRAY
      annotate TEST name=PrintDocCopiesTest
      annotate TEST status_0=pass
      annotate TEST status_1=pass
      annotate TEST status_2=pass
      annotate TEST status_3=pass
      annotate TEST status_4=pass
      annotate TEST status_5=pass
      annotate TEST status_6=pass
      annotate TEST status_7=fail

            prr Philip Race
            ttzhang Tao Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: