1 /* @test
   2  * @bug 4238914
   3  * @summary Tests that JNDI/COS naming parser supports the syntax
   4  * defined in the new INS standard.
   5  */
   6 
   7 import javax.naming.*;
   8 
   9 public class CNNameParser {
  10 
  11     public static void main(String[] args) throws Exception {
  12 
  13         NameParser parser = new com.sun.jndi.cosnaming.CNNameParser();
  14 
  15         for (int i = 0; i < compounds.length; i++) {
  16             checkCompound(parser, compounds[i], compoundComps[i]);
  17         }
  18     }
  19 
  20     private static void checkName(Name name, String[] comps) throws Exception {
  21         if (name.size() != comps.length) {
  22             throw new Exception(
  23                 "test failed; incorrect component count in " + name + "; " +
  24                 "expecting " + comps.length + " got " + name.size());
  25         }
  26         for (int i = 0; i < name.size(); i++) {
  27             if (!comps[i].equals(name.get(i))) {
  28                 throw new Exception (
  29                     "test failed; invalid component in " + name + "; " +
  30                     "expecting '" + comps[i] + "' got '" + name.get(i) + "'");
  31             }
  32         }
  33     }
  34 
  35     private static void checkCompound(NameParser parser,
  36         String input, String[] comps) throws Exception {
  37         checkName(parser.parse(input), comps);
  38     }
  39 
  40     private static final String[] compounds = {
  41         "a/b/c",
  42         "a.b/c.d",
  43         "a",
  44         ".",
  45         "a.",
  46         "c.d",
  47         ".e",
  48         "a/x\\/y\\/z/b",
  49         "a\\.b.c\\.d/e.f",
  50         "a/b\\\\/c",
  51         "x\\\\.y",
  52         "x\\.y",
  53         "x.\\\\y",
  54         "x.y\\\\",
  55         "\\\\x.y",
  56         "a.b\\.c/d"
  57     };
  58 
  59     private static final String[][] compoundComps = {
  60         {"a", "b", "c"},
  61         {"a.b", "c.d"},
  62         {"a"},
  63         {"."},
  64         {"a"},
  65         {"c.d"},
  66         {".e"},
  67         {"a", "x\\/y\\/z", "b"},
  68         {"a\\.b.c\\.d", "e.f"},
  69         {"a", "b\\\\", "c"},
  70         {"x\\\\.y"},
  71         {"x\\.y"},
  72         {"x.\\\\y"},
  73         {"x.y\\\\"},
  74         {"\\\\x.y"},
  75         {"a.b\\.c", "d"},
  76     };
  77 }