1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._sw;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.WriterTools;
33 import util.utils;
34 
35 import com.sun.star.accessibility.AccessibleRole;
36 import com.sun.star.accessibility.XAccessible;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XFootnote;
43 import com.sun.star.text.XText;
44 import com.sun.star.text.XTextCursor;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.view.XViewSettingsSupplier;
49 
50 public class SwAccessibleFootnoteView extends TestCase {
51 
52     XTextDocument xTextDoc = null;
53 
54     /**
55     * Called to create an instance of <code>TestEnvironment</code>
56     * with an object to test and related objects.
57     * Inserts the created footnote to the document.
58     * Changes zoom value to 10%(endnote must be in vissible area of the document).
59     * Obtains accessible object for the inserted footnote.
60     *
61     * @param tParam test parameters
62     * @param log writer to log information while testing
63     *
64     * @see TestEnvironment
65     * @see #getTestEnvironment
66     */
67     protected TestEnvironment createTestEnvironment(
68         TestParameters Param, PrintWriter log) {
69 
70         XInterface oObj = null;
71         XFootnote oFootnote = null;
72 
73         log.println( "Creating a test environment" );
74         // get a soffice factory object
75         XMultiServiceFactory msf = (XMultiServiceFactory)
76             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
77         log.println("creating a footnote");
78 
79         try {
80             oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class,
81                     msf.createInstance("com.sun.star.text.Footnote"));
82         } catch (com.sun.star.uno.Exception e) {
83             e.printStackTrace(log);
84             throw new StatusException("Couldn't create footnote", e);
85         }
86 
87         XText oText = xTextDoc.getText();
88         XTextCursor oCursor = oText.createTextCursor();
89 
90         log.println("inserting the footnote into text document");
91         try {
92             oText.insertTextContent(oCursor, oFootnote, false);
93         } catch (com.sun.star.lang.IllegalArgumentException e) {
94             e.printStackTrace(log);
95             throw new StatusException("Couldn't insert the footnote", e);
96         }
97 
98         XController xController = xTextDoc.getCurrentController();
99         XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
100                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
101                 xController);
102         XPropertySet xPropSet = xViewSetSup.getViewSettings();
103 
104         try {
105             //change zoom value to 10%
106             //footer should be in the vissible area of the document
107             xPropSet.setPropertyValue("ZoomValue", new Short("10"));
108         } catch ( com.sun.star.lang.WrappedTargetException e ) {
109             e.printStackTrace(log);
110             throw new StatusException("Couldn't set propertyValue...", e);
111         }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
112             e.printStackTrace(log);
113             throw new StatusException("Couldn't set propertyValue...", e);
114         } catch ( com.sun.star.beans.PropertyVetoException e ) {
115             e.printStackTrace(log);
116             throw new StatusException("Couldn't set propertyValue...", e);
117         } catch ( com.sun.star.beans.UnknownPropertyException e ) {
118             e.printStackTrace(log);
119             throw new StatusException("Couldn't set propertyValue...", e);
120         }
121 
122         XModel aModel = (XModel)
123             UnoRuntime.queryInterface(XModel.class, xTextDoc);
124 
125         AccessibilityTools at = new AccessibilityTools();
126 
127         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
128         XAccessible xRoot = at.getAccessibleObject(xWindow);
129 
130         at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE);
131 
132         oObj = AccessibilityTools.SearchedContext;
133 
134         log.println("ImplementationName " + utils.getImplName(oObj));
135         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
136 
137         TestEnvironment tEnv = new TestEnvironment(oObj);
138 
139         final XPropertySet PropSet = xViewSetSup.getViewSettings();
140 
141         tEnv.addObjRelation("EventProducer",
142             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
143                 public void fireEvent() {
144                     try {
145                         //change zoom value to 130%
146                         PropSet.setPropertyValue("ZoomValue", new Short("15"));
147                         //and back to 10%
148                         PropSet.setPropertyValue("ZoomValue", new Short("10"));
149                     } catch ( com.sun.star.lang.WrappedTargetException e ) {
150 
151                     }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
152 
153                     } catch ( com.sun.star.beans.PropertyVetoException e ) {
154 
155                     } catch ( com.sun.star.beans.UnknownPropertyException e ) {
156 
157                     }
158                 }
159             });
160 
161         return tEnv;
162 
163     }
164 
165     /**
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
171     */
172     protected void cleanup( TestParameters Param, PrintWriter log) {
173         log.println("dispose text document");
174         util.DesktopTools.closeDoc(xTextDoc);
175     }
176 
177     /**
178      * Called while the <code>TestCase</code> initialization. In the
179      * implementation does nothing. Subclasses can override to initialize
180      * objects shared among all <code>TestEnvironment</code>s.
181      *
182      * @param tParam test parameters
183      * @param log writer to log information while testing
184      *
185      * @see #initializeTestCase
186      */
187     protected void initialize(TestParameters Param, PrintWriter log) {
188         log.println( "creating a text document" );
189         xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());
190     }
191 }
192