--- /dev/null 2016-07-05 10:39:48.000000000 +0530 +++ new/test/java/awt/print/PrinterJob/TestCarryOverValue.java 2016-07-05 10:39:48.139367300 +0530 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 4987884 + * @summary Verify if PrinterJob carries over some values between calls to print + * @run main TestCarryOverValue + */ +import java.awt.Graphics; +import java.awt.print.Book; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; +import javax.print.DocFlavor; +import javax.print.PrintService; +import javax.print.attribute.AttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.PageRanges; + +public class TestCarryOverValue implements Printable { + + static int pageCount = 0; + + public static void main(String args[]) { + PrinterJob pjob = PrinterJob.getPrinterJob(); + PageFormat pf = pjob.defaultPage(); + Book book = new Book(); + + book.append(new TestCarryOverValue(), pf); + book.append(new TestCarryOverValue(), pf); + pjob.setPageable(book); + PrintRequestAttributeSet aset = + new HashPrintRequestAttributeSet(); + aset.add(new PageRanges(1,1)); + PrintService service = pjob.getPrintService(); + AttributeSet unsupportedSet = + service.getUnsupportedAttributes( + DocFlavor.SERVICE_FORMATTED.PAGEABLE, aset); + if (unsupportedSet != null) { + System.out.println("job unsupported - exiting"); + return; + } + try { + pjob.print(aset); + } catch (PrinterException e) { + throw new RuntimeException(e.getMessage()); + } + + Book book2 = new Book(); + book2.append(new TestCarryOverValue(), pf); + book2.append(new TestCarryOverValue(), pf); + pjob.setPageable(book2); + + pageCount = 0; + try { + pjob.print(); + } catch (PrinterException e) { + throw new RuntimeException(e.getMessage()); + } + if (pageCount < 4) { + throw new RuntimeException(" Wrong number of pages printed. " + + " Value carried forward between print calls"); + } + } + + public int print(Graphics g, PageFormat pf, int pageIndex) { + pageCount++; + System.out.println("print " + pageIndex); + return PAGE_EXISTS; + } +} + +