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/09/26 20:31:52 UTC
svn commit: r291704 - in
/directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util:
MutableStringTest.java StringUtilsTest.java
Author: elecharny
Date: Mon Sep 26 11:31:46 2005
New Revision: 291704
URL: http://svn.apache.org/viewcvs?rev=291704&view=rev
Log:
Added some tests and fixed the existing ones according to modification done on MutableString and StringUtils class
Modified:
directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
Modified: directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java?rev=291704&r1=291703&r2=291704&view=diff
==============================================================================
--- directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java (original)
+++ directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java Mon Sep 26 11:31:46 2005
@@ -16,6 +16,8 @@
*/
package org.apache.asn1new.util;
+import java.io.UnsupportedEncodingException;
+
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -30,20 +32,112 @@
Assert.assertEquals("", s);
}
- public void testNormalString()
+ public void testNormalString() throws UnsupportedEncodingException
{
- String s = new MutableString("abcdef".getBytes()).toString();
+ String s = new MutableString( "abcdef" ).toString();
Assert.assertEquals("abcdef", s);
}
+
+ public void testEmptyStringTrim() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "" );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( MutableString.EMPTY_STRING, result );
+ Assert.assertEquals( "", result.toString() );
+ }
+
+ public void testStringNoTrim() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "abcd" );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimLeft() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( " abcd" );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimRightFunc() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "abcd " );
+
+ MutableString result = ms.trimRight();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimLeftFunc() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( " abcd" );
+
+ MutableString result = ms.trimLeft();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimRight() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "abcd " );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimLeftRight() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( " abcd " );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( "abcd", result.toString() );
+ }
+
+ public void testStringTrimAll() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( " " );
+
+ MutableString result = ms.trim();
+
+ Assert.assertEquals( MutableString.EMPTY_STRING, result );
+ Assert.assertEquals( "", result.toString() );
+ }
+
+ public void testStringUpperCase() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "abCdEf" );
+
+ ms.toUpperCase();
+
+ Assert.assertEquals( "ABCDEF", ms.toString() );
+ }
+
+ public void testStringLowerCase() throws UnsupportedEncodingException
+ {
+ MutableString ms = new MutableString( "abCdEf" );
+
+ ms.toLowerCase();
+
+ Assert.assertEquals( "abcdef", ms.toString() );
+ }
/**
* Test a string with non ASCII chars
*
*/
-/* public void testNonASCIIString()
+ public void testNonASCIIString() throws UnsupportedEncodingException
{
- MutableString ms = new MutableString("Emmanuel Lécharny");
+ MutableString ms = new MutableString( new String( "Emmanuel Lécharny".getBytes(), "UTF-8") );
String s = ms.toString();
int msLength = ms.getLength();
@@ -52,5 +146,4 @@
Assert.assertEquals("Emmanuel Lécharny" , s);
Assert.assertEquals( sLength, msLength);
}
-*/
}
Modified: directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java?rev=291704&r1=291703&r2=291704&view=diff
==============================================================================
--- directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java (original)
+++ directory/asn1/branches/asn1-NameComponent/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java Mon Sep 26 11:31:46 2005
@@ -16,6 +16,8 @@
*/
package org.apache.asn1new.util;
+import java.io.UnsupportedEncodingException;
+
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -24,47 +26,162 @@
*/
public class StringUtilsTest extends TestCase {
- public void testOneByteChar()
- {
- char res = StringUtils.bytesToChar(new byte[]{0x30});
-
- Assert.assertEquals('0', res);
- }
-
- public void testOneByteChar00()
- {
- char res = StringUtils.bytesToChar(new byte[]{0x00});
-
- Assert.assertEquals(0x00, res);
- }
-
- public void testOneByteChar7F()
- {
- char res = StringUtils.bytesToChar(new byte[]{0x7F});
-
- Assert.assertEquals(0x7F, res);
- }
-
- public void testTwoBytesChar()
- {
- char res = StringUtils.bytesToChar(new byte[]{(byte)0xCE, (byte)0x91});
-
- Assert.assertEquals(0x0391, res);
- }
-
- public void testThreeBytesChar()
- {
- char res = StringUtils.bytesToChar(new byte[]{(byte)0xE2, (byte)0x89, (byte)0xA2});
-
- Assert.assertEquals(0x2262, res);
- }
-
- /*
- public void testSixBytesChar()
- {
- char res = StringUtils.bytesToChar(new byte[]{(byte)0xFD, (byte)0x93, (byte)0x91, (byte)0xBA, (byte)0x95, (byte)0xA3});
-
- Assert.assertEquals(0x7347A563, res);
- }
- */
+ public void testOneByteChar() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ StringUtils.decodeUTF8( res, new byte[]{0x30} );
+
+ Assert.assertEquals('0', res[0] );
+ }
+
+ public void testOneByteChar00() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ StringUtils.decodeUTF8( res, new byte[]{0x00} );
+
+ Assert.assertEquals(0x00, res[0] );
+ }
+
+ public void testOneByteChar7F() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ StringUtils.decodeUTF8( res, new byte[]{0x7F} );
+
+ Assert.assertEquals(0x7F, res[0] );
+ }
+
+ public void testTwoBytesChar() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ StringUtils.decodeUTF8( res, new byte[]{(byte)0xCE, (byte)0x91} );
+
+ Assert.assertEquals(0x0391, res[0] );
+ }
+
+ public void testThreeBytesChar() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ StringUtils.decodeUTF8( res, new byte[]{(byte)0xE2, (byte)0x89, (byte)0xA2} );
+
+ Assert.assertEquals(0x2262, res[0] );
+ }
+
+ public void testCharOneByte() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ byte[] bytesInit = new byte[]{0x30};
+ byte[] bytesRes = new byte[1];
+
+ StringUtils.decodeUTF8( res, bytesInit );
+
+ int pos = StringUtils.charToBytes( res[0], bytesRes, 0 );
+
+ Assert.assertEquals( bytesInit[0], bytesRes[0]);
+ Assert.assertEquals( 1, pos );
+ }
+
+ public void testCharOneByte00() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ byte[] bytesInit = new byte[]{0x00};
+ byte[] bytesRes = new byte[1];
+ StringUtils.decodeUTF8( res, bytesInit );
+
+ int pos = StringUtils.charToBytes( res[0], bytesRes, 0 );
+
+ Assert.assertEquals( bytesInit[0], bytesRes[0]);
+ Assert.assertEquals( 1, pos );
+ }
+
+ public void testCharOneByte7F() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ byte[] bytesInit = new byte[]{0x7F};
+ byte[] bytesRes = new byte[1];
+ StringUtils.decodeUTF8( res, bytesInit );
+
+ int pos = StringUtils.charToBytes( res[0], bytesRes, 0 );
+
+ Assert.assertEquals( bytesInit[0], bytesRes[0]);
+ Assert.assertEquals( 1, pos );
+ }
+
+ public void testCharTwoBytes() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ byte[] bytesInit = new byte[]{(byte)0xCE, (byte)0x91};
+ byte[] bytesRes = new byte[2];
+ StringUtils.decodeUTF8( res, bytesInit );
+
+ int pos = StringUtils.charToBytes( res[0], bytesRes, 0 );
+
+ Assert.assertEquals( bytesInit[0], bytesRes[0]);
+ Assert.assertEquals( bytesInit[1], bytesRes[1]);
+ Assert.assertEquals( 2, pos );
+ }
+
+ public void testCharThreeBytes() throws UnsupportedEncodingException
+ {
+ char[] res = new char[1];
+
+ byte[] bytesInit = new byte[]{(byte)0xE2, (byte)0x89, (byte)0xA2};
+ byte[] bytesRes = new byte[3];
+ StringUtils.decodeUTF8( res, bytesInit );
+
+ int pos = StringUtils.charToBytes( res[0], bytesRes, 0 );
+
+ Assert.assertEquals( bytesInit[0], bytesRes[0]);
+ Assert.assertEquals( bytesInit[1], bytesRes[1]);
+ Assert.assertEquals( bytesInit[2], bytesRes[2]);
+ Assert.assertEquals( 3, pos );
+ }
+
+ public void testTrimNull()
+ {
+ Assert.assertEquals( null, StringUtils.trim( null ) );
+ }
+
+ public void testTrimEmpty()
+ {
+ Assert.assertEquals( "", StringUtils.trim( "" ) );
+ }
+
+ public void testTrimOneSpace()
+ {
+ Assert.assertEquals( "", StringUtils.trim( " " ) );
+ }
+
+ public void testNoTrim()
+ {
+ Assert.assertEquals( "abcd", StringUtils.trim( "abcd" ) );
+ }
+
+ public void testTrimLeft()
+ {
+ Assert.assertEquals( "abcd", StringUtils.trim( " abcd" ) );
+ }
+
+ public void testTrimRight()
+ {
+ Assert.assertEquals( "abcd", StringUtils.trim( "abcd " ) );
+ }
+
+ public void testTrimFull()
+ {
+ Assert.assertEquals( "abcd", StringUtils.trim( " abcd " ) );
+ }
+
+ public void testTrimSpaces()
+ {
+ Assert.assertEquals( "", StringUtils.trim( " " ) );
+ }
}