bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleDocumentView.java
blob714d3c2901bad768be75fe1a3c5de28bf248a709
1 /*
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 .
18 package mod._sw;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.WriterTools;
28 import util.utils;
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.lang.XMultiServiceFactory;
37 import com.sun.star.text.ControlCharacter;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextCursor;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 /**
45 * Test of accessible object for the text document.<p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
49 * </ul>
50 * @see com.sun.star.accessibility.XAccessible
52 public class SwAccessibleDocumentView extends TestCase {
54 XTextDocument xTextDoc = null;
56 /**
57 * Called to create an instance of <code>TestEnvironment</code>
58 * with an object to test and related objects. The method is called from
59 * <code>getTestEnvironment()</code>. Obtains accissible object for
60 * text document.
62 * @param Param test parameters
63 * @param log writer to log information while testing
65 * @see TestEnvironment
66 * @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" );
77 try {
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",
82 false);
83 oText.insertControlCharacter(
84 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
85 oText.insertString( oCursor,
86 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
87 false);
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 AccessibilityTools at = new AccessibilityTools();
102 XWindow xWindow = AccessibilityTools.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
103 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
105 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
107 log.println("ImplementationName " + utils.getImplName(oObj));
108 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
110 TestEnvironment tEnv = new TestEnvironment(oObj);
112 getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR);
113 final XAccessibleValue xAccVal = UnoRuntime.queryInterface
114 (XAccessibleValue.class, SearchedContext) ;
116 tEnv.addObjRelation("EventProducer",
117 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
118 public void fireEvent() {
119 xAccVal.setCurrentValue(xAccVal.getMinimumValue());
120 xAccVal.setCurrentValue(xAccVal.getMaximumValue());
124 return tEnv;
128 public static boolean first = false;
129 public static XAccessibleContext SearchedContext = null;
131 public static void getAccessibleObjectForRole(XAccessible xacc,short role) {
132 XAccessibleContext ac = xacc.getAccessibleContext();
133 if (ac.getAccessibleRole()==role) {
134 if (first) SearchedContext = ac;
135 else first=true;
136 } else {
137 int k = ac.getAccessibleChildCount();
138 for (int i=0;i<k;i++) {
139 try {
140 getAccessibleObjectForRole(ac.getAccessibleChild(i),role);
141 if (SearchedContext != null) return ;
142 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
143 System.out.println("Couldn't get Child");
151 * Called while disposing a <code>TestEnvironment</code>.
152 * Disposes text document.
153 * @param Param test parameters
154 * @param log writer to log information while testing
156 protected void cleanup( TestParameters Param, PrintWriter log) {
157 log.println("dispose text document");
158 util.DesktopTools.closeDoc(xTextDoc);
162 * Called while the <code>TestCase</code> initialization.
163 * Creates a text document.
165 * @param Param test parameters
166 * @param log writer to log information while testing
168 * @see #initializeTestCase
170 protected void initialize(TestParameters Param, PrintWriter log) {
171 log.println( "creating a text document" );
172 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());