harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r385636 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/BreakIterator.java test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java
Date Mon, 13 Mar 2006 19:46:38 GMT
Author: tellison
Date: Mon Mar 13 11:46:37 2006
New Revision: 385636

URL: http://svn.apache.org/viewcvs?rev=385636&view=rev
Log:
Apply patch for HARMONY-172 (Harmony text component has some API difference with JSE 5 spec)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java?rev=385636&r1=385635&r2=385636&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
Mon Mar 13 11:46:37 2006
@@ -61,6 +61,10 @@
 	 */
 	public static final int DONE = -1;
 
+	private static final int LONG_LENGTH = 8;
+	private static final int INT_LENGTH = 4;
+	private static final int SHORT_LENGTH = 2;
+
 	/*
 	 * -----------------------------------------------------------------------
 	 * variables
@@ -365,26 +369,65 @@
 	}
 
 	/**
-	 * This method is added by Java SE 5 without any spec, but will be removed
-	 * by Java SE 6, so this method is not implemented by Harmony.
+	 * Get a long value from the given byte array, start from given offset.
+	 * 
+	 * @param buf	the bytes to be converted
+	 * @param offset	the start position of conversion
+	 * @return	the converted long value
 	 */
 	protected static long getLong(byte[] buf, int offset) {
-		throw new NotYetImplementedException();
+		if(null == buf){
+			throw new NullPointerException();
+		}
+		if(offset < 0 || offset + LONG_LENGTH > buf.length){
+			throw new ArrayIndexOutOfBoundsException();
+		}
+		long result = 0;
+		for (int i = offset; i < offset + LONG_LENGTH; i++) {
+			result = (result << 8) | (buf[i] & 0xff);
+		}
+		return result;
 	}
 
 	/**
-	 * This method is added by Java SE 5 without any spec, but will be removed
-	 * by Java SE 6, so this method is not implemented by Harmony.
-	 */
+	 * Get a ing value from the given byte array, start from given offset.
+	 * 
+	 * @param buf	the bytes to be converted
+	 * @param offset	the start position of conversion
+	 * @return	the converted int value
+	 */	
 	protected static int getInt(byte[] buf, int offset) {
-		throw new NotYetImplementedException();
+		if(null == buf){
+			throw new NullPointerException();
+		}
+		if(offset < 0 || offset + INT_LENGTH > buf.length){
+			throw new ArrayIndexOutOfBoundsException();
+		}
+		int result = 0;
+		for (int i = offset; i < offset + INT_LENGTH; i++) {
+			result = (result << 8) | (buf[i] & 0xff);
+		}
+		return result;
 	}
 
 	/**
-	 * This method is added by Java SE 5 without any spec, but will be removed
-	 * by Java SE 6, so this method is not implemented by Harmony.
+	 * Get a short value from the given byte array, start from given offset.
+	 * 
+	 * @param buf	the bytes to be converted
+	 * @param offset	the start position of conversion
+	 * @return	the converted short value
 	 */
 	protected static short getShort(byte[] buf, int offset) {
-		throw new NotYetImplementedException();
+		if(null == buf){
+			throw new NullPointerException();
+		}
+		if(offset < 0 || offset + SHORT_LENGTH > buf.length){
+			throw new ArrayIndexOutOfBoundsException();
+		}
+		short result = 0;
+		for (int i = offset; i < offset + SHORT_LENGTH; i++) {
+			result = (short)((result << 8) | (buf[i] & 0xff));
+		}
+		return result;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java?rev=385636&r1=385635&r2=385636&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java
Mon Mar 13 11:46:37 2006
@@ -17,6 +17,7 @@
 package org.apache.harmony.tests.java.text;
 
 import java.text.BreakIterator;
+import java.text.CharacterIterator;
 import java.util.Locale;
 
 import junit.framework.TestCase;
@@ -30,5 +31,144 @@
 		int n = bi.first();
 		n = bi.next();
 		assertEquals("Assert 0: next() returns incorrect value ", 4, n);
+	}
+
+	public void test_getShort() {
+		try {
+			MockBreakIterator.publicGetShort(null, 0);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetShort(null, -1);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetShort(new byte[] { 0, 0, 0, 1 , 1}, -1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		try {
+			MockBreakIterator.publicGetShort(new byte[] { 0, 0 }, 1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		assertEquals(0, MockBreakIterator.publicGetShort(new byte[] { 0, 0 }, 0));
+		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 1 }, 0));
+		assertEquals(-1, MockBreakIterator.publicGetShort(new byte[] { (byte)0xff, (byte)0xff },
0));
+		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 1, 0, 1, 0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1, 0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1, 1 }, 1));
+		assertEquals(257, MockBreakIterator.publicGetShort(new byte[] { 0, 1, 1 }, 1));
+	}
+	
+	public void test_getInt() {
+		try {
+			MockBreakIterator.publicGetInt(null, 0);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetInt(null, -1);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 1 , 1}, -1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		try {
+			MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0}, 1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		assertEquals(0, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0 }, 0));
+		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 1 }, 0));
+		assertEquals(-1, MockBreakIterator.publicGetInt(new byte[] { (byte)0xff, (byte)0xff, (byte)0xff,
(byte)0xff }, 0));
+		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 1, 0, 0, 0, 1, 0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0, 1, 0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0, 1, 1 }, 1));
+		assertEquals(257, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 1, 1 }, 1));
+	}
+	
+	public void test_getLong() {
+		try {
+			MockBreakIterator.publicGetLong(null, 0);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetLong(null, -1);
+			fail("should throw NPE.");
+		} catch (NullPointerException e) {
+		}
+		try {
+			MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 1, 1}, -1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		try {
+			MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 1, 1}, 1);
+			fail("should throw ArrayIndexOutOfBoundsException.");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+		assertEquals(0, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 },
0));
+		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 },
0));
+		assertEquals(-1, MockBreakIterator.publicGetLong(new byte[] { (byte)0xff, (byte)0xff, (byte)0xff,
(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, 0));
+		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 1,
0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1,
0 }, 1));
+		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1,
1 }, 1));
+		assertEquals(257, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1,
1 }, 1));
+	}
+
+	private static class MockBreakIterator extends BreakIterator {
+		public static int publicGetInt(byte[] buf, int offset) {
+			return BreakIterator.getInt(buf, offset);
+		}
+
+		public static long publicGetLong(byte[] buf, int offset) {
+			return BreakIterator.getLong(buf, offset);
+		}
+
+		public static short publicGetShort(byte[] buf, int offset) {
+			return BreakIterator.getShort(buf, offset);
+		}
+
+		public int current() {
+			return 0;
+		}
+
+		public int first() {
+			return 0;
+		}
+
+		public int following(int offset) {
+			return 0;
+		}
+
+		public CharacterIterator getText() {
+			return null;
+		}
+
+		public int last() {
+			return 0;
+		}
+
+		public int next() {
+			return 0;
+		}
+
+		public int next(int n) {
+			return 0;
+		}
+
+		public int previous() {
+			return 0;
+		}
+
+		public void setText(CharacterIterator newText) {
+		}
 	}
 }



Mime
View raw message