bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleDocumentPageView.java
blobe9c097711f9ee59c74f06bfd096969926eba3d86
1 /*
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 .
18 package mod._sw;
20 import java.io.PrintWriter;
22 import lib.Status;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.WriterTools;
29 import util.utils;
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.lang.XMultiServiceFactory;
39 import com.sun.star.text.ControlCharacter;
40 import com.sun.star.text.XText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.util.URL;
46 import com.sun.star.util.XURLTransformer;
48 public class SwAccessibleDocumentPageView extends TestCase {
50 XTextDocument xTextDoc = null;
52 /**
53 * Called to create an instance of <code>TestEnvironment</code>
54 * with an object to test and related objects.
55 * Switchs the document to Print Preview mode.
56 * Obtains accissible object for the document page view.
58 * @param Param test parameters
59 * @param log writer to log information while testing
61 * @see TestEnvironment
62 * @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" );
73 try {
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",
78 false);
79 oText.insertControlCharacter(
80 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
81 oText.insertString( oCursor,
82 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwAccessibleDocumentPageView",
83 false);
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
99 try {
100 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
101 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
102 ( (XMultiServiceFactory) 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 log.println("Couldn't change mode");
114 throw new StatusException(Status.failed("Couldn't change mode"));
117 shortWait();
119 AccessibilityTools at = new AccessibilityTools();
121 XWindow xWindow = AccessibilityTools.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
122 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
124 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT );
126 log.println("ImplementationName " + utils.getImplName(oObj));
128 TestEnvironment tEnv = new TestEnvironment(oObj);
130 final XText the_text = oText;
132 tEnv.addObjRelation("EventProducer",
133 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
134 public void fireEvent() {
135 String oldText = the_text.getString();
136 the_text.setString("EVENT FIRED");
137 shortWait();
138 the_text.setString(oldText);
142 return tEnv;
148 * Sleeps for 1 sec. to allow StarOffice to react on <code>
149 * reset</code> call.
151 private void shortWait() {
152 try {
153 Thread.sleep(2000) ;
154 } catch (InterruptedException e) {
155 log.println("While waiting :" + e) ;
161 * Called while disposing a <code>TestEnvironment</code>.
162 * Disposes text document.
163 * @param Param test parameters
164 * @param log writer to log information while testing
166 protected void cleanup( TestParameters Param, PrintWriter log) {
167 log.println("dispose text document");
168 util.DesktopTools.closeDoc(xTextDoc);
172 * Called while the <code>TestCase</code> initialization. In the
173 * implementation does nothing. Subclasses can override to initialize
174 * objects shared among all <code>TestEnvironment</code>s.
176 * @param Param test parameters
177 * @param log writer to log information while testing
179 * @see #initializeTestCase
181 protected void initialize(TestParameters Param, PrintWriter log) {
182 log.println( "creating a text document" );
183 xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF());