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 2009/07/13 13:38:54 UTC
svn commit: r793553 - in /harmony/enhanced/classlib/trunk/modules/text/src:
main/java/java/text/ test/java/org/apache/harmony/text/tests/java/text/
Author: tellison
Date: Mon Jul 13 11:38:53 2009
New Revision: 793553
URL: http://svn.apache.org/viewvc?rev=793553&view=rev
Log:
Apply modified patch for HARMONY-6267 ([classlib][text] Implementation of AttributedCharacterIterator.Attribute.equals should only return true if objects are the same)
Added:
harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java
harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java
harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java
Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java?rev=793553&r1=793552&r2=793553&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java (original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java Mon Jul 13 11:38:53 2009
@@ -89,10 +89,7 @@
*/
@Override
public final boolean equals(Object object) {
- if (object == null || !(object.getClass().equals(this.getClass()))) {
- return false;
- }
- return name.equals(((Attribute) object).name);
+ return this == object;
}
/**
@@ -113,7 +110,7 @@
*/
@Override
public final int hashCode() {
- return name.hashCode();
+ return super.hashCode();
}
/**
@@ -129,13 +126,13 @@
// text.0C=cannot resolve subclasses
throw new InvalidObjectException(Messages.getString("text.0C")); //$NON-NLS-1$
}
- if (this.equals(INPUT_METHOD_SEGMENT)) {
+ if (this.getName().equals(INPUT_METHOD_SEGMENT.getName())) {
return INPUT_METHOD_SEGMENT;
}
- if (this.equals(LANGUAGE)) {
+ if (this.getName().equals(LANGUAGE.getName())) {
return LANGUAGE;
}
- if (this.equals(READING)) {
+ if (this.getName().equals(READING.getName())) {
return READING;
}
// text.02=Unknown attribute
Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java?rev=793553&r1=793552&r2=793553&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java (original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java Mon Jul 13 11:38:53 2009
@@ -928,10 +928,16 @@
*/
@Override
protected Object readResolve() throws InvalidObjectException {
+ if (this.getClass() != Field.class) {
+ // text.0C=cannot resolve subclasses
+ throw new InvalidObjectException(Messages.getString("text.0C")); //$NON-NLS-1$
+ }
+
if (calendarField != -1) {
try {
Field result = ofCalendarField(calendarField);
- if (result != null && this.equals(result)) {
+
+ if (result != null && this.getName().equals(result.getName())) {
return result;
}
} catch (IllegalArgumentException e) {
Added: harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java?rev=793553&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java Mon Jul 13 11:38:53 2009
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text;
+
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.NotSerializableException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Locale;
+import java.text.Annotation;
+
+public class AttributedCharacterIteratorAttributeTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.text.AttributedCharacterIterator$Attribute()
+ */
+ public void test_constructor() {
+ MyAttribute attribute = new MyAttribute("attribute");
+
+ assertEquals("Attribute has wrong name", "attribute", attribute.getExposedName());
+
+ attribute = new MyAttribute(null);
+ assertEquals("Attribute has wrong name", null, attribute.getExposedName());
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator.Attribute#equals(Object)
+ */
+ public void test_equals() {
+
+ assertTrue(Attribute.LANGUAGE.equals(Attribute.LANGUAGE));
+
+ assertFalse(Attribute.LANGUAGE.equals(Attribute.READING));
+
+ MyAttribute attribute = new MyAttribute("test");
+
+ assertTrue(attribute.equals(attribute));
+
+ /* this implementation of equals should only return true
+ * if the same objects */
+ assertFalse(attribute.equals(new MyAttribute("test")));
+
+ attribute = new MyAttribute(null);
+ assertFalse(attribute.equals(new MyAttribute(null)));
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator$Attribute#readResolve()
+ */
+ public void test_readResolve() {
+ // test for method java.lang.Object readResolve()
+
+ ObjectOutputStream out = null;
+ ObjectInputStream in = null;
+ try {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ out = new ObjectOutputStream(bytes);
+
+ AttributedCharacterIterator.Attribute dattribute, dattribute2;
+ MyAttribute attribute;
+
+ // a regular instance of DateFormat.Field
+ dattribute = AttributedCharacterIterator.Attribute.LANGUAGE;
+
+ // a subclass instance with null name
+ attribute = new MyAttribute(null);
+
+ out.writeObject(dattribute);
+ try {
+ out.writeObject(attribute);
+ } catch (NotSerializableException e) {
+ }
+
+ in = new ObjectInputStream(new ByteArrayInputStream(bytes
+ .toByteArray()));
+
+ try {
+ dattribute2 = (AttributedCharacterIterator.Attribute) in.readObject();
+ assertSame("resolved incorrectly", dattribute, dattribute2);
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException: " + e);
+ }
+
+ } catch (IOException e) {
+ fail("unexpected IOException" + e);
+ } catch (ClassNotFoundException e) {
+ fail("unexpected ClassNotFoundException" + e);
+ } finally {
+ try {
+ if (out != null)
+ out.close();
+ if (in != null)
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ /**
+ * @tests java.text.AttributedCharacterIterator$Attribute#LANGUAGE
+ * java.text.AttributedCharacterIterator$Attribute#READING
+ * java.text.AttributedCharacterIterator$Attribute#INPUT_METHOD_SEGMENT
+ */
+ public void test_fields() {
+
+ // Just check that the fields are accessible as all
+ // methods are protected
+ Attribute language = Attribute.LANGUAGE;
+ Attribute reading = Attribute.READING;
+ Attribute inputMethodSegment = Attribute.INPUT_METHOD_SEGMENT;
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+
+ class MyAttribute extends AttributedCharacterIterator.Attribute {
+ protected MyAttribute(String name) {
+ super(name);
+ }
+
+ public Object getExposedName() {
+ return this.getName();
+ }
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java?rev=793553&r1=793552&r2=793553&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java Mon Jul 13 11:38:53 2009
@@ -165,14 +165,13 @@
FieldPosition fpos = new FieldPosition(1);
fpos.setBeginIndex(5);
fpos.setEndIndex(110);
- assertEquals("hashCode returned incorrect value", 620, fpos.hashCode());
+ fpos.hashCode();
FieldPosition fpos2 = new FieldPosition(
DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
fpos2.setBeginIndex(5);
fpos2.setEndIndex(110);
- assertEquals("hashCode returned incorrect value", 451685956, fpos2
- .hashCode());
+ fpos2.hashCode();
}
/**