001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.TextComponent.AccessibleAWTTextComponent;
023:
024: import javax.accessibility.AccessibleRole;
025: import javax.accessibility.AccessibleState;
026: import javax.accessibility.AccessibleText;
027:
028: import junit.framework.TestCase;
029:
030: public class AccessibleAWTTextComponentTest extends TestCase {
031: TextComponent textComp;
032: AccessibleAWTTextComponent aTextComp;
033:
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: textComp = new TextField();
038: aTextComp = textComp.new AccessibleAWTTextComponent();
039: assertTrue(textComp.getAccessibleContext() instanceof AccessibleAWTTextComponent);
040: }
041:
042: /*
043: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getAccessibleRole()'
044: */
045: public void testGetAccessibleRole() {
046: assertSame(AccessibleRole.TEXT, aTextComp.getAccessibleRole());
047: }
048:
049: /*
050: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getAccessibleStateSet()'
051: */
052: public void testGetAccessibleStateSet() {
053: AccessibleState state = AccessibleState.EDITABLE;
054: assertTrue(aTextComp.getAccessibleStateSet().contains(state));
055: textComp.setEditable(false);
056: assertFalse(aTextComp.getAccessibleStateSet().contains(state));
057: textComp.setEditable(true);
058: assertTrue(aTextComp.getAccessibleStateSet().contains(state));
059: }
060:
061: public void testGetAccessibleText() {
062: assertSame(aTextComp, aTextComp.getAccessibleText());
063: }
064:
065: /*
066: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.AccessibleAWTTextComponent(TextComponent)'
067: */
068: public void testAccessibleAWTTextComponent() {
069: assertSame(aTextComp, textComp.getTextListeners()[0]);
070: }
071:
072: /*
073: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getCaretPosition()'
074: */
075: public void testGetCaretPosition() {
076: assertEquals(0, aTextComp.getCaretPosition());
077: textComp.setText("Text.");
078: assertEquals(0, aTextComp.getCaretPosition());
079: textComp.setCaretPosition(3);
080: assertEquals(3, aTextComp.getCaretPosition());
081: textComp.setCaretPosition(13);
082: assertEquals(5, aTextComp.getCaretPosition());
083:
084: }
085:
086: /*
087: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getCharCount()'
088: */
089: public void testGetCharCount() {
090: assertEquals(0, aTextComp.getCharCount());
091: String text = "text";
092: textComp.setText(text);
093: assertEquals(text.length(), aTextComp.getCharCount());
094: textComp.setText(null);
095: assertEquals(0, aTextComp.getCharCount());
096: }
097:
098: /*
099: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getSelectionEnd()'
100: */
101: public void testGetSelectionEnd() {
102: assertEquals(0, aTextComp.getSelectionEnd());
103: String text = "text";
104: textComp.setText(text);
105: assertEquals(0, aTextComp.getSelectionEnd());
106: textComp.select(1, 2);
107: assertEquals(2, aTextComp.getSelectionEnd());
108: }
109:
110: /*
111: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getSelectionStart()'
112: */
113: public void testGetSelectionStart() {
114: assertEquals(0, aTextComp.getSelectionStart());
115: String text = "text";
116: textComp.setText(text);
117: assertEquals(0, aTextComp.getSelectionStart());
118: textComp.select(1, 2);
119: assertEquals(1, aTextComp.getSelectionStart());
120: }
121:
122: /*
123: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getIndexAtPoint(Point)'
124: */
125: public void testGetIndexAtPoint() {
126: assertEquals(-1, aTextComp.getIndexAtPoint(new Point()));
127: }
128:
129: /*
130: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getCharacterBounds(int)'
131: */
132: public void testGetCharacterBounds() {
133: assertNull(aTextComp.getCharacterBounds(0));
134: }
135:
136: /*
137: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getSelectedText()'
138: */
139: public void testGetSelectedText() {
140: assertNull(aTextComp.getSelectedText());
141: String text = "text";
142: textComp.setText(text);
143: textComp.selectAll();
144: assertEquals(text, aTextComp.getSelectedText());
145: textComp.select(0, 1);
146: assertEquals(text.substring(0, 1), aTextComp.getSelectedText());
147:
148: }
149:
150: /*
151: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getAfterIndex(int, int)'
152: */
153: public void testGetAfterIndex() {
154: assertNull(aTextComp.getAfterIndex(AccessibleText.WORD, 5));
155: textComp.setText("This is some text.\n Second line.");
156: assertEquals("s", aTextComp.getAfterIndex(
157: AccessibleText.CHARACTER, 2));
158: assertEquals("Second", aTextComp.getAfterIndex(
159: AccessibleText.WORD, 13));
160: assertNull("no sentences", aTextComp.getAfterIndex(
161: AccessibleText.SENTENCE, 0));
162:
163: }
164:
165: /*
166: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getAtIndex(int, int)'
167: */
168: public void testGetAtIndex() {
169: assertNull(aTextComp.getAtIndex(AccessibleText.CHARACTER, 0));
170: textComp.setText("This is some text.\nSecond sentence.");
171: assertEquals("s", aTextComp.getAtIndex(
172: AccessibleText.CHARACTER, 3));
173: assertEquals("Second", aTextComp.getAtIndex(
174: AccessibleText.WORD, 19));
175: assertEquals("Second sentence.", aTextComp.getAtIndex(
176: AccessibleText.SENTENCE, 19));
177: }
178:
179: /*
180: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getBeforeIndex(int, int)'
181: */
182: public void testGetBeforeIndex() {
183: assertNull(aTextComp.getAtIndex(AccessibleText.SENTENCE, 1));
184: textComp
185: .setText("This is some text.\nSecond sentence. Third sentence.");
186: assertEquals("s", aTextComp.getBeforeIndex(
187: AccessibleText.CHARACTER, 4));
188: assertEquals("Second", aTextComp.getBeforeIndex(
189: AccessibleText.WORD, 26));
190: assertEquals("This is some text.\n", aTextComp.getBeforeIndex(
191: AccessibleText.SENTENCE, 20));
192: assertEquals("Second sentence. ", aTextComp.getBeforeIndex(
193: AccessibleText.SENTENCE, 38));
194: }
195:
196: /*
197: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.getCharacterAttribute(int)'
198: */
199: public void testGetCharacterAttribute() {
200: assertNull(aTextComp.getCharacterAttribute(0));
201: }
202:
203: /*
204: * Test method for 'java.awt.TextComponent.AccessibleAWTTextComponent.textValueChanged(TextEvent)'
205: */
206: public void testTextValueChanged() {
207: // nothing to check...
208:
209: }
210:
211: }
|