tests/libjava-mauve/src/gnu/testlet/javax/naming/CompositeName/composite.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Simple tests of CompositeName.
       
     2 
       
     3 // Copyright (C) 2001 Red Hat, Inc.
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.
       
    21 
       
    22 // Tags: JDK1.3
       
    23 
       
    24 package gnu.testlet.javax.naming.CompositeName;
       
    25 
       
    26 import gnu.testlet.Testlet;
       
    27 import gnu.testlet.TestHarness;
       
    28 import javax.naming.*;
       
    29 
       
    30 public class composite implements Testlet
       
    31 {
       
    32   public void add (CompositeName n, String what)
       
    33   {
       
    34     // We always check the result of the add so we can just ignore the
       
    35     // exception.
       
    36     try
       
    37       {
       
    38 	n.add (what);
       
    39       }
       
    40     catch (InvalidNameException _)
       
    41       {
       
    42       }
       
    43   }
       
    44 
       
    45   public void remove (CompositeName n, int pos)
       
    46   {
       
    47     // We always check the result of the remove so we can just ignore the
       
    48     // exception.
       
    49     try
       
    50       {
       
    51 	n.remove (pos);
       
    52       }
       
    53     catch (InvalidNameException _)
       
    54       {
       
    55       }
       
    56   }
       
    57 
       
    58   public void test (TestHarness harness)
       
    59   {
       
    60     try
       
    61       {
       
    62 	CompositeName cn1 = new CompositeName ();
       
    63 	CompositeName cn2 = new CompositeName ("");
       
    64 
       
    65 	// There are plenty of empty checks.
       
    66 	harness.check (cn1.toString (), "", "empty CompositeName");
       
    67 	harness.check (cn2.toString (), "");
       
    68 	harness.check (cn1, cn2);
       
    69 	harness.check (cn1.isEmpty ());
       
    70 	harness.check (cn2.isEmpty ());
       
    71 	harness.check (cn1.size (), 0);
       
    72 	harness.check (cn2.size (), 0);
       
    73 	harness.check (cn1.startsWith (cn2));
       
    74 	harness.check (cn2.startsWith (cn1));
       
    75 
       
    76 	add (cn1, "x");
       
    77 	harness.check (! cn1.isEmpty (), "`x' CompositeName");
       
    78 	harness.check (cn1.size (), 1);
       
    79 	harness.check (cn1.get (0), "x");
       
    80 	harness.check (cn1.toString (), "x");
       
    81 
       
    82 	add (cn1, "y");
       
    83 	harness.check (cn1.size (), 2, "`x/y' CompositeName");
       
    84 	harness.check (cn1.get (0), "x");
       
    85 	harness.check (cn1.get (1), "y");
       
    86 	harness.check (cn1.toString (), "x/y");
       
    87 
       
    88 	add (cn2, "");
       
    89 	harness.check (cn2.size (), 1, "`/' CompositeName");
       
    90 	harness.check (cn2.toString (), "/");
       
    91 
       
    92 	add (cn2, "x");
       
    93 	harness.check (cn2.size (), 2, "`/x' CompositeName");
       
    94 	harness.check (cn2.toString (), "/x");
       
    95 
       
    96 	add (cn2, "");
       
    97 	harness.check (cn2.size (), 3, "`/x/' CompositeName");
       
    98 	harness.check (cn2.toString (), "/x/");
       
    99 
       
   100 	add (cn2, "y");
       
   101 	harness.check (cn2.size (), 4, "`/x//y' CompositeName");
       
   102 	harness.check (cn2.toString (), "/x//y");
       
   103 
       
   104 	remove (cn2, 2);
       
   105 	remove (cn2, 0);
       
   106 	harness.check (cn2.size (), 2, "`x/y' CompositeName by removal");
       
   107 	harness.check (cn2.toString (), "x/y");
       
   108 	harness.check (cn1, cn2);
       
   109 
       
   110 	add (cn1, "foo/bar");
       
   111 	harness.check (cn1.size (), 3, "quoting rule");
       
   112 	cn2 = new CompositeName (cn1.toString ());
       
   113 	harness.check (cn2.size (), 3, "parsing with quoting");
       
   114 	harness.check (cn2.get (2), "foo/bar");
       
   115 	harness.check (cn1, cn2);
       
   116 
       
   117 	cn2 = new CompositeName ("x/y/foo\\/bar");
       
   118 	harness.check (cn1, cn2, "more parsing with quoting");
       
   119 	cn2 = new CompositeName ("x/y/\"foo/bar\"");
       
   120 	harness.check (cn1, cn2);
       
   121 
       
   122 	cn1 = new CompositeName ("//");
       
   123 	harness.check (cn1.size (), 2, "parsing `//'");
       
   124 	harness.check (cn1.get (0), "");
       
   125 	harness.check (cn1.get (1), "");
       
   126       }
       
   127     catch (NamingException _)
       
   128       {
       
   129 	harness.debug (_);
       
   130 	harness.fail ("NamingException caught");
       
   131       }
       
   132   }
       
   133 }