Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 57871 invoked from network); 26 Dec 2005 22:50:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Dec 2005 22:50:42 -0000 Received: (qmail 78716 invoked by uid 500); 26 Dec 2005 22:50:41 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 78683 invoked by uid 500); 26 Dec 2005 22:50:41 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 78672 invoked by uid 99); 26 Dec 2005 22:50:41 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2005 14:50:41 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 26 Dec 2005 14:50:40 -0800 Received: (qmail 57705 invoked by uid 65534); 26 Dec 2005 22:50:20 -0000 Message-ID: <20051226225020.57704.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r359119 - /directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/util/StringToolsTest.java Date: Mon, 26 Dec 2005 22:50:19 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 ); + } }