jdk/test/javax/print/PrintServiceLookup/GetPrintServices.java
author jgodinez
Fri, 07 Jun 2013 10:26:29 -0700
changeset 18115 dbd9791b69d2
child 42737 b37da02bd6c1
permissions -rw-r--r--
8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result Reviewed-by: prr, jgodinez Contributed-by: patrick@reini.net
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18115
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     1
/*
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     4
 *
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     8
 *
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    13
 * accompanied this code).
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    14
 *
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    18
 *
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    21
 * questions.
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    22
 */
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    23
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    24
import javax.print.PrintService;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    25
import javax.print.PrintServiceLookup;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    26
import javax.print.attribute.AttributeSet;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    27
import javax.print.attribute.HashAttributeSet;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    28
import javax.print.attribute.standard.PrinterName;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    29
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    30
/*
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    31
 * @test
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    32
 * @bug 8013810
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    33
 * @summary Test that print service returned without filter are of the same class as with name filter
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    34
 */
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    35
public class GetPrintServices {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    36
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    37
  public static void main(String[] args) throws Exception {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    38
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    39
      String serviceName = service.getName();
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    40
      PrintService serviceByName = lookupByName(serviceName);
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    41
      if (!service.equals(serviceByName)) {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    42
        throw new RuntimeException("NOK " + serviceName
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    43
                                   + " expected: " + service.getClass().getName()
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    44
                                   + " got: " + serviceByName.getClass().getName());
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    45
      }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    46
    }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    47
    System.out.println("Test PASSED");
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    48
  }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    49
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    50
  private static PrintService lookupByName(String name) {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    51
    AttributeSet attributes = new HashAttributeSet();
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    52
    attributes.add(new PrinterName(name, null));
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    53
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    54
      return service;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    55
    }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    56
    return null;
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    57
  }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    58
}