0N/A/* @test
0N/A * @bug 4238914
0N/A * @summary Tests that JNDI/COS naming parser supports the syntax
0N/A * defined in the new INS standard.
0N/A */
0N/A
0N/Aimport javax.naming.*;
0N/A
0N/Apublic class CNNameParser {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A NameParser parser = new com.sun.jndi.cosnaming.CNNameParser();
0N/A
0N/A for (int i = 0; i < compounds.length; i++) {
0N/A checkCompound(parser, compounds[i], compoundComps[i]);
0N/A }
0N/A }
0N/A
0N/A private static void checkName(Name name, String[] comps) throws Exception {
0N/A if (name.size() != comps.length) {
0N/A throw new Exception(
0N/A "test failed; incorrect component count in " + name + "; " +
0N/A "expecting " + comps.length + " got " + name.size());
0N/A }
0N/A for (int i = 0; i < name.size(); i++) {
0N/A if (!comps[i].equals(name.get(i))) {
0N/A throw new Exception (
0N/A "test failed; invalid component in " + name + "; " +
0N/A "expecting '" + comps[i] + "' got '" + name.get(i) + "'");
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static void checkCompound(NameParser parser,
0N/A String input, String[] comps) throws Exception {
0N/A checkName(parser.parse(input), comps);
0N/A }
0N/A
0N/A private static final String[] compounds = {
0N/A "a/b/c",
0N/A "a.b/c.d",
0N/A "a",
0N/A ".",
0N/A "a.",
0N/A "c.d",
0N/A ".e",
0N/A "a/x\\/y\\/z/b",
0N/A "a\\.b.c\\.d/e.f",
0N/A "a/b\\\\/c",
0N/A "x\\\\.y",
0N/A "x\\.y",
0N/A "x.\\\\y",
0N/A "x.y\\\\",
0N/A "\\\\x.y",
0N/A "a.b\\.c/d"
0N/A };
0N/A
0N/A private static final String[][] compoundComps = {
0N/A {"a", "b", "c"},
0N/A {"a.b", "c.d"},
0N/A {"a"},
0N/A {"."},
0N/A {"a"},
0N/A {"c.d"},
0N/A {".e"},
0N/A {"a", "x\\/y\\/z", "b"},
0N/A {"a\\.b.c\\.d", "e.f"},
0N/A {"a", "b\\\\", "c"},
0N/A {"x\\\\.y"},
0N/A {"x\\.y"},
0N/A {"x.\\\\y"},
0N/A {"x.y\\\\"},
0N/A {"\\\\x.y"},
0N/A {"a.b\\.c", "d"},
0N/A };
0N/A}