test/jdk/javax/print/PrintServiceLookup/CountPrintServices.java
author coleenp
Mon, 30 Sep 2019 13:10:11 -0400
changeset 58409 a595e67d6683
parent 49096 eaef201ec301
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:
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     1
/*
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     4
 *
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     8
 *
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    13
 * accompanied this code).
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    14
 *
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    18
 *
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    21
 * questions.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    22
 */
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    23
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    24
import java.io.BufferedReader;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    25
import java.io.InputStreamReader;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    26
import javax.print.PrintService;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    27
import javax.print.PrintServiceLookup;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    28
import javax.print.attribute.AttributeSet;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    29
import javax.print.attribute.HashAttributeSet;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    30
import javax.print.attribute.standard.PrinterName;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    31
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    32
/*
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    33
 * @test
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    34
 * @bug 8032693
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    35
 * @key printer
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    36
 * @summary Test that lpstat and JDK agree whether there are printers.
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    37
 */
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    38
public class CountPrintServices {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    39
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    40
  public static void main(String[] args) throws Exception {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    41
    String os = System.getProperty("os.name").toLowerCase();
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    42
    System.out.println("OS is " + os);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    43
    if (!os.equals("linux")) {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    44
        System.out.println("Linux specific test. No need to continue");
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    45
        return;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    46
    }
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    47
    PrintService services[] =
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    48
        PrintServiceLookup.lookupPrintServices(null, null);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    49
    if (services.length > 0) {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    50
       System.out.println("Services found. No need to test further.");
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    51
       return;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    52
    }
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    53
    String[] lpcmd = { "lpstat", "-a" };
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    54
    Process proc = Runtime.getRuntime().exec(lpcmd);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    55
    proc.waitFor();
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    56
    InputStreamReader ir = new InputStreamReader(proc.getInputStream());
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    57
    BufferedReader br = new BufferedReader(ir);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    58
    int count = 0;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    59
    String printer;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    60
    while ((printer = br.readLine()) != null) {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    61
       System.out.println("lpstat:: " + printer);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    62
       count++;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    63
    }
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    64
    if (count > 0) {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    65
        throw new RuntimeException("Services exist, but not found by JDK.");
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    66
    }
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    67
 }
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    68
}
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
diff changeset
    69