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.SOfficeFactory;
37 import util.WriterTools;
38 import util.utils;
39 
40 import com.sun.star.accessibility.AccessibleRole;
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.beans.XPropertySet;
44 import com.sun.star.frame.XController;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.text.XTextTable;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.view.XViewSettingsSupplier;
52 
53 /**
54 * Test of accessible object for the table of a text document.<p>
55 * Object implements the following interfaces :
56 * <ul>
57 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
58 * </ul>
59 * @see com.sun.star.accessibility.XAccessible
60 */
61 public class SwAccessibleTableView extends TestCase {
62 
63     XTextDocument xTextDoc = null;
64 
65     /**
66     * Called to create an instance of <code>TestEnvironment</code>
67     * with an object to test and related objects.
68     * Creates a text table and inserts it into the document.
69     * Then obtains accessible object for the table.
70     *
71     * @param tParam test parameters
72     * @param log writer to log information while testing
73     *
74     * @see TestEnvironment
75     * @see #getTestEnvironment()
76     */
77     protected TestEnvironment createTestEnvironment(
78         TestParameters Param, PrintWriter log) {
79 
80         XInterface oObj = null;
81         XTextTable oTable = null;
82 
83         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)Param.getMSF());
84         try {
85             oTable = SOF.createTextTable( xTextDoc );
86         } catch ( com.sun.star.uno.Exception e ) {
87             e.printStackTrace( log );
88             throw new StatusException("Couldn't create TextTable : " +
89                 e.getMessage(), e);
90         }
91 
92         try {
93             SOF.insertTextContent(xTextDoc, oTable );
94         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
95             e.printStackTrace( log );
96             throw new StatusException("Couldn't insert text content :"
97                 + e.getMessage(), e);
98         }
99 
100         XModel aModel = (XModel)
101             UnoRuntime.queryInterface(XModel.class, xTextDoc);
102 
103         AccessibilityTools at = new AccessibilityTools();
104 
105         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
106         XAccessible xRoot = at.getAccessibleObject(xWindow);
107 
108         at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
109 
110         oObj = at.SearchedContext;
111 
112         log.println("ImplementationName " + utils.getImplName(oObj));
113         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
114 
115         TestEnvironment tEnv = new TestEnvironment(oObj);
116 
117         XController xController = xTextDoc.getCurrentController();
118         XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
119                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
120                 xController);
121 
122         final XPropertySet PropSet = xViewSetSup.getViewSettings();
123 
124         tEnv.addObjRelation("EventProducer",
125             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
126                 public void fireEvent() {
127                     try {
128                         //change zoom value to 15%
129                         PropSet.setPropertyValue("ZoomValue", new Short("15"));
130                         //and back to 100%
131                         PropSet.setPropertyValue("ZoomValue", new Short("100"));
132                     } catch ( com.sun.star.lang.WrappedTargetException e ) {
133 
134                     }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
135 
136                     } catch ( com.sun.star.beans.PropertyVetoException e ) {
137 
138                     } catch ( com.sun.star.beans.UnknownPropertyException e ) {
139 
140                     }
141                 }
142             });
143 
144         return tEnv;
145 
146     }
147 
148     /**
149     * Called while disposing a <code>TestEnvironment</code>.
150     * Disposes text document.
151     * @param tParam test parameters
152     * @param tEnv the environment to cleanup
153     * @param log writer to log information while testing
154     */
155     protected void cleanup( TestParameters Param, PrintWriter log) {
156         log.println("dispose text document");
157         util.DesktopTools.closeDoc(xTextDoc);
158     }
159 
160     /**
161      * Called while the <code>TestCase</code> initialization.
162      * Creates a text document.
163      *
164      * @param tParam test parameters
165      * @param log writer to log information while testing
166      *
167      * @see #initializeTestCase()
168      */
169     protected void initialize(TestParameters Param, PrintWriter log) {
170         log.println( "creating a text document" );
171         xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());
172     }
173 }
174 
175