xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScAccessibleDocument.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.SOfficeFactory;
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.Rectangle;
43 import com.sun.star.awt.XWindow;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XComponent;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 
51 /**
52  * Test for object which is represented by accessible component of
53  * a spreadsheet document.
54  *
55  * Object implements the following interfaces :
56  * <ul>
57  *  <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
58  *  <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
59  *  <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
60  *  <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
61  * </ul> <p>
62  *
63  * @see com.sun.star.accessibility.XAccessibleComponent
64  * @see com.sun.star.accessibility.XAccessibleContext
65  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66  * @see com.sun.star.accessibility.XAccessibleSelection
67  * @see ifc.accessibility._XAccessibleComponent
68  * @see ifc.accessibility.XAccessibleEventBroadcaster
69  * @see ifc.accessibility.XAccessibleSelection
70  * @see ifc.accessibility._XAccessibleContext
71  */
72 public class ScAccessibleDocument extends TestCase {
73 
74     static XComponent xSpreadsheetDoc = null;
75 
76     /**
77     * Called to create an instance of <code>TestEnvironment</code>
78     * with an object to test and related objects.
79     * Obtains accissible object for the spreadsheet document.
80     *
81     * @param tParam test parameters
82     * @param log writer to log information while testing
83     *
84     * @see TestEnvironment
85     * @see #getTestEnvironment()
86     */
87     protected TestEnvironment createTestEnvironment(
88         TestParameters Param, PrintWriter log) {
89 
90         XInterface oObj = null;
91 
92         // get the drawpage of drawing here
93         log.println( "getting Drawpages" );
94 
95         XModel aModel = (XModel)
96             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
97 
98         AccessibilityTools at = new AccessibilityTools();
99 
100         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
101         XAccessible xRoot = at.getAccessibleObject(xWindow);
102 
103         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT, "");
104         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
105         log.println("ImplementationName " + utils.getImplName(oObj));
106 
107         TestEnvironment tEnv = new TestEnvironment(oObj);
108 
109         final XWindow xDocWin = xWindow;
110         tEnv.addObjRelation("EventProducer",
111             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
112                 public void fireEvent() {
113                     Rectangle rect = xDocWin.getPosSize();
114                     xDocWin.setPosSize(rect.X,rect.Y,rect.Height,rect.Width-10,com.sun.star.awt.PosSize.POSSIZE);
115                 }
116             });
117 
118         return tEnv;
119 
120     }
121 
122     /**
123     * Called while disposing a <code>TestEnvironment</code>.
124     * Disposes calc document.
125     * @param tParam test parameters
126     * @param tEnv the environment to cleanup
127     * @param log writer to log information while testing
128     */
129     protected void cleanup( TestParameters Param, PrintWriter log) {
130         log.println( "    disposing xSheetDoc " );
131         util.DesktopTools.closeDoc(xSpreadsheetDoc);
132     }
133 
134     /**
135      * Called while the <code>TestCase</code> initialization. In the
136      * implementation does nothing. Subclasses can override to initialize
137      * objects shared among all <code>TestEnvironment</code>s.
138      *
139      * @param tParam test parameters
140      * @param log writer to log information while testing
141      *
142      * @see #initializeTestCase()
143      */
144     protected void initialize(TestParameters Param, PrintWriter log) {
145         // get a soffice factory object
146         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
147 
148         try {
149             log.println("creating a spreadsheetdocument");
150             String url = utils.getFullTestURL("calcshapes.sxc");
151             log.println("loading document "+url);
152             xSpreadsheetDoc = SOF.loadDocument(url);
153             shortWait();
154         } catch (com.sun.star.uno.Exception e) {
155             e.printStackTrace( log );
156             throw new StatusException( "Couldn't create document ", e );
157         }
158     }
159 
160     /**
161     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
162     * reset</code> call.
163     */
164     private void shortWait() {
165         try {
166             Thread.sleep(500) ;
167         } catch (InterruptedException e) {
168             log.println("While waiting :" + e) ;
169         }
170     }
171 
172 }
173