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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.WriterTools
;
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
.frame
.XController
;
35 import com
.sun
.star
.frame
.XDispatch
;
36 import com
.sun
.star
.frame
.XDispatchProvider
;
37 import com
.sun
.star
.frame
.XModel
;
38 import com
.sun
.star
.text
.ControlCharacter
;
39 import com
.sun
.star
.text
.XText
;
40 import com
.sun
.star
.text
.XTextCursor
;
41 import com
.sun
.star
.text
.XTextDocument
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
44 import com
.sun
.star
.util
.URL
;
45 import com
.sun
.star
.util
.XURLTransformer
;
47 public class SwAccessibleDocumentPageView
extends TestCase
{
49 XTextDocument xTextDoc
= null;
52 * Called to create an instance of <code>TestEnvironment</code>
53 * with an object to test and related objects.
54 * Switchs the document to Print Preview mode.
55 * Obtains accissible object for the document page view.
57 * @param Param test parameters
58 * @param log writer to log information while testing
60 * @see TestEnvironment
61 * @see #getTestEnvironment
64 protected TestEnvironment
createTestEnvironment(
65 TestParameters Param
, PrintWriter log
) {
67 XInterface oObj
= null;
69 XText oText
= xTextDoc
.getText();
70 XTextCursor oCursor
= oText
.createTextCursor();
72 log
.println( "inserting some lines" );
74 for (int i
=0; i
<25; i
++){
75 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
76 oText
.insertString( oCursor
,
77 " The quick brown fox jumps over the lazy Dog: SwAccessibleDocumentPageView",
79 oText
.insertControlCharacter(
80 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
81 oText
.insertString( oCursor
,
82 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwAccessibleDocumentPageView",
84 oText
.insertControlCharacter(oCursor
,
85 ControlCharacter
.PARAGRAPH_BREAK
, false );
86 oText
.insertControlCharacter(
87 oCursor
, ControlCharacter
.LINE_BREAK
, false );
89 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
90 e
.printStackTrace(log
);
91 throw new StatusException( "Couldn't insert lines", e
);
94 XController xController
= xTextDoc
.getCurrentController();
96 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
98 //switch to 'Print Preview' mode
100 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
101 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
102 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
103 // Because it's an in/out parameter we must use an array of URL objects.
104 URL
[] aParseURL
= new URL
[1];
105 aParseURL
[0] = new URL();
106 aParseURL
[0].Complete
= ".uno:PrintPreview";
107 xParser
.parseStrict(aParseURL
);
108 URL aURL
= aParseURL
[0];
109 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
110 if(xDispatcher
!= null)
111 xDispatcher
.dispatch( aURL
, null );
112 } catch (com
.sun
.star
.uno
.Exception e
) {
113 throw new StatusException(e
, Status
.failed("Couldn't change mode"));
116 util
.utils
.pause(2000);
118 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
119 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
121 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.DOCUMENT
);
123 log
.println("ImplementationName " + utils
.getImplName(oObj
));
125 TestEnvironment tEnv
= new TestEnvironment(oObj
);
127 final XText the_text
= oText
;
129 tEnv
.addObjRelation("EventProducer",
130 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
131 public void fireEvent() {
132 String oldText
= the_text
.getString();
133 the_text
.setString("EVENT FIRED");
134 util
.utils
.pause(2000);
135 the_text
.setString(oldText
);
145 * Called while disposing a <code>TestEnvironment</code>.
146 * Disposes text document.
147 * @param Param test parameters
148 * @param log writer to log information while testing
151 protected void cleanup( TestParameters Param
, PrintWriter log
) {
152 log
.println("dispose text document");
153 util
.DesktopTools
.closeDoc(xTextDoc
);
157 * Called while the <code>TestCase</code> initialization. In the
158 * implementation does nothing. Subclasses can override to initialize
159 * objects shared among all <code>TestEnvironment</code>s.
161 * @param Param test parameters
162 * @param log writer to log information while testing
164 * @see #initializeTestCase
167 protected void initialize(TestParameters Param
, PrintWriter log
) {
168 log
.println( "creating a text document" );
169 xTextDoc
= WriterTools
.createTextDoc( Param
.getMSF());