bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / AccessibleOutlineView.java
blob7738e0c02de88b5a45164cb1852b391716903da3
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sd;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.drawing.XDrawPages;
35 import com.sun.star.drawing.XDrawPagesSupplier;
36 import com.sun.star.frame.XDispatch;
37 import com.sun.star.frame.XDispatchProvider;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.URL;
44 import com.sun.star.util.XURLTransformer;
46 public class AccessibleOutlineView extends TestCase {
48 XModel aModel = null;
49 XComponent xImpressDoc = null;
51 /**
52 * Called to create an instance of <code>TestEnvironment</code> with an
53 * object to test and related objects. Subclasses should implement this
54 * method to provide the implementation and related objects. The method is
55 * called from <code>getTestEnvironment()</code>.
57 * @param Param test parameters
58 * @param log writer to log information while testing
60 * @see TestEnvironment
61 * @see #getTestEnvironment
63 protected TestEnvironment createTestEnvironment
64 (TestParameters Param, PrintWriter log) {
65 XInterface oObj = null;
67 AccessibilityTools at = new AccessibilityTools();
69 XWindow xWindow = AccessibilityTools.getCurrentWindow (
70 (XMultiServiceFactory)Param.getMSF(),aModel);
71 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
73 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
75 log.println("ImplementationName "+utils.getImplName(oObj));
77 TestEnvironment tEnv = new TestEnvironment(oObj);
79 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
80 final XDrawPages oDPn = oDPS.getDrawPages();
82 tEnv.addObjRelation("EventMsg","Inserting a drawpage via API has no "+
83 "effect to the outline view #101050# \r\n"+
84 "Therefore the listener isn't called");
86 tEnv.addObjRelation("EventProducer",
87 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
88 public void fireEvent() {
89 oDPn.insertNewByIndex(1);
91 });
93 return tEnv;
97 /**
98 * Called while disposing a <code>TestEnvironment</code>.
99 * Disposes Impress documents.
100 * @param Param test parameters
101 * @param log writer to log information while testing
103 protected void cleanup( TestParameters Param, PrintWriter log ) {
104 log.println("disposing Impress document");
105 util.DesktopTools.closeDoc(xImpressDoc);
109 * Called while the <code>TestCase</code> initialization. In the
110 * implementation does nothing. Subclasses can override to initialize
111 * objects shared among all <code>TestEnvironment</code>s.
113 * @param Param test parameters
114 * @param log writer to log information while testing
116 * @see #initializeTestCase
118 protected void initialize(TestParameters Param, PrintWriter log) {
119 // get a soffice factory object
120 SOfficeFactory SOF = SOfficeFactory.getFactory(
121 (XMultiServiceFactory)Param.getMSF());
123 try {
124 log.println( "creating a impress document" );
125 xImpressDoc = SOF.createImpressDoc(null);
126 shortWait();
127 } catch (com.sun.star.uno.Exception e) {
128 e.printStackTrace( log );
129 throw new StatusException("Couldn't create document", e);
132 aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
134 XInterface oObj = aModel.getCurrentController();
136 //Change to Outline view
137 try {
138 String aSlotID = "slot:27010";
139 XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
140 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
141 ((XMultiServiceFactory)Param.getMSF()).
142 createInstance("com.sun.star.util.URLTransformer"));
143 // Because it's an in/out parameter we must use an array of URL objects.
144 URL[] aParseURL = new URL[1];
145 aParseURL[0] = new URL();
146 aParseURL[0].Complete = aSlotID;
147 xParser.parseStrict(aParseURL);
148 URL aURL = aParseURL[0];
149 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
150 if( xDispatcher != null )
151 xDispatcher.dispatch( aURL, null );
152 } catch (com.sun.star.uno.Exception e) {
153 log.println("Couldn't change mode");
155 shortWait();
158 private void shortWait() {
159 try {
160 Thread.sleep(2000) ;
161 } catch (InterruptedException e) {
162 System.out.println("While waiting :" + e) ;