Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _sd / AccessibleOutlineView.java
blob78bbbe8e1f740e84c67e9419e4f2f727fa339773
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleOutlineView.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sd;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.drawing.XDrawPages;
47 import com.sun.star.drawing.XDrawPagesSupplier;
48 import com.sun.star.frame.XDispatch;
49 import com.sun.star.frame.XDispatchProvider;
50 import com.sun.star.frame.XModel;
51 import com.sun.star.lang.XComponent;
52 import com.sun.star.lang.XMultiServiceFactory;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.util.URL;
56 import com.sun.star.util.XURLTransformer;
58 public class AccessibleOutlineView extends TestCase {
60 XModel aModel = null;
61 XComponent xImpressDoc = null;
63 /**
64 * Called to create an instance of <code>TestEnvironment</code> with an
65 * object to test and related objects. Subclasses should implement this
66 * method to provide the implementation and related objects. The method is
67 * called from <code>getTestEnvironment()</code>.
69 * @param tParam test parameters
70 * @param log writer to log information while testing
72 * @see TestEnvironment
73 * @see #getTestEnvironment()
75 protected TestEnvironment createTestEnvironment
76 (TestParameters Param, PrintWriter log) {
77 XInterface oObj = null;
79 AccessibilityTools at = new AccessibilityTools();
81 XWindow xWindow = at.getCurrentWindow (
82 (XMultiServiceFactory)Param.getMSF(),aModel);
83 XAccessible xRoot = at.getAccessibleObject(xWindow);
85 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
87 oObj = AccessibilityTools.SearchedContext;
89 log.println("ImplementationName "+utils.getImplName(oObj));
91 TestEnvironment tEnv = new TestEnvironment(oObj);
93 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
94 UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
95 final XDrawPages oDPn = oDPS.getDrawPages();
97 tEnv.addObjRelation("EventMsg","Inserting a drawpage via API has no "+
98 "effect to the outline view #101050# \r\n"+
99 "Therefore the listener isn't called");
101 tEnv.addObjRelation("EventProducer",
102 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
103 public void fireEvent() {
104 oDPn.insertNewByIndex(1);
108 return tEnv;
113 * Called while disposing a <code>TestEnvironment</code>.
114 * Disposes Impress documents.
115 * @param tParam test parameters
116 * @param tEnv the environment to cleanup
117 * @param log writer to log information while testing
119 protected void cleanup( TestParameters Param, PrintWriter log ) {
120 log.println("disposing Impress document");
121 util.DesktopTools.closeDoc(xImpressDoc);;
125 * Called while the <code>TestCase</code> initialization. In the
126 * implementation does nothing. Subclasses can override to initialize
127 * objects shared among all <code>TestEnvironment</code>s.
129 * @param tParam test parameters
130 * @param log writer to log information while testing
132 * @see #initializeTestCase()
134 protected void initialize(TestParameters Param, PrintWriter log) {
135 // get a soffice factory object
136 SOfficeFactory SOF = SOfficeFactory.getFactory(
137 (XMultiServiceFactory)Param.getMSF());
139 try {
140 log.println( "creating a impress document" );
141 xImpressDoc = SOF.createImpressDoc(null);
142 shortWait();
143 } catch (com.sun.star.uno.Exception e) {
144 e.printStackTrace( log );
145 throw new StatusException("Couldn't create document", e);
148 aModel = (XModel)
149 UnoRuntime.queryInterface(XModel.class, xImpressDoc);
151 XInterface oObj = aModel.getCurrentController();
153 //Change to Outline view
154 try {
155 String aSlotID = "slot:27010";
156 XDispatchProvider xDispProv = (XDispatchProvider)
157 UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
158 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
159 UnoRuntime.queryInterface(XURLTransformer.class,
160 ((XMultiServiceFactory)Param.getMSF()).
161 createInstance("com.sun.star.util.URLTransformer"));
162 // Because it's an in/out parameter we must use an array of URL objects.
163 URL[] aParseURL = new URL[1];
164 aParseURL[0] = new URL();
165 aParseURL[0].Complete = aSlotID;
166 xParser.parseStrict(aParseURL);
167 URL aURL = aParseURL[0];
168 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
169 if( xDispatcher != null )
170 xDispatcher.dispatch( aURL, null );
171 } catch (com.sun.star.uno.Exception e) {
172 log.println("Couldn't change mode");
174 shortWait();
177 private void shortWait() {
178 try {
179 Thread.sleep(2000) ;
180 } catch (InterruptedException e) {
181 System.out.println("While waiting :" + e) ;