Index: E:/projects/clear/eclipse/workspace/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java =================================================================== --- E:/projects/clear/eclipse/workspace/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java (revision 384131) +++ E:/projects/clear/eclipse/workspace/text/src/test/java/org/apache/harmony/tests/java/text/BreakIteratorTest.java (working copy) @@ -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; @@ -31,4 +32,143 @@ 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) { + } + } }