You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC
svn commit: r386058 [43/49] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/archive/make/common/ modules/archive/src/test/java/tests/
modules/archive/src/test/java/tests/api/
modules/archive/src/test/java/tests/api/java/ modules/archive/...
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,50 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+/**
+ * Test UTF-16.
+ */
+public class UTF16CharsetTest extends ConcreteCharsetTest {
+
+ /**
+ * Constructor.
+ */
+ public UTF16CharsetTest(String arg0) {
+ super(arg0, "UTF-16", new String[] { "UTF_16" }, true, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+ */
+ public void testEncode_Normal() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+ */
+ public void testDecode_Normal() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,73 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+/**
+ * TODO typedef
+ */
+public class UTF16LECharsetDecoderTest extends CharsetDecoderTest {
+
+ protected void setUp() throws Exception {
+ cs = Charset.forName("utf-16le");
+ unibytes = new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
+ 114, 0 };
+ super.setUp();
+ }
+
+ /*
+ * @see CharsetDecoderTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // // FIXME: give up this tests
+ // public void testDefaultCharsPerByte(){
+ // // assertTrue(decoder.averageCharsPerByte() == 1);
+ // // assertTrue(decoder.maxCharsPerByte() == 1);
+ // assertEquals(decoder.averageCharsPerByte(), 0.5, 0.001);
+ // assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+ // }
+
+ ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+ // no unmap byte buffer
+ return null;
+ }
+
+ ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+ // FIXME: different here, JDK can parse 0xd8d8
+ // ByteBuffer buffer = ByteBuffer.allocate(100);
+ // buffer.put((byte)0xd8);
+ // buffer.put((byte)0xd8);
+ // buffer.put(unibytes);
+ // buffer.flip();
+ // return buffer;
+ return null;
+ }
+
+ ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+ return null;
+ }
+
+ byte[] getUnibytes() {
+ return new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0, 114,
+ 0 };
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,117 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+
+/**
+ * TODO type def
+ */
+public class UTF16LECharsetEncoderTest extends CharsetEncoderTest {
+
+ // charset for utf-16le
+ private static final Charset CS = Charset.forName("utf-16le");
+
+ /*
+ * @see CharsetEncoderTest#setUp()
+ */
+ protected void setUp() throws Exception {
+ cs = CS;
+ specifiedReplacement = new byte[] { -3, -1 };
+
+ unibytes = new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
+ 114, 0 };
+
+ // unibytesWithRep = new byte[] {(byte)0xfd, (byte)0xff, 32, 0, 98, 0,
+ // 117, 0, 102, 0, 102, 0, 101, 0, 114 ,0};
+
+ super.setUp();
+ }
+
+ /*
+ * @see CharsetEncoderTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCharsetEncoderCharsetfloatfloat() {
+ // this constructor is invalid for UTF16LE CharsetEncoder
+ }
+
+ public void testCanEncodechar() throws CharacterCodingException {
+ // normal case for utfCS
+ assertTrue(encoder.canEncode('\u0077'));
+ assertTrue(encoder.canEncode('\uc2a3'));
+
+ // for non-mapped char
+ assertTrue(encoder.canEncode('\uc2c0'));
+ }
+
+ public void testCanEncodeCharSequence() {
+ // normal case for utfCS
+ assertTrue(encoder.canEncode("\u0077"));
+ assertTrue(encoder.canEncode("\uc2a3"));
+ assertTrue(encoder.canEncode(""));
+
+ // for non-mapped char
+ assertTrue(encoder.canEncode("\uc2c0"));
+
+ // surrogate char for unicode
+ // 1st byte: d800-dbff
+ // 2nd byte: dc00-dfff
+ // valid surrogate pair
+ assertTrue(encoder.canEncode("\ud800\udc00"));
+ // invalid surrogate pair
+ assertFalse(encoder.canEncode("\ud800\udb00"));
+ }
+
+ public void testCanEncodeICUBug() {
+ assertFalse(encoder.canEncode("\ud800"));
+ }
+
+ public void testSpecificDefaultValue() {
+ assertTrue(encoder.averageBytesPerChar() == 2);
+ assertTrue(encoder.maxBytesPerChar() == 2);
+ }
+
+ public void testIsLegalReplacementEmptyArray() {
+ assertTrue(encoder.isLegalReplacement(new byte[0]));
+ }
+
+ CharBuffer getMalformedCharBuffer() {
+ return CharBuffer.wrap("\ud800 buffer");
+ }
+
+ CharBuffer getUnmapCharBuffer() {
+ return null;
+ }
+
+ CharBuffer getExceptionCharBuffer() {
+ return null;
+ }
+
+ protected byte[] getIllegalByteArray() {
+ return new byte[] { 0x00 };
+ }
+
+ protected byte[] getLegalByteArray() {
+ return new byte[] { (byte) 0xd8, 0x00 };
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,53 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+/**
+ * Test UTF-16LE.
+ */
+public class UTF16LECharsetTest extends ConcreteCharsetTest {
+
+ /**
+ * Constructor.
+ */
+ public UTF16LECharsetTest(String arg0) {
+ super(arg0, "UTF-16LE", new String[] { "UTF_16LE", "X-UTF-16LE" },
+ true, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+ */
+ public void testEncode_Normal() {
+ String input = "ab\u5D14\u654F";
+ byte[] output = new byte[] { 97, 0, 98, 0, 20, 93, 79, 101 };
+ internalTestEncode(input, output);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+ */
+ public void testDecode_Normal() {
+ byte[] input = new byte[] { 97, 0, 98, 0, 20, 93, 79, 101 };
+ char[] output = "ab\u5D14\u654F".toCharArray();
+ internalTestDecode(input, output);
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,52 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+/**
+ * Test UTF-8 charset.
+ */
+public class UTF8CharsetTest extends ConcreteCharsetTest {
+
+ /**
+ * Constructor for UTF8CharsetTest.
+ *
+ */
+ public UTF8CharsetTest(String arg0) {
+ super(arg0, "UTF-8", new String[] { "UTF8" }, true, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+ */
+ public void testDecode_Normal() {
+ byte[] input = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
+ char[] output = "ab\u5D14\u654F".toCharArray();
+ internalTestDecode(input, output);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+ */
+ public void testEncode_Normal() {
+ String input = "ab\u5D14\u654F";
+ byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
+ internalTestEncode(input, output);
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,62 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+/**
+ * test utf-8 decoder
+ */
+public class UTFCharsetDecoderTest extends CharsetDecoderTest {
+
+ protected void setUp() throws Exception {
+ cs = Charset.forName("utf-8");
+ super.setUp();
+ }
+
+ /*
+ * @see CharsetDecoderTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // FIXME: give up this tests
+ // public void testDefaultCharsPerByte(){
+ // assertEquals(decoder.averageCharsPerByte(), 0.333, 0.001);
+ // assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+ // // assertTrue(decoder.averageCharsPerByte() == 1);
+ // // assertTrue(decoder.maxCharsPerByte() == 1);
+ // }
+
+ ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+ return null;
+ }
+
+ ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+ ByteBuffer buffer = ByteBuffer.allocate(20);
+ buffer.put((byte) 0xd8);
+ buffer.put(unibytes);
+ buffer.flip();
+ return buffer;
+ }
+
+ ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+ return null;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,102 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+
+/**
+ * test case specific activity of utf-8 charset encoder
+ */
+public class UTFCharsetEncoderTest extends CharsetEncoderTest {
+
+ // charset for UTF-8
+ private static final Charset CS = Charset.forName("utf-8");
+
+ /*
+ * @see CharsetEncoderTest#setUp()
+ */
+ protected void setUp() throws Exception {
+ cs = CS;
+ specifiedReplacement = new byte[] { -17, -65, -67 };
+ super.setUp();
+ }
+
+ /*
+ * @see CharsetEncoderTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCanEncodechar() throws CharacterCodingException {
+ // normal case for utfCS
+ assertTrue(encoder.canEncode('\u0077'));
+ assertTrue(encoder.canEncode('\uc2a3'));
+
+ // for non-mapped char
+ assertTrue(encoder.canEncode('\uc2c0'));
+ }
+
+ public void testCanEncodeCharSequence() {
+ // normal case for utfCS
+ assertTrue(encoder.canEncode("\u0077"));
+ assertTrue(encoder.canEncode("\uc2a3"));
+ assertTrue(encoder.canEncode(""));
+
+ // for non-mapped char
+ assertTrue(encoder.canEncode("\uc2c0"));
+
+ // surrogate char for unicode
+ // 1st byte: d800-dbff
+ // 2nd byte: dc00-dfff
+ // valid surrogate pair
+ assertTrue(encoder.canEncode("\ud800\udc00"));
+ // invalid surrogate pair
+ assertFalse(encoder.canEncode("\ud800\udb00"));
+ }
+
+ public void testCanEncodeICUBug() {
+ assertFalse(encoder.canEncode("\ud800"));
+ }
+
+ public void testSpecificDefaultValue() {
+ // assertEquals(1.1, encoder.averageBytesPerChar(), 0.0001);
+ assertEquals(2, encoder.averageBytesPerChar(), 0.0001);
+ // assertEquals(4, encoder.maxBytesPerChar(), 0);
+ assertEquals(3, encoder.maxBytesPerChar(), 0);
+ }
+
+ CharBuffer getMalformedCharBuffer() {
+ return CharBuffer.wrap("\ud800 buffer");
+ }
+
+ CharBuffer getUnmapCharBuffer() {
+ return null;
+ }
+
+ CharBuffer getExceptionCharBuffer() {
+ return null;
+ }
+
+ protected byte[] getIllegalByteArray() {
+ return new byte[] { (byte) 0xd8, (byte) 0x00 };
+ }
+
+ protected void assertFlushed() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterException.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterException.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnmappableCharacterExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,72 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnmappableCharacterException;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Test class UnmappableCharacterException.
+ */
+public class UnmappableCharacterExceptionTest extends TestCase {
+
+ public void testConstructor() {
+ UnmappableCharacterException ex = new UnmappableCharacterException(3);
+ assertTrue(ex instanceof CharacterCodingException);
+ assertNull(ex.getCause());
+ assertEquals(ex.getInputLength(), 3);
+ assertTrue(ex.getMessage().indexOf("3") != -1);
+
+ ex = new UnmappableCharacterException(-3);
+ assertNull(ex.getCause());
+ assertEquals(ex.getInputLength(), -3);
+ assertTrue(ex.getMessage().indexOf("-3") != -1);
+
+ ex = new UnmappableCharacterException(0);
+ assertNull(ex.getCause());
+ assertEquals(ex.getInputLength(), 0);
+ assertTrue(ex.getMessage().indexOf("0") != -1);
+
+ }
+
+ /*
+ * Test serialization/deserialization.
+ */
+ public void testSerialization() throws Exception {
+ UnmappableCharacterException ex = new UnmappableCharacterException(11);
+
+ UnmappableCharacterException deEx = (UnmappableCharacterException) SerializationTester
+ .getDeserilizedObject(ex);
+ assertEquals(11, deEx.getInputLength());
+ }
+
+ /*
+ * Test serialization/deserialization compatibility with reference
+ * implementation.
+ */
+ public void testSerializationCompatibility() throws Exception {
+ UnmappableCharacterException ex = new UnmappableCharacterException(11);
+
+ UnmappableCharacterException deEx = (UnmappableCharacterException) SerializationTester
+ .readObject(ex,
+ "tests/api/java/nio/charset/UnmappableCharacterException.ser");
+ assertEquals(11, deEx.getInputLength());
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetException.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetException.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UnsupportedCharsetExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,74 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset;
+
+import java.nio.charset.UnsupportedCharsetException;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Test class UnsupportedCharsetException.
+ */
+public class UnsupportedCharsetExceptionTest extends TestCase {
+
+ public void testConstructor() {
+ UnsupportedCharsetException ex = new UnsupportedCharsetException(
+ "impossible");
+ assertTrue(ex instanceof IllegalArgumentException);
+ assertNull(ex.getCause());
+ assertEquals(ex.getCharsetName(), "impossible");
+ assertTrue(ex.getMessage().indexOf("impossible") != -1);
+
+ ex = new UnsupportedCharsetException("ascii");
+ assertNull(ex.getCause());
+ assertEquals(ex.getCharsetName(), "ascii");
+ assertTrue(ex.getMessage().indexOf("ascii") != -1);
+
+ ex = new UnsupportedCharsetException("");
+ assertNull(ex.getCause());
+ assertEquals(ex.getCharsetName(), "");
+ ex.getMessage();
+
+ ex = new UnsupportedCharsetException(null);
+ assertNull(ex.getCause());
+ assertEquals(ex.getCharsetName(), null);
+ assertTrue(ex.getMessage().indexOf("null") != -1);
+ }
+
+ /*
+ * Test serialization/deserialization.
+ */
+ public void testSerialization() throws Exception {
+ UnsupportedCharsetException ex = new UnsupportedCharsetException(
+ "charsetName");
+
+ UnsupportedCharsetException deEx = (UnsupportedCharsetException) SerializationTester
+ .getDeserilizedObject(ex);
+ }
+
+ /*
+ * Test serialization/deserialization.
+ */
+ public void testSerializationCompatibility() throws Exception {
+ UnsupportedCharsetException ex = new UnsupportedCharsetException(
+ "charsetName");
+
+ UnsupportedCharsetException deEx = (UnsupportedCharsetException) SerializationTester
+ .readObject(ex,
+ "tests/api/java/nio/charset/UnsupportedCharsetException.ser");
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,35 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset.spi;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Suite of tests for the java.nio.charset.spi package.");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(CharsetProviderTest.class);
+ // $JUnit-END$
+ return suite;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/CharsetProviderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/CharsetProviderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/CharsetProviderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/spi/CharsetProviderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,93 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.nio.charset.spi;
+
+import java.nio.charset.Charset;
+import java.nio.charset.spi.CharsetProvider;
+import java.security.Permission;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.nio.charset.spi.CharsetProvider.
+ */
+public class CharsetProviderTest extends TestCase {
+
+ /*
+ * Test the security check in the constructor.
+ */
+ public void testConstructor() {
+ // with sufficient privilege
+ new MockCharsetProvider();
+
+ SecurityManager oldMan = System.getSecurityManager();
+ System.setSecurityManager(new MockSecurityManager());
+ // set a normal value
+ try {
+ new MockCharsetProvider();
+ fail("Should throw SecurityException!");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldMan);
+ }
+ }
+
+ /*
+ * Test the signature.
+ */
+ static class MockCharsetProvider extends CharsetProvider {
+
+ public Charset charsetForName(String charsetName) {
+ return null;
+ }
+
+ public Iterator charsets() {
+ return null;
+ }
+ }
+
+ /*
+ * Used to grant all permissions except charset provider access.
+ */
+ public static class MockSecurityManager extends SecurityManager {
+
+ public MockSecurityManager() {
+ }
+
+ public void checkPermission(Permission perm) {
+ // grant all permissions except logging control
+ if (perm instanceof RuntimePermission) {
+ RuntimePermission rp = (RuntimePermission) perm;
+ if (rp.getName().equals("charsetProvider")) {
+ throw new SecurityException();
+ }
+ }
+ }
+
+ public void checkPermission(Permission perm, Object context) {
+ // grant all permissions except logging control
+ if (perm instanceof RuntimePermission) {
+ RuntimePermission rp = (RuntimePermission) perm;
+ if (rp.getName().equals("charsetProvider")) {
+ throw new SecurityException();
+ }
+ }
+ }
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/nio_char/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/nio_char/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/nio_char/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/nio_char/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,38 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.nio_char;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the NIO_Char project.
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All NIO_Char test suites");
+ // $JUnit-BEGIN$
+ suite.addTest(tests.api.java.nio.charset.AllTests.suite());
+ suite.addTest(tests.api.java.nio.charset.spi.AllTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}
\ No newline at end of file
Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml?rev=386058&r1=386057&r2=386058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml Wed Mar 15 03:46:17 2006
@@ -60,6 +60,7 @@
<include name="*.jar" />
</fileset>
</bootclasspath>
+ <classpath location="../../../../build/tests" />
</javac>
</target>
@@ -89,6 +90,14 @@
<batchtest todir="${hy.tests.reports}" haltonfailure="no">
<fileset dir="${hy.text.src.test.java}">
<include name="**/*Test.java"/>
+ <exclude name="**/AttributedCharacterIteratorTest.java"/>
+ <exclude name="**/ChoiceFormatTest.java"/>
+ <exclude name="**/CollationKeyTest.java"/>
+ <exclude name="**/CollatorTest.java"/>
+ <exclude name="**/DecimalFormatTest.java"/>
+ <exclude name="**/MessageFormatTest.java"/>
+ <exclude name="**/NumberFormatTest.java"/>
+ <exclude name="**/SimpleDateFormatTest.java"/>
</fileset>
</batchtest>
</junit>
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,57 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * TODO Type description
+ *
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Tests for java.text");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(BreakIteratorTest.class);
+ suite.addTestSuite(RuleBasedCollatorTest.class);
+ suite.addTestSuite(CollationElementIteratorTest.class);
+ suite.addTestSuite(BidiTest.class);
+
+ suite.addTestSuite(AnnotationTest.class);
+ suite.addTestSuite(AttributedCharacterIteratorTest.class);
+ suite.addTestSuite(AttributedStringTest.class);
+ suite.addTestSuite(ChoiceFormatTest.class);
+ suite.addTestSuite(CollationKeyTest.class);
+ suite.addTestSuite(CollatorTest.class);
+ suite.addTestSuite(DateFormatFieldTest.class);
+ suite.addTestSuite(DateFormatTest.class);
+ suite.addTestSuite(DateFormatSymbolsTest.class);
+ suite.addTestSuite(FieldPositionTest.class);
+ suite.addTestSuite(MessageFormatFieldTest.class);
+ suite.addTestSuite(MessageFormatTest.class);
+ suite.addTestSuite(NumberFormatFieldTest.class);
+ suite.addTestSuite(NumberFormatTest.class);
+ suite.addTestSuite(ParseExceptionTest.class);
+ suite.addTestSuite(ParsePositionTest.class);
+ suite.addTestSuite(SimpleDateFormatTest.class);
+ suite.addTestSuite(StringCharacterIteratorTest.class);
+
+ // $JUnit-END$
+ return suite;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AnnotationTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AnnotationTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AnnotationTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AnnotationTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,77 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.Annotation;
+
+public class AnnotationTest extends junit.framework.TestCase {
+
+ Annotation ant;
+
+ class Foo {
+ public String name;
+
+ public Foo(String s) {
+ name = s;
+ }
+ }
+
+ class Dummy {
+ public String name;
+
+ public int value;
+
+ public Dummy(String s, int i) {
+ name = s;
+ value = i;
+ }
+ }
+
+ Foo foo;
+ Dummy dummy;
+
+ /**
+ * @tests java.text.Annotation#Annotation(java.lang.Object)
+ */
+ public void test_ConstructorLjava_lang_Object() {
+ assertTrue("Used in testing.", true);
+ }
+
+ /**
+ * @tests java.text.Annotation#getValue()
+ */
+ public void test_getValue() {
+ assertTrue("getValue error", ant.getValue() == foo);
+ }
+
+ /**
+ * @tests java.text.Annotation#toString()
+ */
+ public void test_toString() {
+ ant = new Annotation("HelloWorld");
+ assertTrue("toString error.", ant.toString().equals(
+ "java.text.Annotation[value=HelloWorld]"));
+ }
+
+ protected void setUp() {
+ foo = new Foo("HelloWorld");
+ dummy = new Dummy("HelloWorld", 5);
+ ant = new Annotation(foo);
+
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedCharacterIteratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedCharacterIteratorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedCharacterIteratorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedCharacterIteratorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,177 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.text.CharacterIterator;
+
+public class AttributedCharacterIteratorTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#current()
+ */
+ public void test_current() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ assertTrue("Wrong first", it.current() == 'T');
+ it.next();
+ assertTrue("Wrong second", it.current() == 'e');
+ for (int i = 0; i < 9; i++)
+ it.next();
+ assertTrue("Wrong last", it.current() == 'g');
+ it.next();
+ assertTrue("Wrong final", it.current() == CharacterIterator.DONE);
+
+ it = attrString.getIterator(null, 2, 8);
+ assertTrue("Wrong first2", it.current() == 's');
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#first()
+ */
+ public void test_first() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ assertTrue("Wrong first1", it.first() == 'T');
+ it = attrString.getIterator(null, 0, 3);
+ assertTrue("Wrong first2", it.first() == 'T');
+ it = attrString.getIterator(null, 2, 8);
+ assertTrue("Wrong first3", it.first() == 's');
+ it = attrString.getIterator(null, 11, 11);
+ assertTrue("Wrong first4", it.first() == CharacterIterator.DONE);
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#getBeginIndex()
+ */
+ public void test_getBeginIndex() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator(null, 2, 6);
+ assertTrue("Wrong begin index", it.getBeginIndex() == 2);
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#getEndIndex()
+ */
+ public void test_getEndIndex() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator(null, 2, 6);
+ assertTrue("Wrong begin index", it.getEndIndex() == 6);
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#getIndex()
+ */
+ public void test_getIndex() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ assertTrue("Wrong first", it.getIndex() == 0);
+ it.next();
+ assertTrue("Wrong second", it.getIndex() == 1);
+ for (int i = 0; i < 9; i++)
+ it.next();
+ assertTrue("Wrong last", it.getIndex() == 10);
+ it.next();
+ assertTrue("Wrong final", it.getIndex() == 11);
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#last()
+ */
+ public void test_last() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ assertTrue("Wrong last1", it.last() == 'g');
+ it = attrString.getIterator(null, 0, 3);
+ assertTrue("Wrong last2", it.last() == 's');
+ it = attrString.getIterator(null, 2, 8);
+ assertTrue("Wrong last3", it.last() == 'r');
+ it = attrString.getIterator(null, 0, 0);
+ assertTrue("Wrong last4", it.last() == CharacterIterator.DONE);
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#next()
+ */
+ public void test_next() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ assertTrue("Wrong first", it.next() == 'e');
+ for (int i = 0; i < 8; i++)
+ it.next();
+ assertTrue("Wrong last", it.next() == 'g');
+ assertTrue("Wrong final", it.next() == CharacterIterator.DONE);
+
+ it = attrString.getIterator(null, 2, 8);
+ assertTrue("Wrong first2", it.next() == 't');
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#previous()
+ */
+ public void test_previous() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ it.setIndex(11);
+ assertTrue("Wrong first", it.previous() == 'g');
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#setIndex(int)
+ */
+ public void test_setIndexI() {
+ String test = "Test 23ring";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ it.setIndex(5);
+ assertTrue("Wrong first", it.current() == '2');
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator#getRunLimit(java.text.AttributedCharacterIterator$Attribute)
+ */
+ public void test_getRunLimitLjava_text_AttributedCharacterIterator$Attribute() {
+ AttributedString as = new AttributedString("test");
+ as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2,
+ 3);
+ AttributedCharacterIterator it = as.getIterator();
+ assertTrue(
+ "non-null value limit",
+ it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE) == 2);
+
+ as = new AttributedString("test");
+ as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null,
+ 2, 3);
+ it = as.getIterator();
+ assertTrue(
+ "null value limit",
+ it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE) == 4);
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedStringTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedStringTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedStringTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/AttributedStringTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,43 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.text.CharacterIterator;
+
+public class AttributedStringTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.text.AttributedString#AttributedString(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ String test = "Test string";
+ AttributedString attrString = new AttributedString(test);
+ AttributedCharacterIterator it = attrString.getIterator();
+ StringBuffer buf = new StringBuffer();
+ buf.append(it.first());
+ char ch;
+ while ((ch = it.next()) != CharacterIterator.DONE)
+ buf.append(ch);
+ assertTrue("Wrong string: " + buf, buf.toString().equals(test));
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BidiTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BidiTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BidiTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BidiTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,813 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+import java.text.AttributedString;
+import java.text.Bidi;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class BidiTest extends TestCase {
+
+ Bidi bd;
+
+ public static void assertRunArrayEquals(int[][] expected, Bidi bidi) {
+ assertEquals("different length", expected.length, bidi.getRunCount());
+
+ FORRUN: for (int i = 0; i < bidi.getRunCount(); i++) {
+ int[] butWas = new int[] { bidi.getRunStart(i),
+ bidi.getRunLimit(i), bidi.getRunLevel(i) };
+
+ for (int j = 0; j < expected.length; j++) {
+ if (expected[j][0] == butWas[0] && expected[j][1] == butWas[1]
+ && expected[j][2] == butWas[2]) {
+ continue FORRUN;
+ }
+ }
+ fail("expected [" + i + "] " + " start: " + butWas[0] + " limit: "
+ + butWas[1] + " level: " + butWas[2]);
+ }
+ }
+
+ public void testNullPointerConstructor() {
+ try {
+ bd = new Bidi(null, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ bd = new Bidi(null, 0, new byte[] { 0 }, 0, 0,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ bd = new Bidi("a".toCharArray(), 0, null, 0, 1,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ }
+
+ public void testBadLength() {
+ try {
+ bd = new Bidi("1".toCharArray(), 0, new byte[] { 0 }, 0, 20,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ bd = new Bidi("1234567".toCharArray(), 0, new byte[] { 0 }, 0, 4,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ bd = new Bidi("1234567".toCharArray(), 4, new byte[] { 0, 1, 2, 3,
+ 4 }, 0, 5, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ bd = new Bidi("1234567".toCharArray(), 0, new byte[] { 0, 1, 2, 3,
+ 4 }, 4, 5, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testEmptyParagraph() {
+ bd = new Bidi("", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(0, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 0, 0 } }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(0, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 0, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+
+ bd = new Bidi("", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(0, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 0, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(0, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 0, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+ }
+
+ public void testSpaceParagraph() {
+ bd = new Bidi(" ", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(" ", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+
+ bd = new Bidi(" ", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(" ", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+ }
+
+ public void testSimpleParagraph() {
+ bd = new Bidi("t", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("t", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("t", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testBadFlags() {
+ bd = new Bidi("", 173);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(0, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 0, 0 }, }, bd);
+ assertTrue(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testBadEmbeddings() {
+ try {
+ bd = new Bidi("".toCharArray(), 0, new byte[] {}, 0, 1,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testOverrideEmbeddings() {
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7,
+ (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(7, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 7 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1,
+ (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1,
+ (byte) -2, (byte) -3 }, 0, 3, Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1,
+ (byte) -2, (byte) -3 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testDefaultEmbeddings() {
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) 0,
+ (byte) 0, (byte) 0 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(2, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 3, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testRelativeEmbeddings() {
+ bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) 1,
+ (byte) 2, (byte) 3 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(4, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 2, 2 }, { 2, 3, 4 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testSimpleHebrewParagraph() {
+ bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+
+ bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+
+ bd = new Bidi("\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertFalse(bd.isMixed());
+ assertTrue(bd.isRightToLeft());
+ }
+
+ public void testSimpleBidiParagraph_1() {
+ bd = new Bidi("\u05D0a", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("\u05D0a", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("\u05D0a", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 0 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("\u05D0a", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testSimpleBidiParagraph_2() {
+ bd = new Bidi("a\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("a\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("a\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(0, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi("a\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(2, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(2, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ /*
+ * spec reads: public static final int DIRECTION_RIGHT_TO_LEFT Constant
+ * indicating base direction is right-to-left. according to that, the method
+ * baseIsLeftToRight() here should return false. however, RI doesn't act so.
+ */
+ public void testRIBug_1() {
+ bd = new Bidi("t", Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ // the base level it the essential cause
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ // this is essentially the same bug as Bug_1
+ public void testRIBug_2() {
+ bd = new Bidi("\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(1, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(1, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testComplicatedBidi() {
+ bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a",
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(9, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(2, bd.getLevelAt(2));
+ assertEquals(2, bd.getLevelAt(3));
+ assertEquals(2, bd.getLevelAt(4));
+ assertEquals(1, bd.getLevelAt(5));
+ assertEquals(1, bd.getLevelAt(6));
+ assertEquals(1, bd.getLevelAt(7));
+ assertEquals(2, bd.getLevelAt(8));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(5, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 },
+ { 2, 5, 2 }, { 5, 8, 1 }, { 8, 9, 2 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testComplicatedOverrideBidi() {
+ bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(), 0,
+ new byte[] { 0, 0, 0, -3, -3, 2, 2, 0, 3 }, 0, 9,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(9, bd.getLength());
+ assertEquals(2, bd.getLevelAt(0));
+ assertEquals(1, bd.getLevelAt(1));
+ assertEquals(2, bd.getLevelAt(2));
+ assertEquals(3, bd.getLevelAt(3));
+ assertEquals(3, bd.getLevelAt(4));
+ assertEquals(3, bd.getLevelAt(5));
+ assertEquals(2, bd.getLevelAt(6));
+ assertEquals(1, bd.getLevelAt(7));
+ assertEquals(4, bd.getLevelAt(8));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(7, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 },
+ { 2, 3, 2 }, { 3, 6, 3 }, { 6, 7, 2 }, { 7, 8, 1 },
+ { 8, 9, 4 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testRequiresBidi() {
+ assertFalse(Bidi.requiresBidi(null, 0, 0));
+
+ try {
+ assertFalse(Bidi.requiresBidi(null, 0, 1));
+ fail("should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 1));
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ assertFalse(Bidi.requiresBidi("".toCharArray(), -1, 1));
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ assertFalse(Bidi.requiresBidi("".toCharArray(), 1, 2));
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ assertFalse(Bidi.requiresBidi("".toCharArray(), 4, 5));
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ assertFalse(Bidi.requiresBidi("".toCharArray(), 7, 7));
+ assertFalse(Bidi.requiresBidi(" ".toCharArray(), 0, 1));
+ assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 1, -1));
+ assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), -1, -2));
+ assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 4, 4));
+ assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 3, 1));
+ assertTrue(Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1));
+ }
+
+ public void testHebrewOverrideEmbeddings() {
+ bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0,
+ new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0,
+ new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0,
+ new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_LEFT_TO_RIGHT);
+ assertTrue(bd.baseIsLeftToRight());
+ assertEquals(0, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(0, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+
+ bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0,
+ new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ assertFalse(bd.baseIsLeftToRight());
+ assertEquals(1, bd.getBaseLevel());
+ assertEquals(3, bd.getLength());
+ assertEquals(1, bd.getLevelAt(0));
+ assertEquals(2, bd.getLevelAt(1));
+ assertEquals(3, bd.getLevelAt(2));
+ assertEquals(1, bd.getLevelAt(1000));
+ assertEquals(3, bd.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 },
+ { 2, 3, 3 }, }, bd);
+ assertFalse(bd.isLeftToRight());
+ assertTrue(bd.isMixed());
+ assertFalse(bd.isRightToLeft());
+ }
+
+ public void testCreateLineBidi() {
+ bd = new Bidi("a\u05D0a\na\u05D0\"\u05D0a".toCharArray(), 0,
+ new byte[] { 0, 0, 0, -3, -3, 2, 2, 0, 3 }, 0, 9,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ Bidi line = bd.createLineBidi(2, 7);
+ assertFalse(line.baseIsLeftToRight());
+ assertEquals(1, line.getBaseLevel());
+ assertEquals(5, line.getLength());
+ assertEquals(2, line.getLevelAt(0));
+ assertEquals(1, line.getLevelAt(1));
+ assertEquals(3, line.getLevelAt(2));
+ assertEquals(3, line.getLevelAt(3));
+ assertEquals(2, line.getLevelAt(4));
+ assertEquals(1, line.getLevelAt(1000));
+ assertEquals(4, line.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 },
+ { 2, 4, 3 }, { 4, 5, 2 }, }, line);
+ assertFalse(line.isLeftToRight());
+ assertTrue(line.isMixed());
+ assertFalse(line.isRightToLeft());
+ }
+
+ public void testIncompatibleLineAlgorithm() {
+ // ICU treat a new line as in the same run, however RI does not
+ bd = new Bidi("aaaaa".toCharArray(), 0,
+ new byte[] { -2, -1, -3, -3, -2 }, 0, 5,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ Bidi line = bd.createLineBidi(1, 4);
+ assertFalse(line.baseIsLeftToRight());
+ assertEquals(1, line.getBaseLevel());
+ assertEquals(3, line.getLength());
+ assertEquals(1, line.getLevelAt(0));
+ assertEquals(1, line.getLevelAt(1));
+ assertEquals(1, line.getLevelAt(2));
+ assertEquals(1, line.getLevelAt(1000));
+ assertEquals(1, line.getRunCount());
+ assertRunArrayEquals(new int[][] { { 0, 3, 1 }, }, line);
+ assertFalse(line.isLeftToRight());
+ assertFalse(line.isMixed());
+ assertTrue(line.isRightToLeft());
+ }
+
+ public void testReorderVisually() {
+ String[] init = new String[] { "a", "b", "c", "d" };
+ String[] s = new String[4];
+
+ System.arraycopy(init, 0, s, 0, s.length);
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, 0, 4);
+ assertEquals("[c, b, a, d]", Arrays.asList(s).toString());
+
+ System.arraycopy(init, 0, s, 0, s.length);
+ Bidi.reorderVisually(new byte[] { 1, 3 }, 0, s, 1, 2);
+ assertEquals("[a, c, b, d]", Arrays.asList(s).toString());
+
+ System.arraycopy(init, 0, s, 0, s.length);
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 1, s, 1, 2);
+ assertEquals("[a, c, b, d]", Arrays.asList(s).toString());
+
+ System.arraycopy(init, 0, s, 0, s.length);
+ Bidi.reorderVisually(new byte[] { 2, 1, 2, 1 }, 1, s, 0, 3);
+ assertEquals("[c, b, a, d]", Arrays.asList(s).toString());
+
+ System.arraycopy(init, 0, s, 0, s.length);
+ Bidi.reorderVisually(new byte[] { 2, 1, 0, 1 }, 1, s, 0, 3);
+ assertEquals("[a, b, c, d]", Arrays.asList(s).toString());
+ }
+
+ public void testBadReorderVisually() {
+ String[] s = new String[] { "a", "b", "c", "d" };
+
+ try {
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, 0, 5);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, -1, 1);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, -1, s, 0, 1);
+ fail("should throw IAE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ Bidi.reorderVisually(null, 0, s, 0, 1);
+ fail("should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, null, 0, 1);
+ fail("should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+}