Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Console/CharsetTest.java
41149 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.Console;
25
import java.nio.file.Files;
26
import java.nio.file.Paths;
27
28
import jdk.test.lib.process.OutputAnalyzer;
29
import jdk.test.lib.process.ProcessTools;
30
31
/**
32
* @test
33
* @bug 8264208 8265918
34
* @summary Tests Console.charset() method. "expect" command in Windows/Cygwin
35
* does not work as expected. Ignoring tests on Windows.
36
* @requires (os.family == "linux") | (os.family == "mac")
37
* @library /test/lib
38
* @run main CharsetTest en_US.ISO8859-1 ISO-8859-1
39
* @run main CharsetTest en_US.US-ASCII US-ASCII
40
* @run main CharsetTest en_US.UTF-8 UTF-8
41
*/
42
public class CharsetTest {
43
public static void main(String... args) throws Throwable {
44
if (args.length == 0) {
45
// no arg means child java process being tested.
46
Console con = System.console();
47
System.out.println(con.charset());
48
return;
49
} else {
50
// check "expect" command availability
51
var expect = Paths.get("/usr/bin/expect");
52
if (!Files.exists(expect) || !Files.isExecutable(expect)) {
53
System.out.println("'expect' command not found. Test ignored.");
54
return;
55
}
56
57
// invoking "expect" command
58
var testSrc = System.getProperty("test.src", ".");
59
var testClasses = System.getProperty("test.classes", ".");
60
var jdkDir = System.getProperty("test.jdk");
61
OutputAnalyzer output = ProcessTools.executeProcess(
62
"expect",
63
"-n",
64
testSrc + "/script.exp",
65
jdkDir + "/bin/java",
66
args[0],
67
args[1],
68
testClasses);
69
output.reportDiagnosticSummary();
70
var eval = output.getExitValue();
71
if (eval != 0) {
72
throw new RuntimeException("Test failed. Exit value from 'expect' command: " + eval);
73
}
74
}
75
}
76
}
77
78