1287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka/*
2287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * Licensed to the Apache Software Foundation (ASF) under one or more
3287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * contributor license agreements.  See the NOTICE file distributed with
4287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * this work for additional information regarding copyright ownership.
5287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * The ASF licenses this file to You under the Apache License, Version 2.0
6287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * (the "License"); you may not use this file except in compliance with
7287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * the License.  You may obtain a copy of the License at
8287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka *
9287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka *     http://www.apache.org/licenses/LICENSE-2.0
10287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka *
11287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * Unless required by applicable law or agreed to in writing, software
12287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS,
13287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * See the License for the specific language governing permissions and
15287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka * limitations under the License.
16287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka */
17287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
18287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokapackage org.apache.harmony.text.tests.java.text;
19287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
20287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.text.AttributedCharacterIterator;
21287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.text.AttributedCharacterIterator.Attribute;
22287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.ByteArrayInputStream;
23287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.ByteArrayOutputStream;
24287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.NotSerializableException;
25287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.IOException;
26287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.ObjectInputStream;
27287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.io.ObjectOutputStream;
28287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.util.Locale;
29287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokaimport java.text.Annotation;
30287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
31287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaokapublic class AttributedCharacterIteratorAttributeTest extends junit.framework.TestCase {
32287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
33287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	/**
34287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     * @tests java.text.AttributedCharacterIterator$Attribute()
35287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     */
36287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	public void test_constructor() {
37287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		MyAttribute attribute = new MyAttribute("attribute");
38287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
39287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertEquals("Attribute has wrong name", "attribute", attribute.getExposedName());
40287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
41287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		attribute = new MyAttribute(null);
42287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertEquals("Attribute has wrong name", null, attribute.getExposedName());
43287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	}
44287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
45287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	/**
46287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	 * @tests java.text.AttributedCharacterIterator.Attribute#equals(Object)
47287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	 */
48287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	public void test_equals() {
49287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
50287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertTrue(Attribute.LANGUAGE.equals(Attribute.LANGUAGE));
51287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
52287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertFalse(Attribute.LANGUAGE.equals(Attribute.READING));
53287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
54287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		MyAttribute attribute = new MyAttribute("test");
55287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
56287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertTrue(attribute.equals(attribute));
57287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
58287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		/* this implementation of equals should only return true
59287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		 * if the same objects */
60287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertFalse(attribute.equals(new MyAttribute("test")));
61287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
62287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		attribute = new MyAttribute(null);
63287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		assertFalse(attribute.equals(new MyAttribute(null)));
64287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	}
65287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
66287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	 /**
67287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     * @tests java.text.AttributedCharacterIterator$Attribute#readResolve()
68287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     */
69287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka    public void test_readResolve() {
70287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        // test for method java.lang.Object readResolve()
71287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
72287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        ObjectOutputStream out = null;
73287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        ObjectInputStream in = null;
74287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        try {
75287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
76287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            out = new ObjectOutputStream(bytes);
77287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
78287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            AttributedCharacterIterator.Attribute dattribute, dattribute2;
79287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            MyAttribute attribute;
80287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
81287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            // a regular instance of DateFormat.Field
82287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            dattribute = AttributedCharacterIterator.Attribute.LANGUAGE;
83287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
84287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            // a subclass instance with null name
85287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            attribute = new MyAttribute(null);
86287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
87287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            out.writeObject(dattribute);
88287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            try {
89287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                out.writeObject(attribute);
90287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            } catch (NotSerializableException e) {
91287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            }
92287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
93287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            in = new ObjectInputStream(new ByteArrayInputStream(bytes
94287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                    .toByteArray()));
95287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
96287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            try {
97287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                dattribute2 = (AttributedCharacterIterator.Attribute) in.readObject();
98287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                assertSame("resolved incorrectly", dattribute, dattribute2);
99287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            } catch (IllegalArgumentException e) {
100287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                fail("Unexpected IllegalArgumentException: " + e);
101287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            }
102287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
103287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        } catch (IOException e) {
104287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            fail("unexpected IOException" + e);
105287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        } catch (ClassNotFoundException e) {
106287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            fail("unexpected ClassNotFoundException" + e);
107287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        } finally {
108287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            try {
109287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                if (out != null)
110287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                    out.close();
111287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                if (in != null)
112287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka                    in.close();
113287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            } catch (IOException e) {
114287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka            }
115287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        }
116287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka    }
117287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
118287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka    /**
119287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     * @tests java.text.AttributedCharacterIterator$Attribute#LANGUAGE
120287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     * java.text.AttributedCharacterIterator$Attribute#READING
121287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     * java.text.AttributedCharacterIterator$Attribute#INPUT_METHOD_SEGMENT
122287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka     */
123287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	public void test_fields() {
124287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka
125287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        // Just check that the fields are accessible as all
126287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka        // methods are protected
127287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		Attribute language = Attribute.LANGUAGE;
128287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		Attribute reading = Attribute.READING;
129287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka		Attribute inputMethodSegment = Attribute.INPUT_METHOD_SEGMENT;
130287f4f83e9faa51efce6cc750c5a26b9556db728Tadashi G. Takaoka	}
131
132	protected void setUp() {
133	}
134
135	protected void tearDown() {
136	}
137
138	class MyAttribute extends AttributedCharacterIterator.Attribute {
139		protected MyAttribute(String name) {
140			super(name);
141		}
142
143		public Object getExposedName() {
144			return this.getName();
145		}
146	}
147}