Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / AccessibleDrawDocumentView.java
blob68cc9bec0a0384587f337d8d7b96696a2891f731
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.DrawTools;
29 import util.SOfficeFactory;
30 import util.utils;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.drawing.XDrawPage;
37 import com.sun.star.drawing.XDrawPages;
38 import com.sun.star.drawing.XDrawPagesSupplier;
39 import com.sun.star.drawing.XDrawView;
40 import com.sun.star.drawing.XShape;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.uno.AnyConverter;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 public class AccessibleDrawDocumentView extends TestCase {
50 XComponent xDrawDoc;
52 /**
53 * Called to create an instance of <code>TestEnvironment</code> with an
54 * object to test and related objects. Subclasses should implement this
55 * method to provide the implementation and related objects. The method is
56 * called from <code>getTestEnvironment()</code>.
58 * @param Param test parameters
59 * @param log writer to log information while testing
61 * @see TestEnvironment
62 * @see #getTestEnvironment
64 @Override
65 protected TestEnvironment createTestEnvironment
66 (TestParameters Param, PrintWriter log) {
67 XInterface oObj = null;
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory(
71 Param.getMSF());
73 // get the drawpage of drawing here
74 log.println( "getting Drawpage" );
75 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
76 XDrawPages oDPn = oDPS.getDrawPages();
77 final XDrawPage fDP2 = oDPn.insertNewByIndex(1);
78 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class, oDPn);
79 XDrawPage oDP = null;
80 try {
81 oDP = (XDrawPage) AnyConverter.toObject(
82 new Type(XDrawPage.class),oDPi.getByIndex(0));
83 } catch (com.sun.star.lang.WrappedTargetException e) {
84 e.printStackTrace( log );
85 throw new StatusException("Couldn't get by index", e);
86 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
87 e.printStackTrace( log );
88 throw new StatusException("Couldn't get by index", e);
89 } catch (com.sun.star.lang.IllegalArgumentException e) {
90 e.printStackTrace( log );
91 throw new StatusException("Couldn't get by index", e);
94 //get a Shape
95 log.println( "inserting a Shape" );
96 XShape oShape = SOF.createShape(xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
97 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
99 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
101 XWindow xWindow = AccessibilityTools.getCurrentWindow (
102 aModel);
103 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
105 //com.sun.star.accessibility.AccessibleRole
106 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
108 log.println("ImplementationName "+utils.getImplName(oObj));
110 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
112 TestEnvironment tEnv = new TestEnvironment(oObj);
114 final XDrawView xView = UnoRuntime.queryInterface
115 (XDrawView.class, aModel.getCurrentController()) ;
116 final XDrawPage fDP1 = oDP;
118 tEnv.addObjRelation("EventProducer",
119 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
120 public void fireEvent() {
121 xView.setCurrentPage(fDP2);
122 xView.setCurrentPage(fDP1);
126 return tEnv;
131 * Called while disposing a <code>TestEnvironment</code>.
132 * Disposes Impress documents.
133 * @param Param test parameters
134 * @param log writer to log information while testing
136 @Override
137 protected void cleanup( TestParameters Param, PrintWriter log) {
138 log.println("disposing Draw document");
139 util.DesktopTools.closeDoc(xDrawDoc);
143 * Called while the <code>TestCase</code> initialization. In the
144 * implementation does nothing. Subclasses can override to initialize
145 * objects shared among all <code>TestEnvironment</code>s.
147 * @param Param test parameters
148 * @param log writer to log information while testing
150 * @see #initializeTestCase
152 @Override
153 protected void initialize(TestParameters Param, PrintWriter log) {
154 // get a soffice factory object
155 SOfficeFactory SOF = SOfficeFactory.getFactory(
156 Param.getMSF());
158 try {
159 log.println( "creating a draw document" );
160 xDrawDoc = SOF.createDrawDoc(null);
161 } catch (com.sun.star.uno.Exception e) {
162 // Some exception occurs.FAILED
163 e.printStackTrace( log );
164 throw new StatusException("Couldn't create document", e);