test/jdk/javax/print/PrintServiceLookup/GetPrintServices.java
author coleenp
Mon, 30 Sep 2019 13:10:11 -0400
changeset 58409 a595e67d6683
parent 47216 71c04702a3d5
permissions -rw-r--r--
8184732: Deadlock detection improvements for 'special' locks Summary: Assert that special ranked locks cannot safepoint and allow_vm_block and remove locks from the exceptional lock list in no_safepoint_verifier. Reviewed-by: dholmes, eosterlund
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
/*
42737
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
18115
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
42737
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    32
 * @bug 8013810 8025439
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    33
 * @summary Test that print service returned without filter are of the same class
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    34
 *          as with name filter
18115
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    35
 */
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    36
public class GetPrintServices {
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    37
42737
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    38
    public static void main(String[] args) throws Exception {
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    39
        for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    40
            String serviceName = service.getName();
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    41
            PrinterName name = service.getAttribute(PrinterName.class);
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    42
            String printerName = name.getValue();
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    43
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    44
            PrintService serviceByName = lookupByName(printerName);
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    45
            System.out.println("service " + service);
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    46
            System.out.println("serviceByName " + serviceByName);
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    47
            if (!service.equals(serviceByName)) {
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    48
                throw new RuntimeException("NOK " + serviceName
18115
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    49
                                   + " expected: " + service.getClass().getName()
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    50
                                   + " got: " + serviceByName.getClass().getName());
42737
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    51
            }
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    52
        }
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    53
        System.out.println("Test PASSED");
18115
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    54
    }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    55
42737
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    56
    private static PrintService lookupByName(String name) {
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    57
        AttributeSet attributes = new HashAttributeSet();
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    58
        attributes.add(new PrinterName(name, null));
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    59
        for (PrintService service :
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    60
             PrintServiceLookup.lookupPrintServices(null, attributes)) {
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    61
            return service;
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    62
        }
b37da02bd6c1 8025439: [TEST BUG] [macosx] PrintServiceLookup.lookupPrintServices doesn't work properly since jdk8b105
psadhukhan
parents: 18115
diff changeset
    63
        return null;
18115
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    64
    }
dbd9791b69d2 8013810: PrintServiceLookup.lookupPrintServices() does not return consistent result
jgodinez
parents:
diff changeset
    65
}