From do-not-reply at jboss.org Wed Jan 4 09:11:59 2012 Content-Type: multipart/mixed; boundary="===============3378172445570682909==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r11961 - in trunk: tests/unit-tests/src/test/java/org/hornetq/tests/unit/util and 1 other directory. Date: Wed, 04 Jan 2012 09:11:58 -0500 Message-ID: <201201041411.q04EBwfo027733@svn01.web.mwc.hst.phx2.redhat.com> --===============3378172445570682909== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: borges Date: 2012-01-04 09:11:58 -0500 (Wed, 04 Jan 2012) New Revision: 11961 Modified: trunk/hornetq-commons/src/main/java/org/hornetq/api/core/SimpleString.ja= va trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/SimpleS= tringTest.java Log: HORNETQ-822 Fix SimpleString.charAt(int) conversion error Modified: trunk/hornetq-commons/src/main/java/org/hornetq/api/core/SimpleSt= ring.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/hornetq-commons/src/main/java/org/hornetq/api/core/SimpleString.j= ava 2012-01-04 13:26:24 UTC (rev 11960) +++ trunk/hornetq-commons/src/main/java/org/hornetq/api/core/SimpleString.j= ava 2012-01-04 14:11:58 UTC (rev 11961) @@ -25,7 +25,7 @@ * this minimises expensive copying between String objects. * * This object is used heavily throughout HornetQ for performance reasons. - * = + * * @author Tim Fox * */ @@ -116,7 +116,7 @@ } pos <<=3D 1; = - return (char)(data[pos] | data[pos + 1] << 8); + return (char)((data[pos] & 0xFF) | (data[pos + 1] << 8) & 0xFF00); } = public CharSequence subSequence(final int start, final int end) @@ -215,7 +215,7 @@ { return true; } - = + if (other instanceof SimpleString) { SimpleString s =3D (SimpleString)other; @@ -258,9 +258,8 @@ } = /** - * splits this SimpleString into an array of SimpleString using the cha= r param as the delimeter. - * - * i.e. "a.b" would return "a" and "b" if . was the delimeter + * Splits this SimpleString into an array of SimpleString using the cha= r param as the delimiter. + * i.e. "a.b" would return "a" and "b" if . was the delimiter * @param delim */ public SimpleString[] split(final char delim) @@ -272,11 +271,13 @@ else { List all =3D new ArrayList(); + + byte low =3D (byte)(delim & 0xFF); // low byte + byte high =3D (byte)(delim >> 8 & 0xFF); // high byte + int lasPos =3D 0; for (int i =3D 0; i < data.length; i +=3D 2) { - byte low =3D (byte)(delim & 0xFF); // low byte - byte high =3D (byte)(delim >> 8 & 0xFF); // high byte if (data[i] =3D=3D low && data[i + 1] =3D=3D high) { byte[] bytes =3D new byte[i - lasPos]; @@ -301,10 +302,11 @@ */ public boolean contains(final char c) { + final byte low =3D (byte)(c & 0xFF); // low byte + final byte high =3D (byte)(c >> 8 & 0xFF); // high byte + for (int i =3D 0; i < data.length; i +=3D 2) { - byte low =3D (byte)(c & 0xFF); // low byte - byte high =3D (byte)(c >> 8 & 0xFF); // high byte if (data[i] =3D=3D low && data[i + 1] =3D=3D high) { return true; @@ -314,10 +316,9 @@ } = /** - * concatanates a SimpleString and a String - * - * @param toAdd the String to concate with. - * @return the concatanated SimpleString + * Concatenates a SimpleString and a String + * @param toAdd the String to concatenate with. + * @return the concatenated SimpleString */ public SimpleString concat(final String toAdd) { @@ -325,10 +326,9 @@ } = /** - * concatanates 2 SimpleString's - * - * @param toAdd the SimpleString to concate with. - * @return the concatanated SimpleString + * Concatenates 2 SimpleString's + * @param toAdd the SimpleString to concatenate with. + * @return the concatenated SimpleString */ public SimpleString concat(final SimpleString toAdd) { @@ -339,10 +339,9 @@ } = /** - * concatanates a SimpleString and a char - * + * Concatenates a SimpleString and a char * @param c the char to concate with. - * @return the concatanated SimpleString + * @return the concatenated SimpleString */ public SimpleString concat(final char c) { @@ -390,7 +389,7 @@ } = /** - * = + * * @param srcBegin * @param srcEnd * @param dst Modified: trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/= SimpleStringTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/Simple= StringTest.java 2012-01-04 13:26:24 UTC (rev 11960) +++ trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/Simple= StringTest.java 2012-01-04 14:11:58 UTC (rev 11961) @@ -16,21 +16,63 @@ import java.util.concurrent.CountDownLatch; = import junit.framework.Assert; +import junit.framework.TestCase; = import org.hornetq.api.core.SimpleString; import org.hornetq.tests.util.RandomUtil; -import org.hornetq.tests.util.UnitTestCase; import org.hornetq.utils.DataConstants; = /** - * = + * * A SimpleStringTest - * = + * * @author Tim Fox * */ -public class SimpleStringTest extends UnitTestCase +public class SimpleStringTest extends TestCase { + /** + * Converting back and forth between char and byte requires care as cha= r is unsigned. + * @see SimpleString#getChars(int, int, char[], int) + * @see SimpleString#charAt(int) + * @see SimpleString#split(char) + */ + public void testGetChar() + { + SimpleString p1 =3D new SimpleString("foo"); + SimpleString p2 =3D new SimpleString("bar"); + for (int i =3D 0; i < 1 << 16; i++) + { + String msg =3D "expecting " + i; + char c =3D (char)i; + SimpleString s =3D new SimpleString(String.valueOf(c)); + + char[] c1 =3D new char[1]; + s.getChars(0, 1, c1, 0); + assertEquals(msg, c, c1[0]); + assertEquals(msg, c, s.charAt(0)); + SimpleString s2 =3D s.concat(c); + assertEquals(msg, c, s2.charAt(1)); + + // test splitting with chars + SimpleString sSplit =3D new SimpleString("foo" + String.valueOf(c= ) + "bar"); + SimpleString[] chunks =3D sSplit.split(c); + SimpleString[] split1 =3D p1.split(c); + SimpleString[] split2 =3D p2.split(c); + assertEquals(split1.length + split2.length, chunks.length); + int j =3D 0; + + for (SimpleString iS : split1) + { + assertEquals(iS.toString(), iS, chunks[j++]); + } + for (SimpleString iS : split2) + { + assertEquals(iS.toString(), iS, chunks[j++]); + } + } + } + public void testString() throws Exception { final String str =3D "hello123ABC__524`16254`6125!%^$!%$!%$!%$!%!$%!= $$!\uA324"; --===============3378172445570682909==--