Path: blob/master/test/jdk/javax/accessibility/4170173/AccessibleJTextAfterIndexTest.java
66644 views
/*1* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 417017327* @summary AccessibleJTextComponent.getAfterIndex works incorrectly28* @run main AccessibleJTextAfterIndexTest29*/3031import javax.accessibility.AccessibleText;32import javax.swing.JEditorPane;33import javax.swing.JTextArea;34import javax.swing.JTextField;35import javax.swing.SwingUtilities;3637public class AccessibleJTextAfterIndexTest {3839public static void doTest() {40JTextField jTextField =41new JTextField("Test1 Test2 Test3. Test4 Test5. Test6");42JTextArea jTextArea = new JTextArea("Test1 Test2 Test3.\nTest4 Test5");43JEditorPane jEditorPane =44new JEditorPane("text/plain", "Test1 Test2 Test3.\nTest4 Test5");4546String actualAccessibleText = jTextField.getAccessibleContext()47.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);48if (!(actualAccessibleText.equals("T"))) {49throw new RuntimeException(50"JTextField -" + "getAfterIndex() CHARACTER parameter"51+ " expected:--T--, actual:--" + actualAccessibleText + "--");52}5354actualAccessibleText = jTextField.getAccessibleContext()55.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);56if (!(actualAccessibleText.equals("Test2"))) {57throw new RuntimeException(58"JTextField - " + "getAfterIndex() WORD parameter"59+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");60}6162actualAccessibleText = jTextField.getAccessibleContext()63.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);64if (!(actualAccessibleText.equals("Test4 Test5. "))) {65throw new RuntimeException("JTextField - "66+ "getAfterIndex() SENTENCE parameter"67+ " expected:--Test4 Test5. --, actual:--" + actualAccessibleText + "--");68}6970actualAccessibleText = jTextArea.getAccessibleContext()71.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);72if (!(actualAccessibleText.equals("T"))) {73throw new RuntimeException(74"JTextArea - " + "getAfterIndex() CHARACTER parameter"75+ " expected:--T--, actual:--" + actualAccessibleText + "--");76}7778actualAccessibleText = jTextArea.getAccessibleContext()79.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);80if (!(actualAccessibleText.equals("Test2"))) {81throw new RuntimeException(82"JTextArea - " + "getAfterIndex() WORD parameter"83+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");84}8586actualAccessibleText = jTextArea.getAccessibleContext()87.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);88if (!(actualAccessibleText.equals("Test4 Test5\n"))) {89throw new RuntimeException("JTextArea - "90+ "getAfterIndex() SENTENCE parameter"91+ " expected:--Test4 Test5\n--, actual:--" + actualAccessibleText + "--");92}9394actualAccessibleText = jEditorPane.getAccessibleContext()95.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);96if (!(actualAccessibleText.equals("T"))) {97throw new RuntimeException(98"JEditorPane - " + "getAfterIndex() CHARACTER parameter"99+ " expected:--T--, actual:--" + actualAccessibleText +"--");100}101102actualAccessibleText = jEditorPane.getAccessibleContext()103.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);104if (!(actualAccessibleText.equals("Test2"))) {105throw new RuntimeException(106"JEditorPane - " + "getAfterIndex() WORD parameter"107+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");108}109110actualAccessibleText = jEditorPane.getAccessibleContext()111.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);112if (!(actualAccessibleText.equals("Test4 Test5\n"))) {113throw new RuntimeException("JEditorPane - "114+ "getAfterIndex() Sentence parameter"115+ " expected:--Test4 Test5\n--, actual:--" + actualAccessibleText +"--");116}117}118119public static void main(String[] args) throws Exception {120SwingUtilities.invokeAndWait(() -> doTest());121System.out.println("Test Passed");122}123}124125126