1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwAccessibleDocumentView.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.AccessibilityTools
;
39 import util
.WriterTools
;
42 import com
.sun
.star
.accessibility
.AccessibleRole
;
43 import com
.sun
.star
.accessibility
.XAccessible
;
44 import com
.sun
.star
.accessibility
.XAccessibleContext
;
45 import com
.sun
.star
.accessibility
.XAccessibleValue
;
46 import com
.sun
.star
.awt
.XWindow
;
47 import com
.sun
.star
.frame
.XModel
;
48 import com
.sun
.star
.lang
.XMultiServiceFactory
;
49 import com
.sun
.star
.text
.ControlCharacter
;
50 import com
.sun
.star
.text
.XText
;
51 import com
.sun
.star
.text
.XTextCursor
;
52 import com
.sun
.star
.text
.XTextDocument
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
57 * Test of accessible object for the text document.<p>
58 * Object implements the following interfaces :
60 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
62 * @see com.sun.star.accessibility.XAccessible
64 public class SwAccessibleDocumentView
extends TestCase
{
66 XTextDocument xTextDoc
= null;
69 * Called to create an instance of <code>TestEnvironment</code>
70 * with an object to test and related objects. The method is called from
71 * <code>getTestEnvironment()</code>. Obtains accissible object for
74 * @param tParam test parameters
75 * @param log writer to log information while testing
77 * @see TestEnvironment
78 * @see #getTestEnvironment()
80 protected TestEnvironment
createTestEnvironment(
81 TestParameters Param
, PrintWriter log
) {
83 XInterface oObj
= null;
85 XText oText
= xTextDoc
.getText();
86 XTextCursor oCursor
= oText
.createTextCursor();
88 log
.println( "inserting some lines" );
90 for (int i
=0; i
<5; i
++){
91 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
92 oText
.insertString( oCursor
,
93 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
95 oText
.insertControlCharacter(
96 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
97 oText
.insertString( oCursor
,
98 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
100 oText
.insertControlCharacter(oCursor
,
101 ControlCharacter
.PARAGRAPH_BREAK
, false );
102 oText
.insertControlCharacter(
103 oCursor
, ControlCharacter
.LINE_BREAK
, false );
105 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
106 e
.printStackTrace(log
);
107 throw new StatusException( "Couldn't insert lines", e
);
110 XModel aModel
= (XModel
)
111 UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
113 AccessibilityTools at
= new AccessibilityTools();
115 XWindow xWindow
= at
.getCurrentWindow((XMultiServiceFactory
)Param
.getMSF(), aModel
);
116 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
118 at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.DOCUMENT
);
120 oObj
= AccessibilityTools
.SearchedContext
;
122 log
.println("ImplementationName " + utils
.getImplName(oObj
));
123 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
125 TestEnvironment tEnv
= new TestEnvironment(oObj
);
127 getAccessibleObjectForRole(xRoot
, AccessibleRole
.SCROLL_BAR
);
128 final XAccessibleValue xAccVal
= (XAccessibleValue
) UnoRuntime
.queryInterface
129 (XAccessibleValue
.class, SearchedContext
) ;
131 tEnv
.addObjRelation("EventProducer",
132 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
133 public void fireEvent() {
134 xAccVal
.setCurrentValue(xAccVal
.getMinimumValue());
135 xAccVal
.setCurrentValue(xAccVal
.getMaximumValue());
143 public static boolean first
= false;
144 public static XAccessibleContext SearchedContext
= null;
146 public static void getAccessibleObjectForRole(XAccessible xacc
,short role
) {
147 XAccessibleContext ac
= xacc
.getAccessibleContext();
148 if (ac
.getAccessibleRole()==role
) {
149 if (first
) SearchedContext
= ac
;
152 int k
= ac
.getAccessibleChildCount();
153 for (int i
=0;i
<k
;i
++) {
155 getAccessibleObjectForRole(ac
.getAccessibleChild(i
),role
);
156 if (SearchedContext
!= null) return ;
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
158 System
.out
.println("Couldn't get Child");
166 * Called while disposing a <code>TestEnvironment</code>.
167 * Disposes text document.
168 * @param tParam test parameters
169 * @param tEnv the environment to cleanup
170 * @param log writer to log information while testing
172 protected void cleanup( TestParameters Param
, PrintWriter log
) {
173 log
.println("dispose text document");
174 util
.DesktopTools
.closeDoc(xTextDoc
);
178 * Called while the <code>TestCase</code> initialization.
179 * Creates a text document.
181 * @param tParam test parameters
182 * @param log writer to log information while testing
184 * @see #initializeTestCase()
186 protected void initialize(TestParameters Param
, PrintWriter log
) {
187 log
.println( "creating a text document" );
188 xTextDoc
= WriterTools
.createTextDoc((XMultiServiceFactory
)Param
.getMSF());