Path: blob/master/test/jdk/java/nio/charset/spi/CharsetProviderBasicTest.java
41152 views
/*1* Copyright (c) 2017, 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*/2223/*24* @test25* @bug 4429040 4591027 481474326* @summary Unit test for charset providers27* @library /test/lib28* @build jdk.test.lib.Utils29* jdk.test.lib.Asserts30* jdk.test.lib.JDKToolFinder31* jdk.test.lib.JDKToolLauncher32* jdk.test.lib.Platform33* jdk.test.lib.process.*34* jdk.test.lib.util.JarUtils35* FooCharset FooProvider CharsetTest36* @run driver SetupJar37* @run testng CharsetProviderBasicTest38*/3940import java.io.File;41import java.util.ArrayList;42import java.util.Iterator;43import java.util.List;44import java.util.stream.Stream;4546import jdk.test.lib.JDKToolFinder;47import jdk.test.lib.Utils;48import jdk.test.lib.process.ProcessTools;4950import org.testng.annotations.DataProvider;51import org.testng.annotations.Test;5253import static java.util.Arrays.asList;5455public class CharsetProviderBasicTest {5657private static final String TEST_SRC = System.getProperty("test.src");5859private static final List DEFAULT_CSS = List.of(60"US-ASCII", "8859_1", "iso-ir-6", "UTF-16", "windows-1252", "!BAR", "cp1252"61);6263private static final List MINIMAL_POLICY = List.of(64"-Djava.security.manager",65"-Djava.security.policy=" + TEST_SRC + File.separator + "default-pol"66);6768private static final List CP_POLICY = List.of(69"-Djava.security.manager",70"-Djava.security.policy=" + TEST_SRC + File.separator + "charsetProvider.sp"71);7273private static boolean checkSupports(String locale) throws Throwable {74return ProcessTools.executeProcess("sh", "-c", "LC_ALL=" + locale + " && "75+ "locale -a | grep " + locale)76.getStdout()77.replace(System.lineSeparator(), "")78.equals(locale);79}8081@DataProvider82public static Iterator<Object[]> testCases() {83return Stream.of("", "ja_JP.eucJP", "tr_TR")84.flatMap(locale -> Stream.of(85new Object[]{locale, List.of(""), "FOO"},86new Object[]{locale, MINIMAL_POLICY, "!FOO"},87new Object[]{locale, CP_POLICY, "FOO"}88))89.iterator();90}9192@Test(dataProvider = "testCases")93public void testDefaultCharset(String locale, List opts, String css) throws Throwable {94if ((System.getProperty("os.name").startsWith("Windows") || !checkSupports(locale))95&& (!locale.isEmpty())) {96System.out.println(locale + ": Locale not supported, skipping...");97return;98}99100List<String> args = new ArrayList<>();101args.add(JDKToolFinder.getJDKTool("java"));102args.addAll(asList(Utils.getTestJavaOpts()));103args.add("-cp");104args.add(System.getProperty("test.class.path") + File.pathSeparator + "test.jar");105args.addAll(opts);106args.add(CharsetTest.class.getName());107args.addAll(DEFAULT_CSS);108args.add(css);109args.removeIf(t -> t.isEmpty());110111ProcessBuilder pb = new ProcessBuilder(args);112113if (!locale.isEmpty()) {114pb.environment().put("LC_ALL", locale);115}116117ProcessTools.executeCommand(pb)118.shouldHaveExitValue(0);119}120}121122123