xref: /AOO41X/main/qadevOOo/tests/java/mod/_svtools/AccessibleBrowseBoxHeaderCell.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package mod._svtools;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier;
31*cdf0e10cSrcweir import java.io.PrintWriter;
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir import lib.StatusException;
34*cdf0e10cSrcweir import lib.TestCase;
35*cdf0e10cSrcweir import lib.TestEnvironment;
36*cdf0e10cSrcweir import lib.TestParameters;
37*cdf0e10cSrcweir import util.AccessibilityTools;
38*cdf0e10cSrcweir import util.DesktopTools;
39*cdf0e10cSrcweir import util.SOfficeFactory;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole;
42*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
43*cdf0e10cSrcweir import com.sun.star.awt.XWindow;
44*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
45*cdf0e10cSrcweir import com.sun.star.frame.XController;
46*cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
47*cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
48*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
49*cdf0e10cSrcweir import com.sun.star.frame.XFrame;
50*cdf0e10cSrcweir import com.sun.star.frame.XModel;
51*cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
52*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
53*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
54*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
55*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
56*cdf0e10cSrcweir import com.sun.star.util.URL;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir /**
59*cdf0e10cSrcweir  * Test for object that implements the following interfaces :
60*cdf0e10cSrcweir  * <ul>
61*cdf0e10cSrcweir  *  <li>
62*cdf0e10cSrcweir  *      <code>::com::sun::star::accessibility::XAccessibleContext
63*cdf0e10cSrcweir  *  </code></li>
64*cdf0e10cSrcweir  *  <li>
65*cdf0e10cSrcweir  *      <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
66*cdf0e10cSrcweir  *  </code></li>
67*cdf0e10cSrcweir  * </ul> <p>
68*cdf0e10cSrcweir  *
69*cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
70*cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleContext
71*cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleEventBroadcaster
72*cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleContext
73*cdf0e10cSrcweir  */
74*cdf0e10cSrcweir public class AccessibleBrowseBoxHeaderCell extends TestCase {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     static XDesktop the_Desk;
77*cdf0e10cSrcweir     static XTextDocument xTextDoc;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     /**
80*cdf0e10cSrcweir      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
81*cdf0e10cSrcweir      */
82*cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
83*cdf0e10cSrcweir         the_Desk = (XDesktop) UnoRuntime.queryInterface(
84*cdf0e10cSrcweir                     XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     /**
88*cdf0e10cSrcweir      * Disposes the document, if exists, created in
89*cdf0e10cSrcweir      * <code>createTestEnvironment</code> method.
90*cdf0e10cSrcweir      */
91*cdf0e10cSrcweir     protected void cleanup( TestParameters Param, PrintWriter log) {
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         log.println("disposing xTextDoc");
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         if (xTextDoc != null) {
96*cdf0e10cSrcweir             xTextDoc.dispose();
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     /**
101*cdf0e10cSrcweir      * Creates a text document. Opens the DataSource browser and loads
102*cdf0e10cSrcweir      * the table. Creates an instance of the service
103*cdf0e10cSrcweir      * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
104*cdf0e10cSrcweir      * Then obtains an accessible object with the role
105*cdf0e10cSrcweir      * <code>AccessibleRole.UNKNOWN</code> and with the name
106*cdf0e10cSrcweir      * <code>"Identifier"</code>.
107*cdf0e10cSrcweir      * Object relations created :
108*cdf0e10cSrcweir      * <ul>
109*cdf0e10cSrcweir      *  <li> <code>'EventProducer'</code> for
110*cdf0e10cSrcweir      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
111*cdf0e10cSrcweir      *      method <code>fireEvent()</code> is empty because object is transient
112*cdf0e10cSrcweir      *   </li>
113*cdf0e10cSrcweir      * </ul>
114*cdf0e10cSrcweir      *
115*cdf0e10cSrcweir      * @param tParam test parameters
116*cdf0e10cSrcweir      * @param log writer to log information while testing
117*cdf0e10cSrcweir      *
118*cdf0e10cSrcweir      * @see com.sun.star.awt.Toolkit
119*cdf0e10cSrcweir      * @see com.sun.star.accessibility.AccessibleRole
120*cdf0e10cSrcweir      * @see ifc.accessibility._XAccessibleEventBroadcaster
121*cdf0e10cSrcweir      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
122*cdf0e10cSrcweir      */
123*cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(
124*cdf0e10cSrcweir         TestParameters tParam, PrintWriter log) {
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         log.println( "creating a test environment" );
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         if (xTextDoc != null) xTextDoc.dispose();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         // get a soffice factory object
131*cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         try {
134*cdf0e10cSrcweir             log.println( "creating a text document" );
135*cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
136*cdf0e10cSrcweir         } catch ( com.sun.star.uno.Exception e ) {
137*cdf0e10cSrcweir             // Some exception occures.FAILED
138*cdf0e10cSrcweir             e.printStackTrace( log );
139*cdf0e10cSrcweir             throw new StatusException( "Couldn't create document", e );
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         shortWait();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         XModel aModel1 = (XModel)
145*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XModel.class, xTextDoc);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         XController secondController = aModel1.getCurrentController();
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.
150*cdf0e10cSrcweir             queryInterface(XDispatchProvider.class, secondController);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         XDispatch getting = null;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         log.println( "opening DatasourceBrowser" );
155*cdf0e10cSrcweir         URL the_url = new URL();
156*cdf0e10cSrcweir         the_url.Complete = ".component:DB/DataSourceBrowser";
157*cdf0e10cSrcweir         getting = aProv.queryDispatch(the_url, "_beamer", 12);
158*cdf0e10cSrcweir         PropertyValue[] noArgs = new PropertyValue[0];
159*cdf0e10cSrcweir         getting.dispatch(the_url, noArgs);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         shortWait();
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir         XFrame the_frame1 = the_Desk.getCurrentFrame();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         if (the_frame1 == null) {
166*cdf0e10cSrcweir             log.println("Current frame was not found !!!");
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         the_frame2.setName("DatasourceBrowser");
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         XInterface oObj = null;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         final XInitialization xInit = (XInitialization)
176*cdf0e10cSrcweir                 UnoRuntime.queryInterface(
177*cdf0e10cSrcweir                         XInitialization.class, the_frame2.getController());
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         PropertyValue[] params = new PropertyValue[3];
180*cdf0e10cSrcweir         PropertyValue param1 = new PropertyValue();
181*cdf0e10cSrcweir         param1.Name = "DataSourceName";
182*cdf0e10cSrcweir         param1.Value = "Bibliography";
183*cdf0e10cSrcweir         params[0] = param1;
184*cdf0e10cSrcweir         PropertyValue param2 = new PropertyValue();
185*cdf0e10cSrcweir         param2.Name = "CommandType";
186*cdf0e10cSrcweir         param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
187*cdf0e10cSrcweir         params[1] = param2;
188*cdf0e10cSrcweir         PropertyValue param3 = new PropertyValue();
189*cdf0e10cSrcweir         param3.Name = "Command";
190*cdf0e10cSrcweir         param3.Value = "biblio";
191*cdf0e10cSrcweir         params[2] = param3;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         XController xCont = the_frame2.getController();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
196*cdf0e10cSrcweir             XSelectionSupplier.class, xCont);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir         try {
199*cdf0e10cSrcweir             xSelect.select(params);
200*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException ex) {
201*cdf0e10cSrcweir             throw new StatusException("Could not select Biblio-Database", ex);
202*cdf0e10cSrcweir         }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir         XWindow xWindow = secondController.getFrame().getContainerWindow();
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         oObj = at.getAccessibleObjectForRole(xRoot,
213*cdf0e10cSrcweir             AccessibleRole.ROW_HEADER);
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         log.println("ImplementationName: "+ util.utils.getImplName(oObj));
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir         tEnv.addObjRelation("EventProducer",
220*cdf0e10cSrcweir             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
221*cdf0e10cSrcweir                 public void fireEvent() {
222*cdf0e10cSrcweir                 }
223*cdf0e10cSrcweir             });
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         return tEnv;
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     /**
229*cdf0e10cSrcweir     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
230*cdf0e10cSrcweir     * reset</code> call.
231*cdf0e10cSrcweir     */
232*cdf0e10cSrcweir     private void shortWait() {
233*cdf0e10cSrcweir         try {
234*cdf0e10cSrcweir             Thread.sleep(5000); ;
235*cdf0e10cSrcweir         } catch (InterruptedException e) {
236*cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
237*cdf0e10cSrcweir         }
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir }
241