Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jndi/cosnaming/CNNameParser.java
38855 views
/*1* Copyright (c) 2007, 2013, 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/* @test24* @bug 423891425* @summary Tests that JNDI/COS naming parser supports the syntax26* defined in the new INS standard.27*/2829import javax.naming.*;3031public class CNNameParser {3233public static void main(String[] args) throws Exception {3435NameParser parser = new com.sun.jndi.cosnaming.CNNameParser();3637for (int i = 0; i < compounds.length; i++) {38checkCompound(parser, compounds[i], compoundComps[i]);39}40}4142private static void checkName(Name name, String[] comps) throws Exception {43if (name.size() != comps.length) {44throw new Exception(45"test failed; incorrect component count in " + name + "; " +46"expecting " + comps.length + " got " + name.size());47}48for (int i = 0; i < name.size(); i++) {49if (!comps[i].equals(name.get(i))) {50throw new Exception (51"test failed; invalid component in " + name + "; " +52"expecting '" + comps[i] + "' got '" + name.get(i) + "'");53}54}55}5657private static void checkCompound(NameParser parser,58String input, String[] comps) throws Exception {59checkName(parser.parse(input), comps);60}6162private static final String[] compounds = {63"a/b/c",64"a.b/c.d",65"a",66".",67"a.",68"c.d",69".e",70"a/x\\/y\\/z/b",71"a\\.b.c\\.d/e.f",72"a/b\\\\/c",73"x\\\\.y",74"x\\.y",75"x.\\\\y",76"x.y\\\\",77"\\\\x.y",78"a.b\\.c/d"79};8081private static final String[][] compoundComps = {82{"a", "b", "c"},83{"a.b", "c.d"},84{"a"},85{"."},86{"a"},87{"c.d"},88{".e"},89{"a", "x\\/y\\/z", "b"},90{"a\\.b.c\\.d", "e.f"},91{"a", "b\\\\", "c"},92{"x\\\\.y"},93{"x\\.y"},94{"x.\\\\y"},95{"x.y\\\\"},96{"\\\\x.y"},97{"a.b\\.c", "d"},98};99}100101102