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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.WriterTools
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.awt
.XWindow
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.frame
.XController
;
35 import com
.sun
.star
.frame
.XModel
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.text
.XFootnote
;
38 import com
.sun
.star
.text
.XText
;
39 import com
.sun
.star
.text
.XTextCursor
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
43 import com
.sun
.star
.view
.XViewSettingsSupplier
;
45 public class SwAccessibleFootnoteView
extends TestCase
{
47 XTextDocument xTextDoc
= null;
50 * Called to create an instance of <code>TestEnvironment</code>
51 * with an object to test and related objects.
52 * Inserts the created footnote to the document.
53 * Changes zoom value to 10%(endnote must be in visible area of the document).
54 * Obtains accessible object for the inserted footnote.
56 * @param Param test parameters
57 * @param log writer to log information while testing
59 * @see TestEnvironment
60 * @see #getTestEnvironment
62 protected TestEnvironment
createTestEnvironment(
63 TestParameters Param
, PrintWriter log
) {
65 XInterface oObj
= null;
66 XFootnote oFootnote
= null;
68 log
.println( "Creating a test environment" );
69 // get a soffice factory object
70 XMultiServiceFactory msf
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
71 log
.println("creating a footnote");
74 oFootnote
= UnoRuntime
.queryInterface(XFootnote
.class,
75 msf
.createInstance("com.sun.star.text.Footnote"));
76 } catch (com
.sun
.star
.uno
.Exception e
) {
77 e
.printStackTrace(log
);
78 throw new StatusException("Couldn't create footnote", e
);
81 XText oText
= xTextDoc
.getText();
82 XTextCursor oCursor
= oText
.createTextCursor();
84 log
.println("inserting the footnote into text document");
86 oText
.insertTextContent(oCursor
, oFootnote
, false);
87 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
88 e
.printStackTrace(log
);
89 throw new StatusException("Couldn't insert the footnote", e
);
92 XController xController
= xTextDoc
.getCurrentController();
93 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class,
95 XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
98 //change zoom value to 10%
99 //footer should be in the vissible area of the document
100 xPropSet
.setPropertyValue("ZoomValue", new Short("10"));
101 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
102 e
.printStackTrace(log
);
103 throw new StatusException("Couldn't set propertyValue...", e
);
104 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
105 e
.printStackTrace(log
);
106 throw new StatusException("Couldn't set propertyValue...", e
);
107 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
108 e
.printStackTrace(log
);
109 throw new StatusException("Couldn't set propertyValue...", e
);
110 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
111 e
.printStackTrace(log
);
112 throw new StatusException("Couldn't set propertyValue...", e
);
115 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
117 AccessibilityTools at
= new AccessibilityTools();
119 XWindow xWindow
= AccessibilityTools
.getCurrentWindow((XMultiServiceFactory
)Param
.getMSF(), aModel
);
120 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
122 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.FOOTNOTE
);
124 log
.println("ImplementationName " + utils
.getImplName(oObj
));
125 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
127 TestEnvironment tEnv
= new TestEnvironment(oObj
);
129 final XPropertySet PropSet
= xViewSetSup
.getViewSettings();
131 tEnv
.addObjRelation("EventProducer",
132 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
133 public void fireEvent() {
135 //change zoom value to 130%
136 PropSet
.setPropertyValue("ZoomValue", new Short("15"));
138 PropSet
.setPropertyValue("ZoomValue", new Short("10"));
139 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
141 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
143 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
145 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
156 * Called while disposing a <code>TestEnvironment</code>.
157 * Disposes text document.
158 * @param Param test parameters
159 * @param log writer to log information while testing
161 protected void cleanup( TestParameters Param
, PrintWriter log
) {
162 log
.println("dispose text document");
163 util
.DesktopTools
.closeDoc(xTextDoc
);
167 * Called while the <code>TestCase</code> initialization. In the
168 * implementation does nothing. Subclasses can override to initialize
169 * objects shared among all <code>TestEnvironment</code>s.
171 * @param Param test parameters
172 * @param log writer to log information while testing
174 * @see #initializeTestCase
176 protected void initialize(TestParameters Param
, PrintWriter log
) {
177 log
.println( "creating a text document" );
178 xTextDoc
= WriterTools
.createTextDoc((XMultiServiceFactory
)Param
.getMSF());