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
.XText
;
38 import com
.sun
.star
.text
.XTextContent
;
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 SwAccessibleEndnoteView
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 endnote 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 endnote.
56 * @param Param test parameters
57 * @param log writer to log information while testing
59 * @see TestEnvironment
60 * @see #getTestEnvironment
63 protected TestEnvironment
createTestEnvironment(
64 TestParameters Param
, PrintWriter log
) {
66 XInterface oObj
= null;
67 XInterface oEndnote
= null;
69 log
.println( "Creating a test environment" );
70 XMultiServiceFactory msf
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
71 log
.println("creating a endnote");
73 oEndnote
= UnoRuntime
.queryInterface(XInterface
.class,
74 msf
.createInstance("com.sun.star.text.Endnote"));
75 } catch (com
.sun
.star
.uno
.Exception e
) {
76 e
.printStackTrace(log
);
77 throw new StatusException("Couldn't create endnote", e
);
80 XText oText
= xTextDoc
.getText();
81 XTextCursor oCursor
= oText
.createTextCursor();
83 log
.println("inserting the footnote into text document");
84 XTextContent xTC
= UnoRuntime
.queryInterface(XTextContent
.class, oEndnote
);
86 oText
.insertTextContent(oCursor
, xTC
, false);
87 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
88 e
.printStackTrace(log
);
89 throw new StatusException("Couldn't insert the endnote", 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", Short
.valueOf("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 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
118 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
120 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.END_NOTE
);
122 log
.println("ImplementationName " + utils
.getImplName(oObj
));
123 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
125 TestEnvironment tEnv
= new TestEnvironment(oObj
);
127 final XPropertySet PropSet
= xViewSetSup
.getViewSettings();
129 tEnv
.addObjRelation("EventProducer",
130 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
131 public void fireEvent() {
133 //change zoom value to 130%
134 PropSet
.setPropertyValue("ZoomValue", Short
.valueOf("15"));
136 PropSet
.setPropertyValue("ZoomValue", Short
.valueOf("10"));
137 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
139 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
141 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
143 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
154 * Called while disposing a <code>TestEnvironment</code>.
155 * Disposes text document.
156 * @param Param test parameters
157 * @param log writer to log information while testing
160 protected void cleanup( TestParameters Param
, PrintWriter log
) {
161 log
.println("dispose text document");
162 util
.DesktopTools
.closeDoc(xTextDoc
);
166 * Called while the <code>TestCase</code> initialization. In the
167 * implementation does nothing. Subclasses can override to initialize
168 * objects shared among all <code>TestEnvironment</code>s.
170 * @param Param test parameters
171 * @param log writer to log information while testing
173 * @see #initializeTestCase
176 protected void initialize(TestParameters Param
, PrintWriter log
) {
177 log
.println( "creating a text document" );
178 xTextDoc
= WriterTools
.createTextDoc(Param
.getMSF());