Path: blob/master/test/jdk/java/lang/ClassLoader/LibraryPathProperty.java
41152 views
/*1* Copyright (c) 2015, 2020, 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 8067951 823607526* @summary Unit test for internal ClassLoaderHelper#parsePath().27* Quoted entries should get unquoted on Windows.28* Empty entries should be replaced with dot.29* @library /test/lib30* @modules java.base/jdk.internal.loader:open31* @build jdk.test.lib.Platform32* @run main LibraryPathProperty33*/3435import java.lang.reflect.Method;36import java.io.File;37import java.util.Arrays;38import jdk.test.lib.Platform;3940public class LibraryPathProperty {4142static final String SP = File.pathSeparator;43static Method method;4445public static void main(String[] args) throws Throwable {46Class<?> klass = Class.forName("jdk.internal.loader.ClassLoaderHelper");47method = klass.getDeclaredMethod("parsePath", String.class);48method.setAccessible(true);4950test("", ".");51test(SP, ".", ".");52test("a" + SP, "a", ".");53test(SP + "b", ".", "b");54test("a" + SP + SP + "b", "a", ".", "b");5556if (Platform.isWindows()) {57// on Windows parts of paths may be quoted58test("\"\"", ".");59test("\"\"" + SP, ".", ".");60test(SP + "\"\"", ".", ".");61test("a" + SP + "\"b\"" + SP, "a", "b", ".");62test(SP + "\"a\"" + SP + SP + "b", ".", "a", ".", "b");63test("\"a\"" + SP + "\"b\"", "a", "b");64test("\"/a/\"b" + SP + "c", "/a/b", "c");65test("\"/a;b\"" + SP + "c", "/a;b", "c");66test("\"/a:b\"" + SP + "c", "/a:b", "c");67test("\"/a" + SP + "b\"" + SP + "c", "/a" + SP + "b", "c");68test("/\"a\"\";\"\"b\"" + SP + "\"c\"", "/a;b", "c");69test("/\"a:\"b" + SP + "c", "/a:b", "c");70}71}7273static void test(String s, String... expected) throws Throwable {74String[] res = (String[])method.invoke(null, s);75if (!Arrays.asList(res).equals(Arrays.asList(expected))) {76throw new RuntimeException("Parsing [" + s + "] " +77" result " + Arrays.asList(res) +78" doesn't match " + Arrays.asList(expected));79}80}81}828384