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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.DrawTools
;
29 import util
.SOfficeFactory
;
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
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
49 public class AccessibleDrawDocumentView
extends TestCase
{
54 * Called to create an instance of <code>TestEnvironment</code> with an
55 * object to test and related objects. Subclasses should implement this
56 * method to provide the implementation and related objects. The method is
57 * called from <code>getTestEnvironment()</code>.
59 * @param Param test parameters
60 * @param log writer to log information while testing
62 * @see TestEnvironment
63 * @see #getTestEnvironment
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 (XMultiServiceFactory
)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
);
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
);
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 AccessibilityTools at
= new AccessibilityTools();
103 XWindow xWindow
= AccessibilityTools
.getCurrentWindow (
104 (XMultiServiceFactory
)Param
.getMSF(),aModel
);
105 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
107 //com.sun.star.accessibility.AccessibleRole
108 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.DOCUMENT
);
110 log
.println("ImplementationName "+utils
.getImplName(oObj
));
112 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
114 TestEnvironment tEnv
= new TestEnvironment(oObj
);
116 final XDrawView xView
= UnoRuntime
.queryInterface
117 (XDrawView
.class, aModel
.getCurrentController()) ;
118 final XDrawPage fDP1
= oDP
;
120 tEnv
.addObjRelation("EventProducer",
121 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
122 public void fireEvent() {
123 xView
.setCurrentPage(fDP2
);
124 xView
.setCurrentPage(fDP1
);
133 * Called while disposing a <code>TestEnvironment</code>.
134 * Disposes Impress documents.
135 * @param Param test parameters
136 * @param log writer to log information while testing
138 protected void cleanup( TestParameters Param
, PrintWriter log
) {
139 log
.println("disposing Draw document");
140 util
.DesktopTools
.closeDoc(xDrawDoc
);
144 * Called while the <code>TestCase</code> initialization. In the
145 * implementation does nothing. Subclasses can override to initialize
146 * objects shared among all <code>TestEnvironment</code>s.
148 * @param Param test parameters
149 * @param log writer to log information while testing
151 * @see #initializeTestCase
153 protected void initialize(TestParameters Param
, PrintWriter log
) {
154 // get a soffice factory object
155 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
156 (XMultiServiceFactory
)Param
.getMSF());
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
);