You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/12/26 23:50:19 UTC
svn commit: r359119 -
/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java
Author: elecharny
Date: Mon Dec 26 14:50:15 2005
New Revision: 359119
URL: http://svn.apache.org/viewcvs?rev=359119&view=rev
Log:
- Added asn1-codec StringUtils tests to StringToolsTest
Modified:
directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java
Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java?rev=359119&r1=359118&r2=359119&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java (original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java Mon Dec 26 14:50:15 2005
@@ -17,6 +17,12 @@
package org.apache.ldap.common.util;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
import junit.framework.TestCase;
@@ -28,7 +34,7 @@
*/
public class StringToolsTest extends TestCase
{
- public void testTrimConsecutiveToOne()
+ public void testTrimConsecutiveToOne()
{
String input = null;
String result = null;
@@ -58,4 +64,111 @@
assertEquals( "*a*k*a*r*a*s*u*l*u*", result );
}
+
+
+ public void testOneByteChar()
+ {
+ char res = StringTools.bytesToChar(new byte[]{0x30});
+
+ Assert.assertEquals('0', res);
+ }
+
+ public void testOneByteChar00()
+ {
+ char res = StringTools.bytesToChar(new byte[]{0x00});
+
+ Assert.assertEquals(0x00, res);
+ }
+
+ public void testOneByteChar7F()
+ {
+ char res = StringTools.bytesToChar(new byte[]{0x7F});
+
+ Assert.assertEquals(0x7F, res);
+ }
+
+ public void testTwoBytesChar()
+ {
+ char res = StringTools.bytesToChar(new byte[]{(byte)0xCE, (byte)0x91});
+
+ Assert.assertEquals(0x0391, res);
+ }
+
+ public void testThreeBytesChar()
+ {
+ char res = StringTools.bytesToChar(new byte[]{(byte)0xE2, (byte)0x89, (byte)0xA2});
+
+ Assert.assertEquals(0x2262, res);
+ }
+
+ public void testcharToBytesOne()
+ {
+ Assert.assertEquals( "0x00 ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x0000 ) ) );
+ Assert.assertEquals( "0x61 ", StringTools.dumpBytes( StringTools.charToBytes( 'a' ) ) );
+ Assert.assertEquals( "0x7F ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x007F ) ) );
+ }
+
+ public void testcharToBytesTwo()
+ {
+ Assert.assertEquals( "0xC2 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x0080 ) ) );
+ Assert.assertEquals( "0xC3 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x00FF ) ) );
+ Assert.assertEquals( "0xC4 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x0100 ) ) );
+ Assert.assertEquals( "0xDF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x07FF ) ) );
+ }
+
+ public void testcharToBytesThree()
+ {
+ Assert.assertEquals( "0xE0 0xA0 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x0800 ) ) );
+ Assert.assertEquals( "0xE0 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x0FFF ) ) );
+ Assert.assertEquals( "0xE1 0x80 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( (char)0x1000 ) ) );
+ Assert.assertEquals( "0xEF 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( (char)0xFFFF ) ) );
+ }
+
+ public void testListToString()
+ {
+ List list = new ArrayList();
+
+ list.add( "elem1" );
+ list.add( "elem2" );
+ list.add( "elem3" );
+
+ Assert.assertEquals( "elem1, elem2, elem3", StringTools.listToString( list ) );
+ }
+
+ public void testMapToString()
+ {
+ class Value
+ {
+ String name;
+ int val;
+
+ public Value( String name, int val)
+ {
+ this.name = name;
+ this.val = val;
+ }
+
+ public String toString()
+ {
+ return "[" + name + ", " + val + "]";
+ }
+ }
+
+ Map map = new HashMap();
+
+ map.put( "elem1", new Value( "name1", 1) );
+ map.put( "elem2", new Value( "name2", 2) );
+ map.put( "elem3", new Value( "name3", 3) );
+
+ String result = StringTools.mapToString( map );
+
+ boolean res = "elem1 = '[name1, 1]', elem2 = '[name2, 2]', elem3 = '[name3, 3]'".equals( result) ||
+ "elem1 = '[name1, 1]', elem3 = '[name3, 3]', elem2 = '[name2, 2]'".equals( result) ||
+ "elem2 = '[name2, 2]', elem1 = '[name1, 1]', elem3 = '[name3, 3]'".equals( result) ||
+ "elem2 = '[name2, 2]', elem3 = '[name3, 3]', elem1 = '[name1, 1]'".equals( result) ||
+ "elem3 = '[name3, 3]', elem1 = '[name1, 1]', elem2 = '[name2, 2]'".equals( result) ||
+ "elem3 = '[name3, 3]', elem3 = '[name2, 2]', elem1 = '[name1, 1]'".equals( result);
+
+ Assert.assertTrue( res );
+ }
}