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
.TestEnvironment
;
24 import lib
.TestParameters
;
25 import util
.AccessibilityTools
;
26 import util
.WriterTools
;
29 import com
.sun
.star
.accessibility
.AccessibleRole
;
30 import com
.sun
.star
.accessibility
.XAccessible
;
31 import com
.sun
.star
.awt
.XWindow
;
32 import com
.sun
.star
.frame
.XController
;
33 import com
.sun
.star
.frame
.XDispatch
;
34 import com
.sun
.star
.frame
.XDispatchProvider
;
35 import com
.sun
.star
.frame
.XModel
;
36 import com
.sun
.star
.text
.ControlCharacter
;
37 import com
.sun
.star
.text
.XText
;
38 import com
.sun
.star
.text
.XTextCursor
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.util
.URL
;
43 import com
.sun
.star
.util
.XURLTransformer
;
45 public class SwAccessibleDocumentPageView
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 * Switch the document to Print Preview mode.
53 * Obtains accessible object for the document page view.
55 * @param Param test parameters
56 * @param log writer to log information while testing
58 * @see TestEnvironment
59 * @see #getTestEnvironment
62 protected TestEnvironment
createTestEnvironment(
63 final TestParameters Param
, PrintWriter log
) throws Exception
{
65 XInterface oObj
= null;
67 XText oText
= xTextDoc
.getText();
68 XTextCursor oCursor
= oText
.createTextCursor();
70 log
.println( "inserting some lines" );
71 for (int i
=0; i
<25; i
++){
72 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
73 oText
.insertString( oCursor
,
74 " The quick brown fox jumps over the lazy Dog: SwAccessibleDocumentPageView",
76 oText
.insertControlCharacter(
77 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
78 oText
.insertString( oCursor
,
79 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwAccessibleDocumentPageView",
81 oText
.insertControlCharacter(oCursor
,
82 ControlCharacter
.PARAGRAPH_BREAK
, false );
83 oText
.insertControlCharacter(
84 oCursor
, ControlCharacter
.LINE_BREAK
, false );
87 XController xController
= xTextDoc
.getCurrentController();
89 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
91 //switch to 'Print Preview' mode
92 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
93 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
94 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
95 // Because it's an in/out parameter we must use an array of URL objects.
96 URL
[] aParseURL
= new URL
[1];
97 aParseURL
[0] = new URL();
98 aParseURL
[0].Complete
= ".uno:PrintPreview";
99 xParser
.parseStrict(aParseURL
);
100 URL aURL
= aParseURL
[0];
101 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
102 if(xDispatcher
!= null)
103 xDispatcher
.dispatch( aURL
, null );
105 util
.utils
.waitForEventIdle(Param
.getMSF());
107 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
108 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
110 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.DOCUMENT
);
112 log
.println("ImplementationName " + utils
.getImplName(oObj
));
114 TestEnvironment tEnv
= new TestEnvironment(oObj
);
116 final XText the_text
= oText
;
118 tEnv
.addObjRelation("EventProducer",
119 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
120 public void fireEvent() {
121 String oldText
= the_text
.getString();
122 the_text
.setString("EVENT FIRED");
123 util
.utils
.waitForEventIdle(Param
.getMSF());
124 the_text
.setString(oldText
);
134 * Called while disposing a <code>TestEnvironment</code>.
135 * Disposes text document.
136 * @param Param test parameters
137 * @param log writer to log information while testing
140 protected void cleanup( TestParameters Param
, PrintWriter log
) {
141 log
.println("dispose text document");
142 util
.DesktopTools
.closeDoc(xTextDoc
);
146 * Called while the <code>TestCase</code> initialization. In the
147 * implementation does nothing. Subclasses can override to initialize
148 * objects shared among all <code>TestEnvironment</code>s.
150 * @param Param test parameters
151 * @param log writer to log information while testing
153 * @see #initializeTestCase
156 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
157 log
.println( "creating a text document" );
158 xTextDoc
= WriterTools
.createTextDoc( Param
.getMSF());