directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r664290 [13/13] - in /directory/shared/branches/bigbang: ./ asn1/src/main/java/org/apache/directory/shared/asn1/ asn1/src/main/java/org/apache/directory/shared/asn1/ber/ asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/ asn1/...
Date Sat, 07 Jun 2008 06:28:15 GMT
Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SchemaParserTestUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SchemaParserTestUtils.java?rev=664290&r1=664289&r2=664290&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SchemaParserTestUtils.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SchemaParserTestUtils.java
Fri Jun  6 23:28:06 2008
@@ -36,7 +36,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SchemaParserTestUtils 
+public class SchemaParserTestUtils
 {
 
     /**
@@ -74,34 +74,42 @@
         }
 
         // simple
-        value = "( 0.1.2.3.4.5.6.7.8.9 "+required+" )";
+        value = "( 0.1.2.3.4.5.6.7.8.9 " + required + " )";
         asd = parser.parse( value );
         Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
 
         // simple
-        value = "( 123.4567.890 "+required+")";
+        value = "( 123.4567.890 " + required + ")";
         asd = parser.parse( value );
         Assert.assertEquals( "123.4567.890", asd.getNumericOid() );
-        
-        // simple with spaces
-        value = "(          0.1.2.3.4.5.6.7.8.9         "+required+" )";
+
+        // simple with multiple spaces
+        value = "(          0.1.2.3.4.5.6.7.8.9         " + required + " )";
         asd = parser.parse( value );
         Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
 
-        // non-numeric not allowed
-        value = "( test "+required+" )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NUMERICOID test" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+        // simple w/o spaces
+        value = "(0.1.2.3.4.5.6.7.8.9 " + required + ")";
+        asd = parser.parse( value );
+        Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
+
+        // simple with tabs, newline, comment.
+        value = "(\t0.1.2.3.4.5.6.7.8.9\n#comment\n" + required + "\r\n)\r";
+        asd = parser.parse( value );
+        Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
+
+        // quoted OID
+        value = "( '0.1.2.3.4.5.6.7.8.9' " + required + " )";
+        asd = parser.parse( value );
+        Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
+
+        // quoted OID in parentheses
+        value = "( ('0.1.2.3.4.5.6.7.8.9') " + required + " )";
+        asd = parser.parse( value );
+        Assert.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
 
-        // to short
-        value = "( 1 "+required+" )";
+        // too short
+        value = "( 1 " + required + " )";
         try
         {
             parser.parse( value );
@@ -113,7 +121,7 @@
         }
 
         // dot only
-        value = "( . "+required+" )";
+        value = "( . " + required + " )";
         try
         {
             parser.parse( value );
@@ -125,7 +133,7 @@
         }
 
         // ends with dot
-        value = "( 1.1. "+required+" )";
+        value = "( 1.1. " + required + " )";
         try
         {
             parser.parse( value );
@@ -136,44 +144,60 @@
             // expected
         }
 
-        // quotes not allowed
-        value = "( '1.1' "+required+" )";
+        // multiple not allowed
+        value = "( ( 1.2.3 4.5.6 ) " + required + " )";
         try
         {
             parser.parse( value );
-            Assert.fail( "Exception expected, invalid NUMERICOID '1.1' (quoted)" );
+            Assert.fail( "Exception expected, invalid multiple OIDs not allowed.)" );
         }
         catch ( ParseException pe )
         {
-            // expected
+            // excpected
         }
 
-        // leading 0 not allowed
-        value = "( 01.1 "+required+" )";
-        try
+        if ( !parser.isQuirksMode() )
         {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NUMERICOID 01.1 (leading zero)" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+            // non-numeric not allowed
+            value = "( test " + required + " )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NUMERICOID test" );
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
+
+            // leading 0 not allowed
+            value = "( 01.1 " + required + " )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NUMERICOID 01.1 (leading zero)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
+
+            // alpha not allowed
+            value = "( 1.2.a.4 " + required + " )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NUMERICOID 1.2.a.4 (alpha not allowed)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // excpected
+            }
 
-        // alpha not allowed
-        value = "( 1.2.a.4 "+required+" )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NUMERICOID 1.2.a.4 (alpha not allowed)"
);
-        }
-        catch ( ParseException pe )
-        {
-            Assert.assertTrue( true );
         }
-        
     }
-    
+
+
     /**
      * Tests NAME and its values
      * 
@@ -185,38 +209,40 @@
         AbstractSchemaDescription asd = null;
 
         // alpha
-        value = "( "+oid+" "+required+" NAME 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
)";
+        value = "( " + oid + " " + required + " NAME 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
)";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getNames().size() );
         Assert.assertEquals( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", asd.getNames().get(
0 ) );
 
         // alpha-num-hypen
-        value = "( "+oid+" "+required+" NAME 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'
)";
+        value = "( " + oid + " " + required
+            + " NAME 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' )";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getNames().size() );
-        Assert.assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789",
asd.getNames().get( 0 ) );
+        Assert
+            .assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789",
asd.getNames().get( 0 ) );
 
         // with parentheses
-        value = "( "+oid+" "+required+" NAME ( 'a-z-0-9' ) )";
+        value = "( " + oid + " " + required + " NAME ( 'a-z-0-9' ) )";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getNames().size() );
         Assert.assertEquals( "a-z-0-9", asd.getNames().get( 0 ) );
 
         // with parentheses, without space
-        value = "( "+oid+" "+required+" NAME ('a-z-0-9') )";
+        value = "(" + oid + " " + required + " NAME('a-z-0-9'))";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getNames().size() );
         Assert.assertEquals( "a-z-0-9", asd.getNames().get( 0 ) );
 
         // multi with space
-        value = "( "+oid+" "+required+" NAME ( 'test1' 'test2' ) )";
+        value = " ( " + oid + " " + required + " NAME ( 'test1' 'test2' ) ) ";
         asd = parser.parse( value );
         Assert.assertEquals( 2, asd.getNames().size() );
         Assert.assertEquals( "test1", asd.getNames().get( 0 ) );
         Assert.assertEquals( "test2", asd.getNames().get( 1 ) );
 
         // multi without space
-        value = "( "+oid+" "+required+" NAME ('test1' 'test2' 'test3') )";
+        value = "(" + oid + " " + required + " NAME('test1''test2''test3'))";
         asd = parser.parse( value );
         Assert.assertEquals( 3, asd.getNames().size() );
         Assert.assertEquals( "test1", asd.getNames().get( 0 ) );
@@ -224,75 +250,44 @@
         Assert.assertEquals( "test3", asd.getNames().get( 2 ) );
 
         // multi with many spaces
-        value = "(          "+oid+" "+required+"          NAME          (          'test1'
         'test2'          'test3'          )          )";
+        value = "(          " + oid + " " + required
+            + "          NAME          (          'test1'          'test2'          'test3'
         )          )";
         asd = parser.parse( value );
         Assert.assertEquals( 3, asd.getNames().size() );
         Assert.assertEquals( "test1", asd.getNames().get( 0 ) );
         Assert.assertEquals( "test2", asd.getNames().get( 1 ) );
         Assert.assertEquals( "test3", asd.getNames().get( 2 ) );
 
-        // lowercase
-        value = "( "+oid+" "+required+" name 'test' )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, NAME is lowercase" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
-
-        // unquoted
-        value = "( "+oid+" "+required+" NAME test )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME test (unquoted)" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+        // multi with tabs, newline, comment, etc.
+        value = "(\r\n" + oid + "\r" + required
+            + "\nNAME\t(\t\t\t'test1'\t\n\t'test2'\t\r\t'test3'\t\r\n\t)\n#comment\n)";
+        asd = parser.parse( value );
+        Assert.assertEquals( 3, asd.getNames().size() );
+        Assert.assertEquals( "test1", asd.getNames().get( 0 ) );
+        Assert.assertEquals( "test2", asd.getNames().get( 1 ) );
+        Assert.assertEquals( "test3", asd.getNames().get( 2 ) );
 
-        // start with number
-        value = "( "+oid+" "+required+" NAME '1test' )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME 1test (starts with number)" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+        // lowercase NAME
+        value = "( " + oid + " " + required + " name 'test' )";
+        asd = parser.parse( value );
+        Assert.assertEquals( 1, asd.getNames().size() );
+        Assert.assertEquals( "test", asd.getNames().get( 0 ) );
 
-        // start with hypen
-        value = "( "+oid+" "+required+" NAME '-test' )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME -test (starts with hypen)" );
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+        // unquoted NAME value
+        value = "( " + oid + " " + required + " NAME test )";
+        asd = parser.parse( value );
+        Assert.assertEquals( 1, asd.getNames().size() );
+        Assert.assertEquals( "test", asd.getNames().get( 0 ) );
 
-        // invalid character
-        value = "( "+oid+" "+required+" NAME 'te_st' )";
-        try
-        {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME te_st (contains invalid character)"
);
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+        // multi unquoted NAME values
+        value = " ( " + oid + " " + required + " NAME (test1 test2) ) ";
+        asd = parser.parse( value );
+        Assert.assertEquals( 2, asd.getNames().size() );
+        Assert.assertEquals( "test1", asd.getNames().get( 0 ) );
+        Assert.assertEquals( "test2", asd.getNames().get( 1 ) );
 
         // NAM unknown
-        value = "( "+oid+" "+required+" NAM 'test' )";
+        value = "( " + oid + " " + required + " NAM 'test' )";
         try
         {
             parser.parse( value );
@@ -303,81 +298,133 @@
             // expected
         }
 
-        // one valid, one invalid
-        value = "( "+oid+" "+required+" NAME ( 'test' 'te_st' ) )";
-        try
+        if ( !parser.isQuirksMode() )
         {
-            parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME te_st (contains invalid character)"
);
-        }
-        catch ( ParseException pe )
-        {
-            // expected
-        }
+            // start with number
+            value = "( " + oid + " " + required + " NAME '1test' )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NAME 1test (starts with number)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
 
-        // no space between values
-        value = "( "+oid+" "+required+" NAME ( 'test1''test2' ) )";
-        try
-        {
-            asd = parser.parse( value );
-            Assert.fail( "Exception expected, invalid NAME values (no space between values)"
);
-        }
-        catch ( ParseException pe )
-        {
-            Assert.assertTrue( true );
+            // start with hypen
+            value = "( " + oid + " " + required + " NAME '-test' )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NAME -test (starts with hypen)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
+
+            // invalid character
+            value = "( " + oid + " " + required + " NAME 'te_st' )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NAME te_st (contains invalid character)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
+
+            // one valid, one invalid
+            value = "( " + oid + " " + required + " NAME ( 'test' 'te_st' ) )";
+            try
+            {
+                parser.parse( value );
+                Assert.fail( "Exception expected, invalid NAME te_st (contains invalid character)"
);
+            }
+            catch ( ParseException pe )
+            {
+                // expected
+            }
         }
     }
-    
-    
+
+
     /**
      * Tests DESC
      * 
      * @throws ParseException
      */
-    public static void testDescription( AbstractSchemaParser parser, String oid, String required
) throws ParseException
+    public static void testDescription( AbstractSchemaParser parser, String oid, String required
)
+        throws ParseException
     {
         String value = null;
         AbstractSchemaDescription asd = null;
 
         // simple
-        value = "("+oid+" "+required+" DESC 'Descripton')";
+        value = "(" + oid + " " + required + " DESC 'Descripton')";
+        asd = parser.parse( value );
+        Assert.assertEquals( "Descripton", asd.getDescription() );
+
+        // simple with tabs, newline, comment, etc.
+        value = "(" + oid + "\n" + required + "\tDESC#comment\n\n\r\n\r\t'Descripton')";
+        asd = parser.parse( value );
+        Assert.assertEquals( "Descripton", asd.getDescription() );
+
+        // simple w/o space
+        value = "(" + oid + " " + required + " DESC'Descripton')";
+        asd = parser.parse( value );
+        Assert.assertEquals( "Descripton", asd.getDescription() );
+
+        // simple parentheses and quotes
+        value = "(" + oid + " " + required + " DESC ('Descripton') )";
         asd = parser.parse( value );
         Assert.assertEquals( "Descripton", asd.getDescription() );
 
         // unicode
-        value = "( "+oid+" "+required+" DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577'
)";
+        value = "( " + oid + " " + required + " DESC 'Descripton \u00E4\u00F6\u00FC\u00DF
\u90E8\u9577' )";
         asd = parser.parse( value );
         Assert.assertEquals( "Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", asd.getDescription()
);
-        
+
         // escaped characters
-        value = "( "+oid+" "+required+" DESC 'test\\5Ctest' )";
+        value = "( " + oid + " " + required + " DESC 'test\\5Ctest' )";
         asd = parser.parse( value );
         Assert.assertEquals( "test\\test", asd.getDescription() );
-        value = "( "+oid+" "+required+" DESC 'test\\5ctest' )";
+        value = "( " + oid + " " + required + " DESC 'test\\5ctest' )";
         asd = parser.parse( value );
         Assert.assertEquals( "test\\test", asd.getDescription() );
-        value = "( "+oid+" "+required+" DESC 'test\\27test' )";
+        value = "( " + oid + " " + required + " DESC 'test\\27test' )";
         asd = parser.parse( value );
         Assert.assertEquals( "test'test", asd.getDescription() );
-        value = "( "+oid+" "+required+" DESC '\\5C\\27\\5c' )";
+        value = "( " + oid + " " + required + " DESC '\\5C\\27\\5c' )";
         asd = parser.parse( value );
         Assert.assertEquals( "\\'\\", asd.getDescription() );
-        
-        // lowercase
-        value = "( "+oid+" "+required+" desc 'Descripton' )";
+
+        // lowercase DESC
+        value = "( " + oid + " " + required + " desc 'Descripton' )";
+        asd = parser.parse( value );
+        Assert.assertEquals( "Descripton", asd.getDescription() );
+
+        // empty DESC
+        value = "( " + oid + " " + required + " DESC '' )";
+        asd = parser.parse( value );
+        Assert.assertEquals( "", asd.getDescription() );
+
+        // multiple not allowed
+        value = "(" + oid + " " + required + " DESC ( 'Descripton1' 'Description 2' )  )";
         try
         {
             parser.parse( value );
-            Assert.fail( "Exception expected, DESC is lowercase" );
+            Assert.fail( "Exception expected, invalid multiple DESC not allowed.)" );
         }
         catch ( ParseException pe )
         {
-            Assert.assertTrue( true );
+            // expected
         }
-        
     }
-    
-    
+
+
     /**
      * Test extensions.
      * 
@@ -389,12 +436,12 @@
         AbstractSchemaDescription asd = null;
 
         // no extension
-        value = "( "+oid+" "+required+" )";
+        value = "( " + oid + " " + required + " )";
         asd = parser.parse( value );
         Assert.assertEquals( 0, asd.getExtensions().size() );
 
         // single extension with one value
-        value = "( "+oid+" "+required+" X-TEST 'test' )";
+        value = "( " + oid + " " + required + " X-TEST 'test' )";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getExtensions().size() );
         Assert.assertNotNull( asd.getExtensions().get( "X-TEST" ) );
@@ -402,7 +449,8 @@
         Assert.assertEquals( "test", asd.getExtensions().get( "X-TEST" ).get( 0 ) );
 
         // single extension with multiple values
-        value = "( "+oid+" "+required+" X-TEST-ABC ('test1' 'test \u00E4\u00F6\u00FC\u00DF'
      'test \u90E8\u9577' ) )";
+        value = "( " + oid + " " + required
+            + " X-TEST-ABC ('test1' 'test \u00E4\u00F6\u00FC\u00DF'       'test \u90E8\u9577'
) )";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getExtensions().size() );
         Assert.assertNotNull( asd.getExtensions().get( "X-TEST-ABC" ) );
@@ -412,7 +460,34 @@
         Assert.assertEquals( "test \u90E8\u9577", asd.getExtensions().get( "X-TEST-ABC" ).get(
2 ) );
 
         // multiple extensions
-        value = "("+oid+" "+required+" X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1'
'test2-2'))";
+        value = "(" + oid + " " + required + " X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1'
'test2-2'))";
+        asd = parser.parse( value );
+        Assert.assertEquals( 2, asd.getExtensions().size() );
+        Assert.assertNotNull( asd.getExtensions().get( "X-TEST-a" ) );
+        Assert.assertEquals( 2, asd.getExtensions().get( "X-TEST-a" ).size() );
+        Assert.assertEquals( "test1-1", asd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+        Assert.assertEquals( "test1-2", asd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+        Assert.assertNotNull( asd.getExtensions().get( "X-TEST-b" ) );
+        Assert.assertEquals( 2, asd.getExtensions().get( "X-TEST-b" ).size() );
+        Assert.assertEquals( "test2-1", asd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+        Assert.assertEquals( "test2-2", asd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+
+        // multiple extensions, no spaces
+        value = "(" + oid + " " + required + " X-TEST-a('test1-1''test1-2')X-TEST-b('test2-1''test2-2'))";
+        asd = parser.parse( value );
+        Assert.assertEquals( 2, asd.getExtensions().size() );
+        Assert.assertNotNull( asd.getExtensions().get( "X-TEST-a" ) );
+        Assert.assertEquals( 2, asd.getExtensions().get( "X-TEST-a" ).size() );
+        Assert.assertEquals( "test1-1", asd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+        Assert.assertEquals( "test1-2", asd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+        Assert.assertNotNull( asd.getExtensions().get( "X-TEST-b" ) );
+        Assert.assertEquals( 2, asd.getExtensions().get( "X-TEST-b" ).size() );
+        Assert.assertEquals( "test2-1", asd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+        Assert.assertEquals( "test2-2", asd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+
+        // multiple extensions, tabs, newline, comments
+        value = "(" + oid + "\n#comment\n" + required
+            + "\nX-TEST-a\n(\t'test1-1'\t\n'test1-2'\n\r)\tX-TEST-b\n(\n'test2-1'\t'test2-2'\t)\r)";
         asd = parser.parse( value );
         Assert.assertEquals( 2, asd.getExtensions().size() );
         Assert.assertNotNull( asd.getExtensions().get( "X-TEST-a" ) );
@@ -425,15 +500,18 @@
         Assert.assertEquals( "test2-2", asd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
 
         // some more complicated
-        value = "("+oid+" "+required+" X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
('\\5C\\27\\5c'))";
+        value = "(" + oid + " " + required
+            + " X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ('\\5C\\27\\5c'))";
         asd = parser.parse( value );
         Assert.assertEquals( 1, asd.getExtensions().size() );
         Assert.assertNotNull( asd.getExtensions().get( "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
) );
-        Assert.assertEquals( 1, asd.getExtensions().get( "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
).size() );
-        Assert.assertEquals( "\\'\\", asd.getExtensions().get( "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
).get( 0 ) );
-        
+        Assert.assertEquals( 1, asd.getExtensions().get( "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
+            .size() );
+        Assert.assertEquals( "\\'\\", asd.getExtensions().get(
+            "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ).get( 0 ) );
+
         // invalid extension, no number allowed
-        value = "( "+oid+" "+required+" X-TEST1 'test' )";
+        value = "( " + oid + " " + required + " X-TEST1 'test' )";
         try
         {
             asd = parser.parse( value );
@@ -446,7 +524,7 @@
 
     }
 
-    
+
     /**
      * Tests OBSOLETE
      * 
@@ -458,27 +536,32 @@
         AbstractSchemaDescription asd = null;
 
         // not obsolete
-        value = "( "+oid+" "+required+" )";
+        value = "( " + oid + " " + required + " )";
         asd = parser.parse( value );
         Assert.assertFalse( asd.isObsolete() );
 
         // not obsolete
-        value = "( "+oid+" "+required+" NAME 'test' DESC 'Descripton' )";
+        value = "( " + oid + " " + required + " NAME 'test' DESC 'Descripton' )";
         asd = parser.parse( value );
         Assert.assertFalse( asd.isObsolete() );
-        
+
         // obsolete
-        value = "("+oid+" "+required+" NAME 'test' DESC 'Descripton' OBSOLETE)";
+        value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLETE)";
         asd = parser.parse( value );
         Assert.assertTrue( asd.isObsolete() );
 
         // obsolete 
-        value = "("+oid+" "+required+" OBSOLETE)";
+        value = "(" + oid + " " + required + " OBSOLETE)";
         asd = parser.parse( value );
         Assert.assertTrue( asd.isObsolete() );
 
-        // ivalid
-        value = "("+oid+" "+required+" NAME 'test' DESC 'Descripton' OBSOLET )";
+        // lowercased obsolete 
+        value = "(" + oid + " " + required + " obsolete)";
+        asd = parser.parse( value );
+        Assert.assertTrue( asd.isObsolete() );
+
+        // invalid
+        value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLET )";
         try
         {
             asd = parser.parse( value );
@@ -488,9 +571,9 @@
         {
             // expected
         }
-        
+
         // trailing value not allowed
-        value = "("+oid+" "+required+" NAME 'test' DESC 'Descripton' OBSOLETE 'true' )";
+        value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLETE 'true'
)";
         try
         {
             asd = parser.parse( value );
@@ -500,11 +583,10 @@
         {
             Assert.assertTrue( true );
         }
-        
+
     }
-    
-    
-    
+
+
     /**
      * Tests for unique elements.
      * 
@@ -518,17 +600,17 @@
             try
             {
                 parser.parse( testValue );
-                Assert.fail( "Exception expected, element appears twice in "+testValue );
+                Assert.fail( "Exception expected, element appears twice in " + testValue
);
             }
             catch ( ParseException pe )
             {
                 Assert.assertTrue( true );
             }
         }
-        
+
     }
-    
-    
+
+
     /**
      * Tests the multithreaded use of a single parser.
      */
@@ -536,7 +618,7 @@
     {
         final boolean[] isSuccessMultithreaded = new boolean[1];
         isSuccessMultithreaded[0] = true;
-        
+
         // start up and track all threads (40 threads)
         List<Thread> threads = new ArrayList<Thread>();
         for ( int ii = 0; ii < 10; ii++ )
@@ -565,7 +647,47 @@
 
         // check that no one thread failed to parse and generate a SS object
         Assert.assertTrue( isSuccessMultithreaded[0] );
-        
+
+    }
+
+
+    /**
+     * Tests quirks mode.
+     */
+    public static void testQuirksMode( AbstractSchemaParser parser, String required ) throws
ParseException
+    {
+        try
+        {
+            String value = null;
+            AbstractSchemaDescription asd = null;
+            
+            parser.setQuirksMode( true );
+            
+            // alphanum OID
+            value = "( abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 "
+ required + " )";
+            asd = parser.parse( value );
+            Assert.assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789",
asd
+                .getNumericOid() );
+
+            // start with hypen
+            value = "( -oid " + required + " )";
+            asd = parser.parse( value );
+            Assert.assertEquals( "-oid", asd.getNumericOid() );
+
+            // start with number
+            value = "( 1oid " + required + " )";
+            asd = parser.parse( value );
+            Assert.assertEquals( "1oid", asd.getNumericOid() );
+
+            // start with dot
+            value = "( .oid " + required + " )";
+            asd = parser.parse( value );
+            Assert.assertEquals( ".oid", asd.getNumericOid() );
+        }
+        finally
+        {
+            parser.setQuirksMode( false );
+        }
     }
 
     static class ParseSpecification implements Runnable
@@ -573,17 +695,18 @@
         private final AbstractSchemaParser parser;
         private final String value;
         private final boolean[] isSuccessMultithreaded;
-        
+
         private AbstractSchemaDescription result;
-        
+
+
         public ParseSpecification( AbstractSchemaParser parser, String value, boolean[] isSuccessMultithreaded
)
         {
             this.parser = parser;
             this.value = value;
             this.isSuccessMultithreaded = isSuccessMultithreaded;
         }
-        
-        
+
+
         public void run()
         {
             try
@@ -594,10 +717,9 @@
             {
                 e.printStackTrace();
             }
-            
+
             isSuccessMultithreaded[0] = isSuccessMultithreaded[0] && ( result !=
null );
         }
     }
-    
-    
+
 }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SyntaxCheckerDescriptionSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SyntaxCheckerDescriptionSchemaParserTest.java?rev=664290&r1=664289&r2=664290&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SyntaxCheckerDescriptionSchemaParserTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/parser/SyntaxCheckerDescriptionSchemaParserTest.java
Fri Jun  6 23:28:06 2008
@@ -56,7 +56,7 @@
     }
 
 
-    public void testNumericOid() throws Exception
+    public void testNumericOid() throws ParseException
     {
         SchemaParserTestUtils.testNumericOid( parser, "FQCN org.apache.directory.SimpleComparator"
);
     }
@@ -70,7 +70,6 @@
 
     public void testFqcn() throws ParseException
     {
-
         String value = null;
         SyntaxCheckerDescription scd = null;
 
@@ -79,13 +78,11 @@
         scd = parser.parseSyntaxCheckerDescription( value );
         assertNotNull( scd.getFqcn() );
         assertEquals( "org.apache.directory.SimpleComparator", scd.getFqcn() );
-
     }
 
 
     public void testBytecode() throws ParseException
     {
-
         String value = null;
         SyntaxCheckerDescription scd = null;
 
@@ -94,7 +91,6 @@
         scd = parser.parseSyntaxCheckerDescription( value );
         assertNotNull( scd.getBytecode() );
         assertEquals( "ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====",
scd.getBytecode() );
-
     }
 
 
@@ -132,7 +128,7 @@
     }
 
 
-    public void testSimpleSyntaxChecker() throws Exception
+    public void testSimpleSyntaxChecker() throws ParseException
     {
         String simple = "( " + OID + " FQCN " + FQCN + " )";
         SyntaxCheckerDescription desc = parser.parseSyntaxCheckerDescription( simple );
@@ -144,7 +140,7 @@
     }
 
 
-    public void testSyntaxCheckerWithDesc() throws Exception
+    public void testSyntaxCheckerWithDesc() throws ParseException
     {
         String simple = "( " + OID + " DESC '" + DESC + "' FQCN " + FQCN + " )";
         SyntaxCheckerDescription desc = parser.parseSyntaxCheckerDescription( simple );
@@ -156,7 +152,7 @@
     }
 
 
-    public void testSyntaxCheckerWithDescAndByteCode() throws Exception
+    public void testSyntaxCheckerWithDescAndByteCode() throws ParseException
     {
         String simple = "( " + OID + " DESC '" + DESC + "' FQCN " + FQCN + " BYTECODE " +
BYTECODE + " )";
         SyntaxCheckerDescription desc = parser.parseSyntaxCheckerDescription( simple );
@@ -168,7 +164,7 @@
     }
 
 
-    public void testSyntaxCheckerExample() throws Exception
+    public void testSyntaxCheckerExample() throws ParseException
     {
         String simple = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
         SyntaxCheckerDescription desc = parser.parseSyntaxCheckerDescription( simple );
@@ -176,7 +172,7 @@
     }
 
 
-    public void testRealByteCodeExample() throws Exception
+    public void testRealByteCodeExample() throws ParseException
     {
         String simple = "( 1.3.6.1.4.1.18060.0.4.1.0.10002 DESC 'bogus desc' "
             + "FQCN DummySyntaxChecker BYTECODE yv66vgAAADEAHgoABAAYCQADABkHABoHABsHABwBAANvaWQBABJMam"
@@ -204,9 +200,42 @@
     /**
      * Tests the multithreaded use of a single parser.
      */
-    public void testMultiThreaded() throws Exception
+    public void testMultiThreaded() throws ParseException
     {
         // TODO
     }
 
+
+    /**
+     * Tests quirks mode.
+     */
+    public void testQuirksMode() throws ParseException
+    {
+        SchemaParserTestUtils.testQuirksMode( parser, "FQCN org.apache.directory.SimpleComparator"
);
+
+        try
+        {
+            parser.setQuirksMode( true );
+
+            // ensure all other test pass in quirks mode
+            testNumericOid();
+            testDescription();
+            testFqcn();
+            testBytecode();
+            testExtensions();
+            testFull();
+            testUniqueElements();
+            testSimpleSyntaxChecker();
+            testSyntaxCheckerWithDesc();
+            testSyntaxCheckerWithDescAndByteCode();
+            testSyntaxCheckerExample();
+            testRealByteCodeExample();
+            testMultiThreaded();
+        }
+        finally
+        {
+            parser.setQuirksMode( false );
+        }
+    }
+
 }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java?rev=664290&r1=664289&r2=664290&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
Fri Jun  6 23:28:06 2008
@@ -193,8 +193,8 @@
         TriggerSpecification triggerSpecification = null;
         
         String spec = "AFTER Delete " +
-        	"CALL \"BackupUtilities.backupDeletedEntry\" ($ldapContext \"ou=Backup,ou=System\",
$name, $deletedEntry); " +
-        	"CALL \"BackupUtilities.recreateDeletedEntry\" ($name, $deletedEntry);";
+            "CALL \"BackupUtilities.backupDeletedEntry\" ($ldapContext \"ou=Backup,ou=System\",
$name, $deletedEntry); " +
+            "CALL \"BackupUtilities.recreateDeletedEntry\" ($name, $deletedEntry);";
 
         triggerSpecification = parser.parse( spec );
         



Mime
View raw message