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