Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / AccessibleSlideView.java
blobccdd916cf13c9769cca3a9150cf38533e93392b5
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.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.util.URL;
43 import com.sun.star.util.XURLTransformer;
45 public class AccessibleSlideView extends TestCase {
47 XModel aModel = null;
48 XComponent xImpressDoc = null;
50 /**
51 * Called to create an instance of <code>TestEnvironment</code> with an
52 * object to test and related objects. Subclasses should implement this
53 * method to provide the implementation and related objects. The method is
54 * called from <code>getTestEnvironment()</code>.
56 * @param Param test parameters
57 * @param log writer to log information while testing
59 * @see TestEnvironment
60 * @see #getTestEnvironment
62 @Override
63 protected TestEnvironment createTestEnvironment
64 (TestParameters Param, PrintWriter log) {
65 XInterface oObj = null;
67 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
68 XDrawPages oDPn = oDPS.getDrawPages();
70 oDPn.insertNewByIndex(0);
72 util.utils.pause(2000);
74 XWindow xWindow = AccessibilityTools.getCurrentWindow (
75 aModel);
76 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
78 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
80 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
82 System.out.println("ImplementationName "+utils.getImplName(oObj));
84 TestEnvironment tEnv = new TestEnvironment(oObj);
86 //util.dbg.printInterfaces(oObj);
87 log.println("Implementationname: "+util.utils.getImplName(oObj));
89 final XDrawPages DrawPages = oDPn;
91 tEnv.addObjRelation("EventProducer",
92 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
93 public void fireEvent() {
94 DrawPages.insertNewByIndex(2);
96 });
98 return tEnv;
103 * Called while disposing a <code>TestEnvironment</code>.
104 * Disposes Impress documents.
105 * @param Param test parameters
106 * @param log writer to log information while testing
108 @Override
109 protected void cleanup( TestParameters Param, PrintWriter log ) {
110 log.println("disposing impress document");
111 util.DesktopTools.closeDoc(xImpressDoc);
115 * Called while the <code>TestCase</code> initialization. In the
116 * implementation does nothing. Subclasses can override to initialize
117 * objects shared among all <code>TestEnvironment</code>s.
119 * @param Param test parameters
120 * @param log writer to log information while testing
122 * @see #initializeTestCase
124 @Override
125 protected void initialize(TestParameters Param, PrintWriter log) {
126 // get a soffice factory object
127 SOfficeFactory SOF = SOfficeFactory.getFactory(
128 Param.getMSF());
130 try {
131 log.println( "creating a impress document" );
132 xImpressDoc = SOF.createImpressDoc(null);
133 } catch (com.sun.star.uno.Exception e) {
134 e.printStackTrace( log );
135 throw new StatusException("Couldn't create document", e);
138 util.utils.pause(2000);
140 aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
142 //Change to Outline view
143 try {
144 String aSlotID = "slot:27011";
145 XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class,
146 aModel.getCurrentController() );
147 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
148 Param.getMSF().
149 createInstance("com.sun.star.util.URLTransformer"));
150 // Because it's an in/out parameter we must use an array of URL objects.
151 URL[] aParseURL = new URL[1];
152 aParseURL[0] = new URL();
153 aParseURL[0].Complete = aSlotID;
154 xParser.parseStrict(aParseURL);
155 URL aURL = aParseURL[0];
156 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
157 if( xDispatcher != null )
158 xDispatcher.dispatch( aURL, null );
159 } catch (com.sun.star.uno.Exception e) {
160 log.println("Couldn't change mode");
163 util.utils.pause(2000);