tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleDocumentView.java
blobcdae4e041f98d845241e5bedcd75e0b3d1479617
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.TestCase;
23 import lib.TestEnvironment;
24 import lib.TestParameters;
25 import util.AccessibilityTools;
26 import util.WriterTools;
27 import util.utils;
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleContext;
32 import com.sun.star.accessibility.XAccessibleValue;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.frame.XModel;
35 import com.sun.star.text.ControlCharacter;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test of accessible object for the text document.<p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
47 * </ul>
48 * @see com.sun.star.accessibility.XAccessible
50 public class SwAccessibleDocumentView extends TestCase {
52 XTextDocument xTextDoc = null;
54 /**
55 * Called to create an instance of <code>TestEnvironment</code>
56 * with an object to test and related objects. The method is called from
57 * <code>getTestEnvironment()</code>. Obtains accessible object for
58 * text document.
60 * @param Param test parameters
61 * @param log writer to log information while testing
63 * @see TestEnvironment
64 * @see #getTestEnvironment
66 @Override
67 protected TestEnvironment createTestEnvironment(
68 TestParameters Param, PrintWriter log) {
70 XInterface oObj = null;
72 XText oText = xTextDoc.getText();
73 XTextCursor oCursor = oText.createTextCursor();
75 log.println( "inserting some lines" );
76 for (int i=0; i<5; i++){
77 oText.insertString( oCursor,"Paragraph Number: " + i, false);
78 oText.insertString( oCursor,
79 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
80 false);
81 oText.insertControlCharacter(
82 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
83 oText.insertString( oCursor,
84 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
85 false);
86 oText.insertControlCharacter(oCursor,
87 ControlCharacter.PARAGRAPH_BREAK, false );
88 oText.insertControlCharacter(
89 oCursor, ControlCharacter.LINE_BREAK, false );
92 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
94 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
95 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
97 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
99 log.println("ImplementationName " + utils.getImplName(oObj));
100 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
102 TestEnvironment tEnv = new TestEnvironment(oObj);
104 getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR);
105 final XAccessibleValue xAccVal = UnoRuntime.queryInterface
106 (XAccessibleValue.class, SearchedContext) ;
108 tEnv.addObjRelation("EventProducer",
109 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
110 public void fireEvent() {
111 xAccVal.setCurrentValue(xAccVal.getMinimumValue());
112 xAccVal.setCurrentValue(xAccVal.getMaximumValue());
116 return tEnv;
120 public static boolean first = false;
121 public static XAccessibleContext SearchedContext = null;
123 public static void getAccessibleObjectForRole(XAccessible xacc,short role) {
124 XAccessibleContext ac = xacc.getAccessibleContext();
125 if (ac.getAccessibleRole()==role) {
126 if (first) SearchedContext = ac;
127 else first=true;
128 } else {
129 long k = ac.getAccessibleChildCount();
130 for (long i = 0; i < k; i++) {
131 try {
132 getAccessibleObjectForRole(ac.getAccessibleChild(i),role);
133 if (SearchedContext != null) return ;
134 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
135 System.out.println("Couldn't get Child");
143 * Called while disposing a <code>TestEnvironment</code>.
144 * Disposes text document.
145 * @param Param test parameters
146 * @param log writer to log information while testing
148 @Override
149 protected void cleanup( TestParameters Param, PrintWriter log) {
150 log.println("dispose text document");
151 util.DesktopTools.closeDoc(xTextDoc);
155 * Called while the <code>TestCase</code> initialization.
156 * Creates a text document.
158 * @param Param test parameters
159 * @param log writer to log information while testing
161 * @see #initializeTestCase
163 @Override
164 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
165 log.println( "creating a text document" );
166 xTextDoc = WriterTools.createTextDoc(Param.getMSF());