directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1745843 - in /directory/shared/branches/shared-value/ldap/model/src: main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java
Date Sat, 28 May 2016 07:42:58 GMT
Author: elecharny
Date: Sat May 28 07:42:58 2016
New Revision: 1745843

URL: http://svn.apache.org/viewvc?rev=1745843&view=rev
Log:
o Fixed the insignificantSpacesStringAny PrepareString method
o Added tests for all the Initial, Any, and Final use cases.

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java
    directory/shared/branches/shared-value/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java?rev=1745843&r1=1745842&r2=1745843&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/PrepareString.java
Sat May 28 07:42:58 2016
@@ -3842,15 +3842,13 @@ public final class PrepareString
     {
         if ( origin == null )
         {
-            // Special case : a null strings is replaced by 2 spaces
-            return "  ";
+            // Special case : a null strings is replaced by 1 space
+            return " ";
         }
 
         int pos = 0;
 
-        // Create a target char array which is longer than the original String, as we will
-        // have 2 more spaces (one at the beginning, one at the end, and each space in the

-        // middle will be doubled).
+        // Create a target char array which is longer than the original String, as we may
have to add a space.
         char[] target = new char[origin.length * 2 + 1];
         int newPos = 0;
         
@@ -3863,7 +3861,7 @@ public final class PrepareString
                 case START :
                     if ( pos == origin.length )
                     {
-                        // We are done, it's an empty string
+                        // We are done, it's an empty string -> one space
                         return " ";
                     }
                     
@@ -3898,7 +3896,8 @@ public final class PrepareString
                     
                     if ( c == ' ' )
                     {
-                        // Switch to the SPACES state
+                        // Switch to the SPACES state, add a space in the target
+                        target[newPos++] = ' ';
                         pos++;
                         normState = NormStateEnum.SPACES;
                     }
@@ -3915,7 +3914,7 @@ public final class PrepareString
                 case INITIAL_SPACES :
                     if ( pos == origin.length )
                     {
-                        // We are done, this is an empty String
+                        // We are done, this is an empty String -> one space
                         return " ";
                     }
                     
@@ -3942,8 +3941,7 @@ public final class PrepareString
                 case CHARS :
                     if ( pos == origin.length )
                     {
-                        // We are done, add a Space
-                        target[newPos++] = ' ';
+                        // We are done
                         normState = NormStateEnum.END;
                         
                         break;
@@ -3953,6 +3951,9 @@ public final class PrepareString
                     
                     if ( c == ' ' )
                     {
+                        // Add the space
+                        target[newPos++] = ' ';
+                        
                         pos++;
                         normState = NormStateEnum.SPACES;
                     }
@@ -3969,8 +3970,7 @@ public final class PrepareString
                 case SPACES :
                     if ( pos == origin.length )
                     {
-                        // We are done, add a Space
-                        target[newPos++] = ' ';
+                        // We are done
                         normState = NormStateEnum.END;
 
                         break;
@@ -3985,8 +3985,7 @@ public final class PrepareString
                     }
                     else
                     {
-                        // Add the two spaces
-                        target[newPos++] = ' ';
+                        // Add the second space
                         target[newPos++] = ' ';
                         
                         // Add the char
@@ -4002,8 +4001,7 @@ public final class PrepareString
                 case SPACE_CHAR :
                     if ( pos == origin.length )
                     {
-                        // We are done, add a Space
-                        target[newPos++] = ' ';
+                        // We are done
                         normState = NormStateEnum.END;
 
                         break;
@@ -4014,6 +4012,9 @@ public final class PrepareString
                     if ( c == ' ' )
                     {
                         pos++;
+
+                        // Add the space
+                        target[newPos++] = ' ';
                         
                         // Switch to Spaces state
                         normState = NormStateEnum.SPACES;

Modified: directory/shared/branches/shared-value/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java?rev=1745843&r1=1745842&r2=1745843&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/PrepareStringTest.java
Sat May 28 07:42:58 2016
@@ -20,11 +20,11 @@
 
 package org.apache.directory.api.ldap.model.schema;
 
-import static org.junit.Assert.*;
-
 import java.io.IOException;
 
+import org.apache.directory.api.util.exception.InvalidCharacterException;
 import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
 /**
  * Tests for the PrepareString class
@@ -33,11 +33,442 @@ import org.junit.Test;
  */
 public class PrepareStringTest
 {
-
     @Test
     public void testEscapeBackSlash() throws IOException
     {
         String result = PrepareString.normalize( "C:\\a\\b\\c" );
         System.out.println( result );
     }
+    
+    //-------------------------------------------------------------------------
+    // Test the PrepareString.insignificantSpacesStringInitial method
+    //-------------------------------------------------------------------------
+    @Test 
+    public void insignificantSpacesStringInitialNull() throws InvalidCharacterException
+    {
+        char[] empty = null;
+        assertEquals( " ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialEmpty() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{};
+        assertEquals( " ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ' };
+        assertEquals( " ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', ' '};
+        assertEquals( " ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c' };
+        assertEquals( " abc", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialOneSpaceA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialNSpacesA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialOneSpaceABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a', 'b', 'c' };
+        assertEquals( " abc", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialNSpacesABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a', 'b', 'c' };
+        assertEquals( " abc", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialInnerOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', 'b', ' ', 'c' };
+        assertEquals( " a  b  c", PrepareString.insignificantSpacesStringInitial( empty )
);
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialInnerNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ', 'c' };
+        assertEquals( " a  b  c", PrepareString.insignificantSpacesStringInitial( empty )
);
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialEndingOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ' };
+        assertEquals( " a ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialEndingNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', ' ' };
+        assertEquals( " a ", PrepareString.insignificantSpacesStringInitial( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringInitialAll() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ', 'c', ' ', ' ',
' ' };
+        assertEquals( " a  b  c ", PrepareString.insignificantSpacesStringInitial( empty
) );
+    }
+    
+    
+    //-------------------------------------------------------------------------
+    // Test the PrepareString.insignificantSpacesStringFinal method
+    //-------------------------------------------------------------------------
+    @Test 
+    public void insignificantSpacesStringFinalNull() throws InvalidCharacterException
+    {
+        char[] empty = null;
+        assertEquals( " ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalEmpty() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{};
+        assertEquals( " ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ' };
+        assertEquals( " ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', ' '};
+        assertEquals( " ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c' };
+        assertEquals( "abc ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalAOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalANSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalABCOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c', ' ' };
+        assertEquals( "abc ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalABCNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c', ' ', ' ', ' ' };
+        assertEquals( "abc ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalInnerOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', 'b', ' ', 'c' };
+        assertEquals( "a  b  c ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalInnerNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ', 'c' };
+        assertEquals( "a  b  c ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalStartingOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a' };
+        assertEquals( " a ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalStartingNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a'};
+        assertEquals( " a ", PrepareString.insignificantSpacesStringFinal( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringFinalAll() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ',
'c', ' ', 'd' };
+        assertEquals( " a  b  c  d ", PrepareString.insignificantSpacesStringFinal( empty
) );
+    }
+    
+    
+    //-------------------------------------------------------------------------
+    // Test the PrepareString.insignificantSpacesStringAny method
+    //-------------------------------------------------------------------------
+    @Test 
+    public void insignificantSpacesStringAnyNull() throws InvalidCharacterException
+    {
+        char[] empty = null;
+        assertEquals( " ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyEmpty() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{};
+        assertEquals( " ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ' };
+        assertEquals( " ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', ' '};
+        assertEquals( " ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a' };
+        assertEquals( "a", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c' };
+        assertEquals( "abc", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyAOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyANSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyOneSpaceA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyNSpacesA() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyABCOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c', ' ' };
+        assertEquals( "abc ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyABCNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', 'b', 'c', ' ', ' ', ' ' };
+        assertEquals( "abc ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyOneSpaceABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a', 'b', 'c' };
+        assertEquals( " abc", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyNSpacesABC() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a', 'b', 'c' };
+        assertEquals( " abc", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyInnerOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', 'b', ' ', 'c' };
+        assertEquals( "a  b  c", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyInnerNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ', 'c' };
+        assertEquals( "a  b  c", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyStartingOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a' };
+        assertEquals( " a", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyStartingNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a'};
+        assertEquals( " a", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyEndingOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyEndingNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ 'a', ' ', ' ', ' ' };
+        assertEquals( "a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyStartingEndingOneSpace() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', 'a', ' ' };
+        assertEquals( " a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyStartingEndingNSpaces() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a', ' ', ' ', ' ' };
+        assertEquals( " a ", PrepareString.insignificantSpacesStringAny( empty ) );
+    }
+    
+    
+    @Test 
+    public void insignificantSpacesStringAnyAll() throws InvalidCharacterException
+    {
+        char[] empty = new char[]{ ' ', ' ', ' ', 'a', ' ', ' ', 'b', ' ', ' ', ' ', ' ',
'c', ' ', 'd', ' ', ' ', ' ' };
+        assertEquals( " a  b  c  d ", PrepareString.insignificantSpacesStringAny( empty )
);
+    }
 }



Mime
View raw message