Skip to content

Commit f60d8f8

Browse files
author
SendaoYan
committed
8366359: Test should throw SkippedException when there is no lpstat
Backport-of: f23c150709fbd6d9b84261a7c99b67d7d08334b9
1 parent e1a1027 commit f60d8f8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

test/jdk/javax/print/PrintServiceLookup/CountPrintServices.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,33 +25,38 @@
2525
import java.io.InputStreamReader;
2626
import javax.print.PrintService;
2727
import javax.print.PrintServiceLookup;
28-
import javax.print.attribute.AttributeSet;
29-
import javax.print.attribute.HashAttributeSet;
30-
import javax.print.attribute.standard.PrinterName;
28+
import java.io.IOException;
29+
30+
import jtreg.SkippedException;
3131

3232
/*
3333
* @test
3434
* @bug 8032693
3535
* @key printer
36+
* @library /test/lib/
37+
* @requires (os.family == "linux")
3638
* @summary Test that lpstat and JDK agree whether there are printers.
3739
*/
3840
public class CountPrintServices {
3941

4042
public static void main(String[] args) throws Exception {
41-
String os = System.getProperty("os.name").toLowerCase();
42-
System.out.println("OS is " + os);
43-
if (!os.equals("linux")) {
44-
System.out.println("Linux specific test. No need to continue");
45-
return;
46-
}
4743
PrintService services[] =
4844
PrintServiceLookup.lookupPrintServices(null, null);
4945
if (services.length > 0) {
5046
System.out.println("Services found. No need to test further.");
5147
return;
5248
}
5349
String[] lpcmd = { "lpstat", "-a" };
54-
Process proc = Runtime.getRuntime().exec(lpcmd);
50+
Process proc;
51+
try {
52+
proc = Runtime.getRuntime().exec(lpcmd);
53+
} catch (IOException e) {
54+
if (e.getMessage().contains("No such file or directory")) {
55+
throw new SkippedException("Cannot find lpstat");
56+
} else {
57+
throw e;
58+
}
59+
}
5560
proc.waitFor();
5661
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
5762
BufferedReader br = new BufferedReader(ir);
@@ -66,4 +71,3 @@ public static void main(String[] args) throws Exception {
6671
}
6772
}
6873
}
69-

0 commit comments

Comments
 (0)