1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package mod._svx;
20 
21 import java.io.PrintWriter;
22 
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.SOfficeFactory;
28 import util.utils;
29 
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.XAccessibleEditableText;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.frame.XModel;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 
41 public class AccessibleEditableTextPara extends TestCase {
42 
43     static XComponent xSpreadsheetDoc = null;
44 
45     /**
46     * Called to create an instance of <code>TestEnvironment</code>
47     * with an object to test and related objects.
48     * Obtains accessible object for the spreadsheet document.
49     *
50     * @param Param test parameters
51     * @param log writer to log information while testing
52     *
53     * @see TestEnvironment
54     * @see #getTestEnvironment
55     */
56     @Override
createTestEnvironment( TestParameters Param, PrintWriter log)57     protected TestEnvironment createTestEnvironment(
58         TestParameters Param, PrintWriter log) {
59 
60         XInterface oObj = null;
61 
62 
63         XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
64 
65         XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
66         XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
67 
68         AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
69 
70         XAccessibleContext InputLine = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME,"Input line");
71         try {
72             oObj = InputLine.getAccessibleChild(0);
73             XAccessibleEditableText et = UnoRuntime.queryInterface(XAccessibleEditableText.class, oObj);
74             et.setText("AccessibleEditablePara");
75         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
76 
77         }
78         log.println("ImplementationName " + utils.getImplName(oObj));
79 
80         TestEnvironment tEnv = new TestEnvironment(oObj);
81 
82         final XAccessibleEditableText edText = UnoRuntime.queryInterface(XAccessibleEditableText.class,oObj) ;
83 
84         tEnv.addObjRelation("EventProducer",
85             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
86                 public void fireEvent() {
87                     try {
88                         int l = "AccessibleEditablePara".length();
89                         edText.deleteText(0, l);
90                         edText.setText("Event");
91                         edText.setText("AccessibleEditablePara");
92                     } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
93                         System.out.println("caught exception: " + e);
94                     }
95                 }
96             });
97 
98         return tEnv;
99 
100     }
101 
102     /**
103     * Called while disposing a <code>TestEnvironment</code>.
104     * Disposes text document.
105     * @param Param test parameters
106     * @param log writer to log information while testing
107     */
108     @Override
cleanup( TestParameters Param, PrintWriter log)109     protected void cleanup( TestParameters Param, PrintWriter log) {
110         log.println( "    disposing xSheetDoc " );
111         util.DesktopTools.closeDoc(xSpreadsheetDoc);
112     }
113 
114     /**
115      * Called while the <code>TestCase</code> initialization. In the
116      * implementation does nothing. Subclasses can override to initialize
117      * objects shared among all <code>TestEnvironment</code>s.
118      *
119      * @param Param test parameters
120      * @param log writer to log information while testing
121      *
122      * @see #initializeTestCase
123      */
124     @Override
initialize(TestParameters Param, PrintWriter log)125     protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
126         // get a soffice factory object
127         SOfficeFactory SOF = SOfficeFactory.getFactory(  Param.getMSF());
128 
129         log.println("creating a spreadsheetdocument");
130         xSpreadsheetDoc = UnoRuntime.queryInterface(XComponent.class,SOF.createCalcDoc(null));
131         util.utils.waitForEventIdle(Param.getMSF());
132     }
133 
134 }
135