2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.WriterTools
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.accessibility
.XAccessibleContext
;
33 import com
.sun
.star
.accessibility
.XAccessibleValue
;
34 import com
.sun
.star
.awt
.XWindow
;
35 import com
.sun
.star
.frame
.XModel
;
36 import com
.sun
.star
.text
.ControlCharacter
;
37 import com
.sun
.star
.text
.XText
;
38 import com
.sun
.star
.text
.XTextCursor
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test of accessible object for the text document.<p>
45 * Object implements the following interfaces :
47 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
49 * @see com.sun.star.accessibility.XAccessible
51 public class SwAccessibleDocumentView
extends TestCase
{
53 XTextDocument xTextDoc
= null;
56 * Called to create an instance of <code>TestEnvironment</code>
57 * with an object to test and related objects. The method is called from
58 * <code>getTestEnvironment()</code>. Obtains accissible object for
61 * @param Param test parameters
62 * @param log writer to log information while testing
64 * @see TestEnvironment
65 * @see #getTestEnvironment
68 protected TestEnvironment
createTestEnvironment(
69 TestParameters Param
, PrintWriter log
) {
71 XInterface oObj
= null;
73 XText oText
= xTextDoc
.getText();
74 XTextCursor oCursor
= oText
.createTextCursor();
76 log
.println( "inserting some lines" );
78 for (int i
=0; i
<5; i
++){
79 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
80 oText
.insertString( oCursor
,
81 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
83 oText
.insertControlCharacter(
84 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
85 oText
.insertString( oCursor
,
86 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
88 oText
.insertControlCharacter(oCursor
,
89 ControlCharacter
.PARAGRAPH_BREAK
, false );
90 oText
.insertControlCharacter(
91 oCursor
, ControlCharacter
.LINE_BREAK
, false );
93 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
94 e
.printStackTrace(log
);
95 throw new StatusException( "Couldn't insert lines", e
);
98 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
100 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
101 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
103 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.DOCUMENT
);
105 log
.println("ImplementationName " + utils
.getImplName(oObj
));
106 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
108 TestEnvironment tEnv
= new TestEnvironment(oObj
);
110 getAccessibleObjectForRole(xRoot
, AccessibleRole
.SCROLL_BAR
);
111 final XAccessibleValue xAccVal
= UnoRuntime
.queryInterface
112 (XAccessibleValue
.class, SearchedContext
) ;
114 tEnv
.addObjRelation("EventProducer",
115 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
116 public void fireEvent() {
117 xAccVal
.setCurrentValue(xAccVal
.getMinimumValue());
118 xAccVal
.setCurrentValue(xAccVal
.getMaximumValue());
126 public static boolean first
= false;
127 public static XAccessibleContext SearchedContext
= null;
129 public static void getAccessibleObjectForRole(XAccessible xacc
,short role
) {
130 XAccessibleContext ac
= xacc
.getAccessibleContext();
131 if (ac
.getAccessibleRole()==role
) {
132 if (first
) SearchedContext
= ac
;
135 int k
= ac
.getAccessibleChildCount();
136 for (int i
=0;i
<k
;i
++) {
138 getAccessibleObjectForRole(ac
.getAccessibleChild(i
),role
);
139 if (SearchedContext
!= null) return ;
140 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
141 System
.out
.println("Couldn't get Child");
149 * Called while disposing a <code>TestEnvironment</code>.
150 * Disposes text document.
151 * @param Param test parameters
152 * @param log writer to log information while testing
155 protected void cleanup( TestParameters Param
, PrintWriter log
) {
156 log
.println("dispose text document");
157 util
.DesktopTools
.closeDoc(xTextDoc
);
161 * Called while the <code>TestCase</code> initialization.
162 * Creates a text document.
164 * @param Param test parameters
165 * @param log writer to log information while testing
167 * @see #initializeTestCase
170 protected void initialize(TestParameters Param
, PrintWriter log
) {
171 log
.println( "creating a text document" );
172 xTextDoc
= WriterTools
.createTextDoc(Param
.getMSF());