Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions test/jdk/javax/print/PrintServiceLookup/CountPrintServices.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,33 +25,38 @@
import java.io.InputStreamReader;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;
import javax.print.attribute.standard.PrinterName;
import java.io.IOException;

import jtreg.SkippedException;

/*
* @test
* @bug 8032693
* @key printer
* @library /test/lib/
* @requires (os.family == "linux")
* @summary Test that lpstat and JDK agree whether there are printers.
*/
public class CountPrintServices {

public static void main(String[] args) throws Exception {
String os = System.getProperty("os.name").toLowerCase();
System.out.println("OS is " + os);
if (!os.equals("linux")) {
System.out.println("Linux specific test. No need to continue");
return;
}
PrintService services[] =
PrintServiceLookup.lookupPrintServices(null, null);
if (services.length > 0) {
System.out.println("Services found. No need to test further.");
return;
}
String[] lpcmd = { "lpstat", "-a" };
Process proc = Runtime.getRuntime().exec(lpcmd);
Process proc;
try {
proc = Runtime.getRuntime().exec(lpcmd);
} catch (IOException e) {
if (e.getMessage().contains("No such file or directory")) {
throw new SkippedException("Cannot find lpstat");
} else {
throw e;
}
}
proc.waitFor();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
BufferedReader br = new BufferedReader(ir);
Expand All @@ -66,4 +71,3 @@ public static void main(String[] args) throws Exception {
}
}
}