Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 60237 invoked from network); 9 Oct 2006 05:34:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Oct 2006 05:34:24 -0000 Received: (qmail 63182 invoked by uid 500); 9 Oct 2006 05:34:23 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 63139 invoked by uid 500); 9 Oct 2006 05:34:22 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 63087 invoked by uid 99); 9 Oct 2006 05:34:22 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Oct 2006 22:34:22 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:62931] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 65/52-06006-84FD9254 for ; Sun, 08 Oct 2006 22:34:00 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 78D4E1A981C; Sun, 8 Oct 2006 22:33:35 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r454289 [20/22] - in /incubator/harmony/enhanced/classlib/trunk/modules/H-1609: ./ modules/ modules/applet/ modules/applet/src/ modules/applet/src/main/ modules/applet/src/main/java/ modules/applet/src/main/java/java/ modules/applet/src/mai... Date: Mon, 09 Oct 2006 05:33:21 -0000 To: harmony-commits@incubator.apache.org From: mloenko@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061009053335.78D4E1A981C@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupDefaultPrintServiceTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupDefaultPrintServiceTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupDefaultPrintServiceTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupDefaultPrintServiceTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,81 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import java.io.InputStream; + +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.MediaName; +import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.Sides; + +import junit.framework.TestCase; + +public class LookupDefaultPrintServiceTest extends TestCase { + public void testLookupDefaultPrintService() { + System.out + .println("======= START LookupDefaultPrintServiceTest ======"); + + DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF; + PrintService service; + InputStream fis; + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + HashDocAttributeSet daset = new HashDocAttributeSet(); + DocPrintJob pj; + Doc doc; + + aset.add(new Copies(2)); + aset.add(MediaSizeName.ISO_A4); + daset.add(MediaName.ISO_A4_WHITE); + daset.add(Sides.TWO_SIDED_LONG_EDGE); + + try { + service = PrintServiceLookup.lookupDefaultPrintService(); + if (service != null) { + if (service.isDocFlavorSupported(psFlavor)) { + if (service.getUnsupportedAttributes(psFlavor, aset)==null) { + fis = this.getClass().getResourceAsStream( + "/Resources/GIF.gif"); + doc = new SimpleDoc(fis, psFlavor, daset); + + pj = service.createPrintJob(); + pj.print(doc, aset); + System.out.println(fis.toString() + " printed on " + + service.getName()); + } + } else { + System.out.println("flavor is not supported"); + } + } else { + System.out.println("service not found"); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + System.out.println("======= END LookupDefaultPrintServiceTest ======="); + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupDefaultPrintServiceTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupMultiDocPrintServicesTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupMultiDocPrintServicesTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupMultiDocPrintServicesTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupMultiDocPrintServicesTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,76 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import java.io.FileInputStream; + +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.MediaName; +import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.Sides; + +import junit.framework.TestCase; + +public class LookupMultiDocPrintServicesTest extends TestCase { + public void testLookupMultiDocPrintServices() { + System.out + .println("============= START LookupMultiDocPrintServicesTest ================"); + + DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF; + MultiDocPrintService[] services; + FileInputStream fis; + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + HashDocAttributeSet daset = new HashDocAttributeSet(); + DocPrintJob pj; + Doc doc; + + aset.add(new Copies(2)); + aset.add(MediaSizeName.ISO_A4); + daset.add(MediaName.ISO_A4_WHITE); + daset.add(Sides.TWO_SIDED_LONG_EDGE); + + try { + services = PrintServiceLookup.lookupMultiDocPrintServices( + new DocFlavor[] { psFlavor }, aset); + if (services != null && services.length > 0) { + fis = new FileInputStream("/Resources/1M.GIF"); + doc = new SimpleDoc(fis, psFlavor, daset); + + pj = services[0].createPrintJob(); + pj.print(doc, aset); + System.out.println(fis.toString() + " printed on " + + services[0].getName()); + } else { + System.out.println("services not found"); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + System.out + .println("============= END LookupMultiDocPrintServicesTest ================"); + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupMultiDocPrintServicesTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupPrintServicesTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupPrintServicesTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupPrintServicesTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupPrintServicesTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,73 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import java.io.InputStream; +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; + +import junit.framework.TestCase; + +public class LookupPrintServicesTest extends TestCase { + public void testLookupPrintServices() { + System.out.println("======== START LookupPrintServicesTest ========"); + + PrintService[] services; + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + HashDocAttributeSet daset = new HashDocAttributeSet(); + DocPrintJob pj; + Doc doc; + + Object[][] filetoprint = { { "/Resources/JPEG.jpg", + DocFlavor.INPUT_STREAM.JPEG }, + { "/Resources/GIF.gif", DocFlavor.INPUT_STREAM.GIF } }; + try { + DocFlavor df; + InputStream fis; + + for (int i = 0; i < filetoprint.length; i++) { + df = (DocFlavor) filetoprint[i][1]; + + services = PrintServiceLookup.lookupPrintServices(df, aset); + TestUtil.checkServices(services); + + for (int j = 0; j < services.length; j++) { + fis = this.getClass().getResourceAsStream( + (String) filetoprint[i][0]); + doc = new SimpleDoc(fis, df, daset); + PrintService printer = services[j]; + + pj = printer.createPrintJob(); + pj.print(doc, aset); + System.out.println(fis.toString() + " printed on " + + printer.getName()); + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + System.out.println("====== END LookupPrintServicesTest ========"); + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/LookupPrintServicesTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintAutosenseTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintAutosenseTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintAutosenseTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintAutosenseTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,72 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import java.io.InputStream; + +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.standard.MediaSizeName; + +import junit.framework.TestCase; + +public class PrintAutosenseTest extends TestCase { + public static void main(String[] args) { + new PrintAutosenseTest().testPrintAutosense(); + } + + public void testPrintAutosense() { + System.out.println("======== START PrintAutosenseTest ========"); + + PrintService[] services; + HashDocAttributeSet daset = new HashDocAttributeSet(); + DocPrintJob pj; + Doc doc; + + daset.add(MediaSizeName.ISO_A4); + + try { + DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE; + InputStream fis = this.getClass().getResourceAsStream( + "/Resources/hello_ps.ps"); + services = PrintServiceLookup.lookupPrintServices(df, null); + TestUtil.checkServices(services); + + for (int j = 0; j < services.length; j++) { + PrintService printer = services[j]; + if (printer.toString().indexOf("print-to-file") >= 0) { + doc = new SimpleDoc(fis, df, null); + + pj = printer.createPrintJob(); + pj.print(doc, null); + System.out.println(fis.toString() + " printed on " + + printer.getName()); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + System.out.println("====== END PrintAutosenseTest ========"); + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintAutosenseTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintJpegTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintJpegTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintJpegTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintJpegTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,75 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import java.io.InputStream; + +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.MediaSizeName; + +import junit.framework.TestCase; + +public class PrintJpegTest extends TestCase { + public static void main(String[] args) { + new PrintJpegTest().testPrintJpeg(); + } + + public void testPrintJpeg() { + System.out.println("======== START PrintJpegTest ========"); + + PrintService[] services; + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + HashDocAttributeSet daset = new HashDocAttributeSet(); + DocPrintJob pj; + Doc doc; + + daset.add(MediaSizeName.ISO_A4); + + try { + DocFlavor df = DocFlavor.INPUT_STREAM.JPEG; + InputStream fis = this.getClass().getResourceAsStream( + "/Resources/JPEG.jpg"); + services = PrintServiceLookup.lookupPrintServices(df, aset); + TestUtil.checkServices(services); + + for (int j = 0; j < services.length; j++) { + PrintService printer = services[j]; + if (printer.toString().indexOf("print-to-file") >= 0) { + doc = new SimpleDoc(fis, df, daset); + + pj = printer.createPrintJob(); + pj.print(doc, aset); + System.out.println(fis.toString() + " printed on " + + printer.getName()); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + System.out.println("====== END PrintJpegTest ========"); + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintJpegTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,228 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.3 $ + */ + +package javax.print; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Locale; + +import javax.print.attribute.DocAttributeSet; +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.DocumentName; +import javax.print.attribute.standard.JobName; +import javax.print.attribute.standard.MediaName; +import javax.print.attribute.standard.RequestingUserName; + +import junit.framework.TestCase; + +public class PrintTest extends TestCase { + public static void main(String[] args) { + junit.textui.TestRunner.run(PrintTest.class); + } + + public void testPrintSomething() { + /*Authenticator.setDefault(new PrintTestAuth());*/ + + boolean testrun = true; + + System.out.println("============= START PrintTest ================"); + //if ((System.getProperty("os.name")).toLowerCase().indexOf("linux") >= 0) { + if (!testrun) { + System.out.println("The test is always pass temporary."); + System.out.println("============= END PrintTest ================"); + return; + } + + String file_txt = "/Resources/readme.txt"; + String file_gif = "/Resources/printservice.gif"; + String http_gif = ""; + String http_ps = ""; + + PrintService[] services = PrintServiceLookup.lookupPrintServices(null, + null); + TestUtil.checkServices(services); + + PrintService service = PrintServiceLookup.lookupDefaultPrintService(); + + System.out.println("Default: " + + (service == null ? "null" : service.getName())); + + System.out.println("Print services:"); + for (int i = 0; i < services.length; i++) { + System.out.println("\t" + services[i].getName()); + } + + DocAttributeSet dset = new HashDocAttributeSet(); + dset.add(new DocumentName("print doc name", Locale.US)); + + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + aset.add(new Copies(3)); + aset.add(MediaName.ISO_A4_WHITE); + aset.add(new RequestingUserName("ichebyki", Locale.US)); + + try { + PrintService serv = services[0]; + InputStream stream; + DocFlavor flavor; + DocPrintJob job; + Doc doc; + URL url; + Reader rdr; + + try { + flavor = DocFlavor.URL.PDF;//TEXT_HTML_HOST; + if (serv.isDocFlavorSupported(flavor)) { + aset.add(new JobName(flavor.toString(), Locale.US)); + dset.add(new DocumentName(http_ps, Locale.US)); + job = serv.createPrintJob(); + url = new URL(http_ps); + doc = new SimpleDoc(url, flavor, dset); + System.out.println("\nPrinting on " + + job.getPrintService().getName() + "..."); + job.print(doc, aset); + System.out.println("File '" + http_ps + "' was printed as " + + flavor.getRepresentationClassName()); + } + + flavor = DocFlavor.URL.GIF; + if (serv.isDocFlavorSupported(flavor)) { + aset.add(new JobName(flavor.toString(), Locale.US)); + dset.add(new DocumentName(http_gif, Locale.US)); + job = serv.createPrintJob(); + url = new URL(http_gif); + doc = new SimpleDoc(url, flavor, dset); + System.out.println("\nPrinting on " + + job.getPrintService().getName() + "..."); + job.print(doc, aset); + System.out.println("File '" + http_gif + "' was printed as " + + flavor.getRepresentationClassName()); + } + } catch (PrintException e1) { + e1.printStackTrace(); + } + + flavor = DocFlavor.READER.TEXT_PLAIN; + if (serv.isDocFlavorSupported(flavor)) { + aset.add(new JobName(flavor.toString(), Locale.US)); + dset.add(new DocumentName(file_txt, Locale.US)); + job = serv.createPrintJob(); + rdr = new InputStreamReader(getClass().getResourceAsStream( + file_txt)); + doc = new SimpleDoc(rdr, flavor, dset); + System.out.println("Printing on " + + job.getPrintService().getName() + "..."); + job.print(doc, aset); + System.out.println("File '" + file_txt + "' was printed as " + + flavor.getRepresentationClassName()); + } + + flavor = DocFlavor.INPUT_STREAM.GIF; + if (serv.isDocFlavorSupported(flavor)) { + aset.add(new JobName(flavor.toString(), Locale.US)); + dset.add(new DocumentName(file_gif, Locale.US)); + job = serv.createPrintJob(); + stream = getClass().getResourceAsStream(file_gif); + doc = new SimpleDoc(stream, flavor, dset); + System.out.println("\nPrinting on " + + job.getPrintService().getName() + "..."); + job.print(doc, aset); + System.out.println("File '" + file_gif + "' was printed as " + + flavor.getRepresentationClassName()); + } + + flavor = DocFlavor.BYTE_ARRAY.JPEG; + if (serv.isDocFlavorSupported(flavor)) { + aset.add(new JobName(flavor.toString(), Locale.US)); + dset.add(new DocumentName(file_gif, Locale.US)); + job = serv.createPrintJob(); + stream = getClass().getResourceAsStream(file_gif); + byte[] gif_buf; + byte[] buf = new byte[1024]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int count; + while ((count = stream.read(buf, 0, 1024)) > 0) { + baos.write(buf, 0, count); + } + stream.close(); + gif_buf = baos.toByteArray(); + baos.close(); + doc = new SimpleDoc(gif_buf, flavor, dset); + System.out.println("\nPrinting on " + + job.getPrintService().getName() + "..."); + job.print(doc, aset); + System.out.println("File '" + file_gif + "' was printed as " + + flavor.getRepresentationClassName()); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + fail("Unexpected exception occured!\n" + e.getLocalizedMessage()); + } catch (PrintException e) { + e.printStackTrace(); + fail("PrintException occured!\n" + e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception occured!\n" + e.getLocalizedMessage()); + } + + System.out.println("============= END PrintTest ================"); + } + + /* + * For authentication + * uncomment when swing will support JTextField and etc. + */ + /* + class PrintTestAuth extends Authenticator { + protected PasswordAuthentication getPasswordAuthentication() { + JTextField username = new JTextField(); + JTextField password = new JPasswordField(); + JPanel panel = new JPanel(new GridLayout(2, 2)); + panel.add(new JLabel("Login")); + panel.add(username); + panel.add(new JLabel("Password")); + panel.add(password); + int option = JOptionPane.CANCEL_OPTION; + + option = JOptionPane.showConfirmDialog(null, + new Object[] { "Site: " + getRequestingHost(), + "Realm: " + getRequestingPrompt(), + panel }, "Enter Network Password", + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + if (option == JOptionPane.OK_OPTION) { + String user = username.getText(); + char pass[] = password.getText().toCharArray(); + return new PasswordAuthentication(user, pass); + } + + return null; + } + } + */ + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/PrintTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUIFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUIFactoryTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUIFactoryTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUIFactoryTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,43 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Irina A. Arkhipets + * @version $Revision: 1.2 $ + */ + +/* + * ServiceUIFactoryTest.java + * + * JUnit tests for javax.print.ServiceUIFactory + * + */ + +package javax.print; + +import junit.framework.TestCase; + +public class ServiceUIFactoryTest extends TestCase { +public void testStaticFields() { + assertTrue(ServiceUIFactory.ABOUT_UIROLE == 1); + assertTrue(ServiceUIFactory.ADMIN_UIROLE == 2); + assertTrue(ServiceUIFactory.MAIN_UIROLE == 3); + assertTrue(ServiceUIFactory.RESERVED_UIROLE == 99); + assertEquals(ServiceUIFactory.DIALOG_UI, "java.awt.Dialog"); + assertEquals(ServiceUIFactory.JCOMPONENT_UI, "javax.swing.JComponent"); + assertEquals(ServiceUIFactory.JDIALOG_UI, "javax.swing.JDialog"); + assertEquals(ServiceUIFactory.PANEL_UI, "java.awt.Panel"); +} +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUIFactoryTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUITests.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUITests.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUITests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUITests.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,124 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Irina A. Arkhipets + * @version $Revision: 1.3 $ + */ + +/* + * ServiceUITests.java + * + * JUnit tests for javax.print.ServiceUI class + * + */ + +package javax.print; + +import javax.print.attribute.HashPrintRequestAttributeSet; + +import junit.framework.TestCase; + +public class ServiceUITests extends TestCase { + +private PrintService [] services = null; +private HashPrintRequestAttributeSet attrs = null; + +protected void setUp() throws Exception { + services = PrintServiceLookup.lookupPrintServices( + DocFlavor.INPUT_STREAM.GIF, null); + attrs = new HashPrintRequestAttributeSet(); +} + +/* + * Throws IllegalArgumentException if services array is null +*/ +public void testPrintDialog1() { + try { + ServiceUI.printDialog(null, + 5, + 5, + null, + null, + null, + attrs); + fail(); + } catch (IllegalArgumentException e) { + /* IllegalArgimentException is expected here, so the test passes */ + } +} + +/* + * Throws IllegalArgumentException if services array is or empty +*/ +public void testPrintDialog2() { + try { + ServiceUI.printDialog(null, + 5, + 5, + new PrintService [] {}, + null, + null, + attrs); + fail(); + } catch (IllegalArgumentException e) { + /* IllegalArgimentException is expected here, so the test passes */ + } +} + +/* + * Throws IllegalArgumentException if attributes is null +*/ +public void testPrintDialog3() { + try { + ServiceUI.printDialog(null, + 5, + 5, + services, + null, + null, + null); + fail(); + } catch (IllegalArgumentException e) { + /* IllegalArgimentException is expected here, so the test passes */ + } +} + +/* + * Throws IllegalArgumentException if initial PrintService + * is not in the list of browsable services +*/ +public void testPrintDialog4() { + if ((services != null) && (services.length > 1)) { + PrintService [] s1 = new PrintService [services.length-1]; + for (int i = 0; i < services.length - 1; i++) { + s1[i] = services[i]; + } + try { + ServiceUI.printDialog(null, + 5, + 5, + s1, + services[services.length - 1], + null, + null); + fail(); + } catch (IllegalArgumentException e) { + /* IllegalArgimentException is expected here, so the test passes */ + } + } +} + +} /* End of ServiceUITests */ Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ServiceUITests.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/TestUtil.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/TestUtil.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/TestUtil.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/TestUtil.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,55 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor A. Pyankov + * @version $Revision: 1.2 $ + */ + +package javax.print; + +import junit.framework.TestCase; + +public class TestUtil extends TestCase { + public void testFakeTest() { + // fake test case + } + + public static void checkServices(PrintService[] srvs) { + assertNotNull( + "\nPrintServiceLookup.lookupPrintServices must return non-null value", + srvs); + if (srvs.length == 0) { + String szerr = "\nNo printers found."; + String os = System.getProperty("os.name"); + + if (os == null) { + szerr += "\nPlease add printer on localhost."; + } else if (os.toLowerCase().indexOf("windows") >= 0) { + szerr += "\nPlease add printer on localhost."; + } else if (os.toLowerCase().indexOf("linux") >= 0) { + szerr += "\nPlease install CUPS and create printers on localhost"; + } + szerr += "\nYou can use " + + "'print.cups.servers' and/or 'print.ipp.printers' \n" + + "properties to specify CUPS servers and/or IPP printers.\n" + + "Usage: \n" + + " print.cups.servers=http://:,...\n" + + " print.ipp.printers=http://:/path/to/printer1,...\n"; + fail(szerr); + } + } + +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/TestUtil.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ValueTests.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ValueTests.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ValueTests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ValueTests.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,586 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Irina A. Arkhipets + * @version $Revision: 1.3 $ + */ + +/* + * ValueTests.java + * + * JUnit not-interactive Value tests for "Hello, World!" version (javax.print + * package only). + * + */ + +package javax.print; + +import java.io.ByteArrayOutputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.util.Locale; +import java.util.Vector; + +import javax.print.attribute.Attribute; +import javax.print.attribute.DocAttribute; +import javax.print.attribute.DocAttributeSet; +import javax.print.attribute.HashDocAttributeSet; +import javax.print.attribute.HashPrintJobAttributeSet; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.HashPrintServiceAttributeSet; +import javax.print.attribute.PrintJobAttribute; +import javax.print.attribute.PrintJobAttributeSet; +import javax.print.attribute.PrintRequestAttribute; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.PrintServiceAttribute; +import javax.print.attribute.PrintServiceAttributeSet; +import javax.print.attribute.standard.ColorSupported; +import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.MediaName; +import javax.print.attribute.standard.OrientationRequested; +import javax.print.attribute.standard.PrintQuality; +import javax.print.attribute.standard.PrinterLocation; + +import junit.framework.TestCase; + +public class ValueTests extends TestCase { + +private static String OS = null; + +static { + try { + OS = System.getProperty("os.name"); + if (OS.startsWith("Windows")) { + System.loadLibrary("ValueTestsLibrary"); + } + } catch (Exception e) { + if (OS == null) { + System.out.println("WARNING: Can not get Operation System name!"); + } else { + if (OS.startsWith("Windows")) { + System.out.println( + "WARNING! Can not load ValueTestsLibrary library!"); + } + } + System.out.println("Some testcases probably will not be started!"); + } +} + +public void testDocFlavor() { + startTest("DocFlavor class testing..."); + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + assertEquals(flavor, new DocFlavor.INPUT_STREAM("image/gif")); + assertEquals(flavor.getMediaSubtype(), "gif"); + assertEquals(flavor.getMediaType(), "image"); + assertEquals(flavor.getMimeType(), "image/gif"); + assertEquals(flavor.getRepresentationClassName(), "java.io.InputStream"); + assertEquals(flavor.toString(), + "image/gif; class=\"java.io.InputStream\""); +} + +public void testSimpleDoc() { + startTest("SimpleDoc class testing..."); + + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + InputStream reader = + getClass().getResourceAsStream("/Resources/picture.gif"); + if (reader == null) { + fail("/Resources/picture.gif resource is not found!"); + } + + DocAttributeSet aSet = new HashDocAttributeSet(); + Doc doc = new SimpleDoc(reader, flavor, aSet); + + assertEquals(doc.getAttributes(), aSet); + aSet.add(OrientationRequested.LANDSCAPE); + aSet.add(MediaName.NA_LETTER_WHITE); + assertEquals(doc.getAttributes(), aSet); + assertEquals(doc.getDocFlavor(), DocFlavor.INPUT_STREAM.GIF); + try { + assertTrue(doc.getPrintData() instanceof java.io.InputStream); + assertEquals(doc.getReaderForText(), null); + assertEquals(doc.getStreamForBytes(), reader); + } catch(Exception e) { + e.printStackTrace(); + fail("Exception found: "+e); + } +} + +public void testDefaultPrintService() { + boolean flg = false; + + startTest("PrintService class testing..."); + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + PrintRequestAttributeSet printRequestSet = + new HashPrintRequestAttributeSet(); + PrintService service = getPrintService(flavor, printRequestSet); + DocFlavor [] flavors; + String myName = getDefaultPrintService(); + + System.out.println("OS is " + OS); + if (service == null) { + System.out.println( + "WARNING: Can not get print service which supports INPUT_STREAM.GIF!"); + } else { + assertTrue(service.isDocFlavorSupported(flavor)); + flavors = service.getSupportedDocFlavors(); + for (int i = 0; i < flavors.length; i++) { + if (flavors[i].equals(flavor)) { + flg = true; + break; + } + } + assertTrue(flg); +/* if (myName != null) { + assertEquals(service.getName(), myName); + } +*/ + } +} + +public void testPrintJob() { + startTest("PrintJob class testing..."); + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + PrintRequestAttributeSet printRequestSet = + new HashPrintRequestAttributeSet(); + PrintService service = getPrintService(flavor, printRequestSet); + if (service != null) { + DocPrintJob job = service.createPrintJob(); + assertEquals(job.getPrintService(), service); + } else { + System.out.println( + "WARNING: Can not get print service which supports INPUT_STREAM.GIF!"); + } +} + +public void testStreamServiceFactory() { + startTest("StreamPrintServiceFactory class testing..."); + boolean flg = false; + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + StreamPrintServiceFactory [] aFactory = StreamPrintServiceFactory + .lookupStreamPrintServiceFactories(flavor, "application/postscript"); + StreamPrintServiceFactory streamFactory=null; + StreamPrintService streamService; + DocFlavor [] flavors; + + if ((aFactory == null) || (aFactory.length == 0)) { + fail("Can not find stream print service factory!"); + } else { + streamFactory = aFactory[0]; + } + streamService = streamFactory.getPrintService(new ByteArrayOutputStream()); + assertEquals(streamFactory.getOutputFormat(), "application/postscript"); + assertEquals(streamFactory.getPrintService(new ByteArrayOutputStream()), + streamService); + flavors = streamFactory.getSupportedDocFlavors(); + for (int i = 0; i < flavors.length; i++) { + if (flavors[i].equals(flavor)) { + flg = true; + break; + } + } + assertTrue(flg); +} + +public void testStreamPrintService() { + startTest("StreamPrintService class testing..."); + + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + StreamPrintServiceFactory [] aFactory = StreamPrintServiceFactory + .lookupStreamPrintServiceFactories(flavor, "application/postscript"); + StreamPrintServiceFactory streamFactory = null; + StreamPrintService streamService; + DocFlavor [] flavors; + boolean flg = false; + + if ((aFactory == null) || (aFactory.length == 0)) { + fail("Can not find stream print service factory!"); + } else { + streamFactory = aFactory[0]; + } + streamService = streamFactory.getPrintService(new ByteArrayOutputStream()); + + assertEquals(streamService.getOutputFormat(), "application/postscript"); + assertTrue(streamService.isDocFlavorSupported(flavor)); + flavors = streamService.getSupportedDocFlavors(); + for (int i = 0; i < flavors.length; i++) { + if (flavors[i].equals(flavor)) { + flg = true; + break; + } + } + assertTrue(flg); + streamService.dispose(); + assertEquals(streamService.isDisposed(), true); +} + +public void testStreamServicePrinting() { + startTest("StreamPrintServiceFactory class testing..."); + + byte [] forChecking = {'%', '!', 'P', 'S', '-', 'A', 'd', 'o', 'b', 'e'}; + DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; + StreamPrintServiceFactory [] aFactory = StreamPrintServiceFactory + .lookupStreamPrintServiceFactories(flavor, "application/postscript"); + StreamPrintServiceFactory streamFactory = null; + StreamPrintService streamService; + DocPrintJob aJob; + InputStream aStream = + getClass().getResourceAsStream("/Resources/picture.gif"); + Doc doc; + byte [] arr; + boolean flg = true; + + if ((aFactory == null) || (aFactory.length == 0)) { + fail("Can not find stream print service factory!"); + } else { + streamFactory = aFactory[0]; + } + if (aStream == null) { + fail("/Resources/picture.gif resource is not found!"); + } + + streamService = streamFactory.getPrintService(new ByteArrayOutputStream()); + aJob = streamService.createPrintJob(); + doc = new SimpleDoc(aStream, flavor, null); + try { + aJob.print(doc, null); + } catch (Exception e) { + e.printStackTrace(); + fail("Can not print PrintJob!"); + } + arr = ((ByteArrayOutputStream) (streamService.getOutputStream())) + .toByteArray(); + for (int i = 0; i < 10; i++) { + if(arr[i] != forChecking[i]) { + flg = false; + break; + } + } + assertTrue(flg); +} + +public void testHashDocAttributeSet() { + startTest("HashDocAttributeSet class testing..."); + + DocAttributeSet set1 = new HashDocAttributeSet(); + DocAttributeSet set2 = + new HashDocAttributeSet(OrientationRequested.LANDSCAPE); + DocAttributeSet set3 = new HashDocAttributeSet(set2); + DocAttribute [] arr = {OrientationRequested.LANDSCAPE, + MediaName.NA_LETTER_WHITE}; + DocAttributeSet set4 = new HashDocAttributeSet(arr); + Attribute [] attrArr; + + assertTrue(set1.isEmpty()); + assertFalse(set2.isEmpty()); + assertTrue(set3.equals(set2)); + assertFalse(set3.equals(set1)); + set3.clear(); + assertEquals(set3, set1); + set3.add(OrientationRequested.LANDSCAPE); + set3.add(MediaName.NA_LETTER_WHITE); + assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass())); + assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass())); + assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE)); + assertFalse(set3.containsValue(OrientationRequested.PORTRAIT)); + assertFalse(set3.containsValue(PrintQuality.DRAFT)); + assertEquals(set1.size(), 0); + assertEquals(set2.size(), 1); + assertEquals(set3.size(), 2); + assertTrue(set4.equals(set3)); + assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()), + OrientationRequested.LANDSCAPE); + assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass())) + .equals(OrientationRequested.PORTRAIT)); + set1.addAll(set3); + assertEquals(set3, set1); + set1.remove(OrientationRequested.PORTRAIT.getClass()); + assertEquals(set1.size(), 1); + attrArr = set1.toArray(); + assertEquals(attrArr.length, 1); + assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE); +} + +public void testHashPrintJobAttributeSet() { + startTest("HashPrintJobAttributeSet class testing..."); + + PrintJobAttributeSet set1 = new HashPrintJobAttributeSet(); + PrintJobAttributeSet set2 = + new HashPrintJobAttributeSet(OrientationRequested.LANDSCAPE); + PrintJobAttributeSet set3 = new HashPrintJobAttributeSet(set2); + PrintJobAttribute [] arr = {OrientationRequested.LANDSCAPE, + MediaName.NA_LETTER_WHITE}; + PrintJobAttributeSet set4 = new HashPrintJobAttributeSet(arr); + Attribute [] attrArr; + + assertTrue(set1.isEmpty()); + assertFalse(set2.isEmpty()); + assertTrue(set3.equals(set2)); + assertFalse(set3.equals(set1)); + set3.clear(); + assertEquals(set3, set1); + set3.add(OrientationRequested.LANDSCAPE); + set3.add(MediaName.NA_LETTER_WHITE); + assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass())); + assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass())); + assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE)); + assertFalse(set3.containsValue(OrientationRequested.PORTRAIT)); + assertFalse(set3.containsValue(PrintQuality.DRAFT)); + assertEquals(set1.size(), 0); + assertEquals(set2.size(), 1); + assertEquals(set3.size(), 2); + assertTrue(set4.equals(set3)); + assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()), + OrientationRequested.LANDSCAPE); + assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass())) + .equals(OrientationRequested.PORTRAIT)); + set1.addAll(set3); + assertEquals(set3, set1); + set1.remove(OrientationRequested.PORTRAIT.getClass()); + assertEquals(set1.size(), 1); + attrArr = set1.toArray(); + assertEquals(attrArr.length, 1); + assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE); +} + +public void testHashPrintRequestAttributeSet() { + startTest("HashPrintRequestAttributeSet class testing..."); + + Copies copies = new Copies(2); + PrintRequestAttributeSet set1 = new HashPrintRequestAttributeSet(); + PrintRequestAttributeSet set2 = new HashPrintRequestAttributeSet(copies); + PrintRequestAttributeSet set3 = new HashPrintRequestAttributeSet(set2); + PrintRequestAttribute [] arr = {copies, + MediaName.NA_LETTER_WHITE}; + PrintRequestAttributeSet set4 = new HashPrintRequestAttributeSet(arr); + Attribute [] attrArr = set1.toArray(); + + assertTrue(set1.isEmpty()); + assertFalse(set2.isEmpty()); + assertTrue(set3.equals(set2)); + assertFalse(set3.equals(set1)); + set3.clear(); + assertEquals(set3, set1); + set3.add(copies); + set3.add(MediaName.NA_LETTER_WHITE); + assertTrue(set3.containsKey(copies.getClass())); + assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass())); + assertTrue(set3.containsValue(copies)); + assertFalse(set3.containsValue(OrientationRequested.PORTRAIT)); + assertFalse(set3.containsValue(PrintQuality.DRAFT)); + assertEquals(set1.size(), 0); + assertEquals(set2.size(), 1); + assertEquals(set3.size(), 2); + assertTrue(set4.equals(set3)); + assertEquals(set3.get(copies.getClass()), copies); + set1.addAll(set3); + assertEquals(set3, set1); + set1.remove(copies.getClass()); + assertEquals(set1.size(), 1); + attrArr = set1.toArray(); + assertEquals(attrArr.length, 1); + assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE); +} + +public void testHashPrintServiceAttributeSet() { + startTest("HashPrintJobAttributeSet class testing..."); + + PrintServiceAttributeSet set1 = new HashPrintServiceAttributeSet(); + PrintServiceAttributeSet set2 = new HashPrintServiceAttributeSet( + ColorSupported.SUPPORTED); + PrintServiceAttributeSet set3 = new HashPrintServiceAttributeSet(set2); + PrinterLocation location = new PrinterLocation("room 222", Locale.ENGLISH); + PrintServiceAttribute [] arr = { location, + ColorSupported.SUPPORTED }; + PrintServiceAttributeSet set4 = new HashPrintServiceAttributeSet(arr); + + assertTrue(set1.isEmpty()); + assertFalse(set2.isEmpty()); + assertTrue(set3.equals(set2)); + assertFalse(set3.equals(set1)); + set3.clear(); + assertEquals(set3, set1); + set3.add(ColorSupported.SUPPORTED); + set3.add(location); + assertTrue(set3.containsKey(location.getClass())); + assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass())); + assertTrue(set4.equals(set3)); + assertEquals(set3.get(location.getClass()), location); + set1.addAll(set3); + assertEquals(set3, set1); + set1.remove(location.getClass()); + assertEquals(set1.size(), 1); +} + +// --------------------------------------------------------------------------------- +/* +* This function search a PrintService which supports given +* DocFlavor and PrintRequestAttributeSet. +* If default printer supports them, this function returns default printer. +* Overwise it returna first printer from all print services list. +*/ +private PrintService getPrintService(DocFlavor aFlavor, + PrintRequestAttributeSet aSet) +{ + PrintService [] services = + PrintServiceLookup.lookupPrintServices(aFlavor, aSet); + PrintService defaultService = + PrintServiceLookup.lookupDefaultPrintService(); + + if (services.length <= 0) { + System.out.println("Can not find default print service!"); + return null; + } + for (int i = 0; i < services.length; i++) { + if (services[i].equals(defaultService)) { + return services[i]; + } + } + System.out.println( + "System Default PrintService does not support given attributes!"); + return services[0]; +} + +/* + * This functions returns a list of the available printers +*/ +private String[] getPrintServices() { + return (OS.startsWith("Windows") + ? getWindowsPrintServices() + : getLinuxPrintServices()); +} + +/* + * This native function returms Windows printers list + */ +private native String [] getWindowsPrintServices(); + +/* +* This function returns Linus printers list. +* On Linux all CUPS printers are listed on /etc/printcap file +*/ +private String [] getLinuxPrintServices() { + Vector services = new Vector(); + String str = ""; + short state = 0; + char c; + String [] res; + + try { + boolean flg = true; + FileReader reader = new FileReader("/etc/printcap"); + while (flg) { + c = (char) reader.read(); + if (( c <= 0) || (c == 65535)) { + if (state == 2) { + services.add(str); + } + flg = false; + } + switch(state) { + case 0: + if (c == '#') { + state = 1; + } else if (Character.isLetter(c)) { + str = str + c; + state = 2; + } + break; + case 1: + if (c == '\n') { + state = 0; + str = ""; + } + break; + case 2: + if ((c == '|') || (c == '\n') || (c == ' ') || (c == 9)) { + services.add(str); + str = ""; + state = (c == '\n') ? (short) 0 : (short) 1; + } else { + str = str + c; + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + res = new String [services.size()]; + for (int i = 0; i < services.size(); i++) { + res[i] = (String)services.get(i); + } + + return res; +} + +/* + * This function returns system default printer +*/ +private String getDefaultPrintService() { + return OS.startsWith("Windows") + ? getDefaultWindowsPrintService() + : getDefaultLinuxPrintService(); +} + +/* + * This function returns Windows default printer name + */ +private native String getDefaultWindowsPrintService(); + +/* + * This function returns Linux default printer name + * On Linux lpstat -d returns string like the following: + * "system default destination: test" + */ +private String getDefaultLinuxPrintService() { + try { + Process process = Runtime.getRuntime().exec( + "lpstat -d | grep \"system default destination\""); + InputStream iStream; + byte [] res; + String resStr; + + process.waitFor(); + if (process.exitValue() != 0) { + System.out.println("Can not exec \"lpstat -d\""); + return null; + } + iStream = process.getInputStream(); + res = new byte [iStream.available()]; + iStream.read(res); + resStr = new String(res); + if (!resStr.startsWith("system default destination: ")) { + System.out.println( + "WARNING: Can not recognize \"lpstat -d\" output:"); + System.out.println(resStr + "\n"); + return null; + } + // Last symbol in resStr is "\n"! + return resStr.substring(28, resStr.length()-1); + } catch (Exception e) { + e.printStackTrace(); + return null; + } +} + +private void startTest(String s) { + System.out.println("----------------------------------------"); + System.out.println(s); +} +} \ No newline at end of file Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/ValueTests.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/AttributeSetUtilitiesTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/AttributeSetUtilitiesTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/AttributeSetUtilitiesTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/AttributeSetUtilitiesTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,252 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Elena V. Sayapina + * @version $Revision: 1.3 $ + */ + +package javax.print.attribute; + + +import javax.print.Doc; +import javax.print.SimpleDoc; +import javax.print.attribute.standard.ColorSupported; +import javax.print.attribute.standard.Compression; +import javax.print.attribute.standard.Copies; + +import junit.framework.TestCase; + + +public class AttributeSetUtilitiesTest extends TestCase { + + + public static void main(String[] args) { + junit.textui.TestRunner.run(AttributeSetUtilitiesTest.class); + } + + static { + System.out.println("AttributeSetUtilities testing..."); + } + + /* + * verifyAttributeCategory(Object object, Class interfaceName) method testing. + * Tests that method returns the same Class and no exception is thown + * if arguments are valid. + */ + public final void testVerifyAttributeCategory() { + + try { + assertEquals(ColorSupported.class, + AttributeSetUtilities. + verifyAttributeCategory(ColorSupported.class, + PrintServiceAttribute.class)); + } catch (Exception e) { + fail("Unexpected was thrown: " + e.toString()); + } + } + + /* + * verifyAttributeCategory(Object object, Class interfaceName) method testing. + * Tests that method throws ClassCastException if object is not + * a Class that implements interfaceName. + */ + public final void testVerifyAttributeCategory1() { + + try { + AttributeSetUtilities. + verifyAttributeCategory(ColorSupported.class, DocAttribute.class); + fail("metod doesn't throw ClassCastException " + + "if object is not a Class that implements interfaceName"); + } catch (ClassCastException e) { + //System.out.println("testVerifyAttributeCategory1 - " + e.toString()); + } + + } + + /* + * verifyAttributeCategory(Object object, Class interfaceName) method testing. + * Tests that method throws NullPointerException if object is null. + */ + public final void testVerifyAttributeCategory2() { + + try { + Attribute att = null; + AttributeSetUtilities. + verifyAttributeCategory(att, DocAttribute.class); + fail("method doesn't throw NullPointerException if object is null"); + } catch (NullPointerException e) { + //System.out.println("testVerifyAttributeCategory2 - " + e.toString()); + } + + } + + /* + * verifyAttributeCategory(Object object, Class interfaceName) method testing. + * Tests that method throws exeption if object is a Class that implements + * interfaceName but interfaceName is not a class that implements interface + * Attribute. + */ + public final void testVerifyAttributeCategory3() { + + //fails in "some" invironment + //see AttributeSetUtilities, line 337-339 + + try { + AttributeSetUtilities. + verifyAttributeCategory(SimpleDoc.class, Doc.class); + fail("metod doesn't throw ClassCastException if object " + + "is a Class that implements interfaceName but " + + "interfaceName is not a class that implements " + + "interface Attribute"); + } catch (ClassCastException e) { + //System.out.println("testVerifyAttributeCategory3 - " + e.toString()); + } + + } + + + /* + * verifyAttributeValue(Object attribute, Class interfaceName) method testing. + * Tests that method returns object downcasted to type Attribute and no + * exception is thown if arguments are valid. + */ + public final void testVerifyAttributeValue() { + + try { + PrintJobAttribute att = new Copies(10); + assertEquals(att, + AttributeSetUtilities. + verifyAttributeValue(att, PrintJobAttribute.class)); + assertEquals(att, + AttributeSetUtilities. + verifyAttributeValue(att, PrintRequestAttribute.class)); + } catch (Exception e) { + fail("Unexpected was thrown: " + e.toString()); + } + + } + + /* + * verifyAttributeValue(Object attribute, Class interfaceName) method testing. + * Tests that method throws ClassCastException if object isn't an instance + * of interfaceName. + */ + public final void testVerifyAttributeValue1() { + + try { + DocAttribute att = Compression.COMPRESS; + AttributeSetUtilities. + verifyAttributeValue(att, PrintJobAttribute.class); + + } catch (ClassCastException e) { + //System.out.println("testVerifyAttributeValue1 - " + e.toString()); + } + } + + /* + * verifyAttributeValue(Object attribute, Class interfaceName) method testing. + * Tests that method throws NullPointerException if object is null. + */ + public final void testVerifyAttributeValue2() { + + try { + AttributeSetUtilities.verifyAttributeValue(null, DocAttribute.class); + fail("method doesn't throw NullPointerException if object is null"); + } catch (NullPointerException e) { + //System.out.println("testVerifyAttributeValue2 - " + e.toString()); + } + } + + + /* + * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing. + * Tests that method throws no exception if arguments are valid. + */ + public final void testVerifyCategoryForValue() { + + try { + PrintServiceAttribute att = ColorSupported.NOT_SUPPORTED; + AttributeSetUtilities. + verifyCategoryForValue(ColorSupported.class, att); + } catch (Exception e) { + fail("Unexpected was thrown: " + e.toString()); + } + } + + /* + * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing. + * Tests that method throws IllegalArgumentException if the category is + * not equal to the category of the attribute. + */ + public final void testVerifyCategoryForValue1() { + + try { + PrintServiceAttribute att = ColorSupported.NOT_SUPPORTED; + AttributeSetUtilities. + verifyCategoryForValue(DocAttribute.class, att); + fail("method doesn't thrown IllegalArgumentException if the category " + + "is not equal to the category of the attribute."); + } catch (IllegalArgumentException e) { + //System.out.println("testVerifyCategoryForValue1 - " + e.toString()); + } + } + + /* + * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing. + * Tests that method throws NullPointerException if the attribute is null. + */ + public final void testVerifyCategoryForValue2() { + + try { + AttributeSetUtilities.verifyCategoryForValue(DocAttribute.class, null); + fail("method doesn't throw NullPointerException if object is null"); + } catch (NullPointerException e) { + //System.out.println("testVerifyCategoryForValue2 - " + e.toString()); + } + } + + + /* + * unmodifiableView(AttributeSet attributeSet) methods testing. + * Tests that methods provides a client "read-only" access to the created + * unmodifiable view of some attribute set. + */ + public final void testUnmodifiableView() { + + AttributeSet aset = new HashAttributeSet(); + aset = AttributeSetUtilities.unmodifiableView(aset); + try { + aset.add(ColorSupported.SUPPORTED); + aset.addAll(aset); + aset.clear(); + aset.remove(ColorSupported.NOT_SUPPORTED); + aset.remove(ColorSupported.class); + fail("method doesn't throw UnmodifiableSetException if someone" + + "try to modify attribute set"); + } catch (Exception e) { + //System.out.println("testUnmodifiableView - " + e.toString()); + } + } + + + /* + * synchronizedView(AttributeSet attributeSet) methods testing. + */ + public final void testSynchronizedView() { + //To-Do + } + +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/AttributeSetUtilitiesTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/DateTimeSyntaxTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/DateTimeSyntaxTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/DateTimeSyntaxTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/DateTimeSyntaxTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,133 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Elena V. Sayapina + * @version $Revision: 1.3 $ + */ + +package javax.print.attribute; + +import java.util.Date; + +import junit.framework.TestCase; + +public class DateTimeSyntaxTest extends TestCase { + + + public static void main(String[] args) { + junit.textui.TestRunner.run(DateTimeSyntaxTest.class); + } + + static { + System.out.println("DateTimeSyntax testing..."); + } + + private DateTimeSyntax dts1, dts2; + private Date date; + + + /* + * DateTimeSyntax(Date date) constructor testing. + */ + public final void testDateTimeSyntax() { + + date = null; + try { + dts1 = new dateTimeSyntax(date); + fail("DateTimeSyntax(Date date) doesn't throw " + + "NullPointerException if date is null"); + } catch (NullPointerException e) { + + } + } + + /* + * hashCode() method testing. Tests if two object are equal they must have + * the same hash code. + */ + public final void testHashCode() { + date = new Date((long) Math.pow(10, 12)); + dts1 = new dateTimeSyntax(date); + dts2 = new dateTimeSyntax(date); + assertTrue(dts1.hashCode() == dts2.hashCode()); + } + + /* + * hashCode() method testing. Tests if two object aren't equal they should + * have different hash codes. + */ + public final void testHashCode1() { + date = new Date((long) Math.pow(10, 12)); + dts1 = new dateTimeSyntax(date); + date = new Date(); + dts2 = new dateTimeSyntax(date); + assertFalse(dts1.hashCode() == dts2.hashCode()); + } + + /* + * equals(Object object) method testing. Tests if two DateTimeSyntax + * objects aren't equal equals() return false. + */ + public final void testEquals() { + + date = new Date((long) Math.pow(10, 12)); + dts1 = new dateTimeSyntax(date); + date = new Date((long) Math.pow(10, 12)-1); + dts2 = new dateTimeSyntax(date); + assertFalse(dts1.equals(dts2)); + + + dts2 = null; + assertFalse(dts1.equals(dts2)); + } + + /* + * equals(Object object) method testing. Tests if two DateTimeSyntax + * objects are equal equals() return true. + */ + public final void testEquals1() { + + date = new Date(); + dts1 = new dateTimeSyntax(date); + dts2 = new dateTimeSyntax(date); + assertTrue(dts1.equals(dts2)); + } + + /* + * getValue() method testing. + */ + public final void testGetValue() { + date = new Date(); + dts1 = new dateTimeSyntax(date); + assertEquals(date, dts1.getValue()); + + date = new Date((long) Math.pow(10, 12)); + dts2 = new dateTimeSyntax(date); + assertEquals(date, dts2.getValue()); + } + + /* + * Auxiliary class + */ + public class dateTimeSyntax extends DateTimeSyntax { + + public dateTimeSyntax(Date value) { + super(value); + } + } + + +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/DateTimeSyntaxTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/EnumSyntaxTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/EnumSyntaxTest.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/EnumSyntaxTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/EnumSyntaxTest.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,185 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Elena V. Sayapina + * @version $Revision: 1.3 $ + */ + +package javax.print.attribute; + +import java.io.ObjectStreamException; + +import junit.framework.TestCase; + +public class EnumSyntaxTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(EnumSyntaxTest.class); + } + + static { + System.out.println("EnumSyntax testing..."); + } + + enumSyntax es; + ExtendEnumSyntax ees; + + /* + * clone() method testing. + */ + public void testClone() { + es = new enumSyntax(10); + Object es2 = es.clone(); + assertEquals(es2, es); + } + + + /* + * getEnumValueTable() method testing. + * Tests that getEnumValueTable() returns null as a default. + */ + public void testGetEnumValueTable() { + es = new enumSyntax(10); + EnumSyntax[] esyntax = es.getEnumValueTableEx(); + assertNull(esyntax); + } + + + /* + * getOffset() method testing. + * Tests that getOffset() returns 0 as a default. + */ + public void testGetOffset() { + es = new enumSyntax(10); + int i = es.getOffsetEx(); + assertEquals(0, i); + } + + + /* + * getStringTable() method testing. + * Tests that GetStringTable() returns null as a default. + */ + public void testGetStringTable() { + es = new enumSyntax(10); + String[] str = es.getStringTableEx(); + assertNull(str); + } + + + /* + * getValue() method testing. + * Tests that getValue() returns this enumeration value's integer value. + */ + public void testGetValue() { + es = new enumSyntax(10); + int i = es.getValue(); + assertEquals(10, i); + } + + + /* + * hashCode() method testing. + * Tests that hash code is this enumeration value's integer value. + */ + public void testHashCode() { + es = new enumSyntax(0); + int i = es.hashCode(); + assertEquals(0, i); + } + + /* + * readResolve() method testing. + */ + public void testReadResolve() { + ees = new ExtendEnumSyntax(1); + try { + ees.readResolveEx(); + fail("readResolve() doesn't throw InvalidObjectException if" + + "enumeration value table is null"); + } catch (ObjectStreamException e) { + //System.out.println(e); + } + } + + /* + * readResolve() method testing. + */ + public void testReadResolve1() { + ees = new ExtendEnumSyntax(3); + try { + ees.readResolveEx(); + fail("readResolve() doesn't throw InvalidObjectException if" + + "integer value doesn't have corresponding enumeration value"); + } catch (ObjectStreamException e) { + //System.out.println(e); + } + } + + /* + * readResolve() method testing. + */ + public void testReadResolve2() { + ees = new ExtendEnumSyntax(2); + try { + ees.readResolveEx(); + fail("readResolve() doesn't throw InvalidObjectException if" + + "enumeration value is null"); + } catch (ObjectStreamException e) { + //System.out.println(e); + } + } + + /* + * toString() method testing. + * Tests that if there is no string value corresponding to this enumeration + * value toString() returns string contains this enumeration value. + */ + public void testToString() { + try { + ees = new ExtendEnumSyntax(2); + assertEquals("2", ees.toString()); + es = new enumSyntax(10); + assertEquals("10", es.toString()); + } catch (Exception e) { + fail("toString() throws an exception"); + } + } + + /* + * Auxiliary class + */ + protected class enumSyntax extends EnumSyntax { + + public enumSyntax(int value) { + super(value); + } + + public EnumSyntax[] getEnumValueTableEx() { + return getEnumValueTable(); + } + + public String[] getStringTableEx() { + return getStringTable(); + } + + public int getOffsetEx() { + return getOffset(); + } + } + + +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/EnumSyntaxTest.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/ExtendEnumSyntax.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/ExtendEnumSyntax.java?view=auto&rev=454289 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/ExtendEnumSyntax.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/ExtendEnumSyntax.java Sun Oct 8 22:33:09 2006 @@ -0,0 +1,48 @@ +/* + * Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Elena V. Sayapina + * @version $Revision: 1.3 $ + */ + +package javax.print.attribute; + +import java.io.ObjectStreamException; + +/* + * Auxiliary class for EnumSyntax unit test + */ +public final class ExtendEnumSyntax extends EnumSyntax { + + public ExtendEnumSyntax(int value) { + super(value); + } + + public static final ExtendEnumSyntax ENUM1 = new ExtendEnumSyntax(0); + public static final ExtendEnumSyntax ENUM2 = new ExtendEnumSyntax(1); + + + public final EnumSyntax[] enumValueTable = { ENUM1, + null}; + + public final String[] stringTable = { "str1", + null }; + + public Object readResolveEx() throws ObjectStreamException { + return readResolve(); + } + +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/attribute/ExtendEnumSyntax.java ------------------------------------------------------------------------------ svn:executable = *