1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._sw;
28 
29 import java.io.PrintWriter;
30 
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.AccessibilityTools;
36 import util.WriterTools;
37 import util.utils;
38 
39 import com.sun.star.accessibility.AccessibleRole;
40 import com.sun.star.accessibility.XAccessible;
41 import com.sun.star.awt.XWindow;
42 import com.sun.star.beans.XPropertySet;
43 import com.sun.star.frame.XController;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.XText;
47 import com.sun.star.text.XTextContent;
48 import com.sun.star.text.XTextCursor;
49 import com.sun.star.text.XTextDocument;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.view.XViewSettingsSupplier;
53 
54 public class SwAccessibleEndnoteView extends TestCase {
55 
56     XTextDocument xTextDoc = null;
57 
58     /**
59     * Called to create an instance of <code>TestEnvironment</code>
60     * with an object to test and related objects.
61     * Inserts the created endnote to the document.
62     * Changes zoom value to 10%(endnote must be in vissible area of the document).
63     * Obtains accessible object for the inserted endnote.
64     *
65     * @param tParam test parameters
66     * @param log writer to log information while testing
67     *
68     * @see TestEnvironment
69     * @see #getTestEnvironment()
70     */
71     protected TestEnvironment createTestEnvironment(
72         TestParameters Param, PrintWriter log) {
73 
74         XInterface oObj = null;
75         XInterface oEndnote = null;
76 
77         log.println( "Creating a test environment" );
78         XMultiServiceFactory msf = (XMultiServiceFactory)
79             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
80         log.println("creating a endnote");
81         try {
82             oEndnote = (XInterface) UnoRuntime.queryInterface(XInterface.class,
83                     msf.createInstance("com.sun.star.text.Endnote"));
84         } catch (com.sun.star.uno.Exception e) {
85             e.printStackTrace(log);
86             throw new StatusException("Couldn't create endnote", e);
87         }
88 
89         XText oText = xTextDoc.getText();
90         XTextCursor oCursor = oText.createTextCursor();
91 
92         log.println("inserting the footnote into text document");
93         XTextContent xTC = (XTextContent)
94             UnoRuntime.queryInterface(XTextContent.class, oEndnote);
95         try {
96             oText.insertTextContent(oCursor, xTC, false);
97         } catch (com.sun.star.lang.IllegalArgumentException e) {
98             e.printStackTrace(log);
99             throw new StatusException("Couldn't insert the endnote", e);
100         }
101 
102         XController xController = xTextDoc.getCurrentController();
103         XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
104                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
105                 xController);
106         XPropertySet xPropSet = xViewSetSup.getViewSettings();
107 
108         try {
109             //change zoom value to 10%
110             //footer should be in the vissible area of the document
111             xPropSet.setPropertyValue("ZoomValue", new Short("10"));
112         } catch ( com.sun.star.lang.WrappedTargetException e ) {
113             e.printStackTrace(log);
114             throw new StatusException("Couldn't set propertyValue...", e);
115         }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
116             e.printStackTrace(log);
117             throw new StatusException("Couldn't set propertyValue...", e);
118         } catch ( com.sun.star.beans.PropertyVetoException e ) {
119             e.printStackTrace(log);
120             throw new StatusException("Couldn't set propertyValue...", e);
121         } catch ( com.sun.star.beans.UnknownPropertyException e ) {
122             e.printStackTrace(log);
123             throw new StatusException("Couldn't set propertyValue...", e);
124         }
125 
126         XModel aModel = (XModel)
127             UnoRuntime.queryInterface(XModel.class, xTextDoc);
128 
129         AccessibilityTools at = new AccessibilityTools();
130 
131         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
132         XAccessible xRoot = at.getAccessibleObject(xWindow);
133 
134         at.getAccessibleObjectForRole(xRoot, AccessibleRole.END_NOTE);
135 
136         oObj = AccessibilityTools.SearchedContext;
137 
138         log.println("ImplementationName " + utils.getImplName(oObj));
139         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
140 
141         TestEnvironment tEnv = new TestEnvironment(oObj);
142 
143         final XPropertySet PropSet = xViewSetSup.getViewSettings();
144 
145         tEnv.addObjRelation("EventProducer",
146             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
147                 public void fireEvent() {
148                     try {
149                         //change zoom value to 130%
150                         PropSet.setPropertyValue("ZoomValue", new Short("15"));
151                         //and back to 10%
152                         PropSet.setPropertyValue("ZoomValue", new Short("10"));
153                     } catch ( com.sun.star.lang.WrappedTargetException e ) {
154 
155                     }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
156 
157                     } catch ( com.sun.star.beans.PropertyVetoException e ) {
158 
159                     } catch ( com.sun.star.beans.UnknownPropertyException e ) {
160 
161                     }
162                 }
163             });
164 
165         return tEnv;
166 
167     }
168 
169     /**
170     * Called while disposing a <code>TestEnvironment</code>.
171     * Disposes text document.
172     * @param tParam test parameters
173     * @param tEnv the environment to cleanup
174     * @param log writer to log information while testing
175     */
176     protected void cleanup( TestParameters Param, PrintWriter log) {
177         log.println("dispose text document");
178         util.DesktopTools.closeDoc(xTextDoc);
179     }
180 
181     /**
182      * Called while the <code>TestCase</code> initialization. In the
183      * implementation does nothing. Subclasses can override to initialize
184      * objects shared among all <code>TestEnvironment</code>s.
185      *
186      * @param tParam test parameters
187      * @param log writer to log information while testing
188      *
189      * @see #initializeTestCase()
190      */
191     protected void initialize(TestParameters Param, PrintWriter log) {
192         log.println( "creating a text document" );
193         xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());
194     }
195 }
196