1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 package mod._sw; 19 20 import java.io.PrintWriter; 21 22 import lib.TestCase; 23 import lib.TestEnvironment; 24 import lib.TestParameters; 25 import util.AccessibilityTools; 26 import util.WriterTools; 27 import util.utils; 28 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.XModel; 33 import com.sun.star.text.XText; 34 import com.sun.star.text.XTextDocument; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.uno.XInterface; 37 38 /** 39 * Test of accessible object for paragraph of a text document.<p> 40 * Object implements the following interfaces : 41 * <ul> 42 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li> 43 * </ul> 44 * @see com.sun.star.accessibility.XAccessible 45 */ 46 public class SwAccessibleParagraphView extends TestCase { 47 48 XTextDocument xTextDoc = null; 49 50 /** 51 * Called to create an instance of <code>TestEnvironment</code> 52 * with an object to test and related objects. Obtains accessible object 53 * for one of document paragraph. 54 * 55 * @param Param test parameters 56 * @param log writer to log information while testing 57 * 58 * @see TestEnvironment 59 * @see #getTestEnvironment 60 */ 61 @Override createTestEnvironment( TestParameters Param, PrintWriter log)62 protected TestEnvironment createTestEnvironment( 63 TestParameters Param, PrintWriter log) { 64 65 XInterface oObj = null; 66 67 XText oText = xTextDoc.getText(); 68 oText.setString("XAccessibleText"); 69 70 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc); 71 72 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel); 73 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); 74 75 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH); 76 77 log.println("ImplementationName " + utils.getImplName(oObj)); 78 79 TestEnvironment tEnv = new TestEnvironment(oObj); 80 81 final XText paraText = xTextDoc.getText(); 82 83 tEnv.addObjRelation("EventProducer", 84 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 85 public void fireEvent() { 86 String old = paraText.getString(); 87 paraText.setString("Just a line"); 88 paraText.setString(old); 89 } 90 }); 91 92 final String text = "XAccessibleText"; 93 94 tEnv.addObjRelation("XAccessibleText.Text", text); 95 96 return tEnv; 97 98 } 99 100 /** 101 * Called while disposing a <code>TestEnvironment</code>. 102 * Disposes text document. 103 * @param Param test parameters 104 * @param log writer to log information while testing 105 */ 106 @Override cleanup( TestParameters Param, PrintWriter log)107 protected void cleanup( TestParameters Param, PrintWriter log) { 108 log.println("dispose text document"); 109 util.DesktopTools.closeDoc(xTextDoc); 110 } 111 112 /** 113 * Called while the <code>TestCase</code> initialization. 114 * Creates a text document. 115 * 116 * @param Param test parameters 117 * @param log writer to log information while testing 118 * 119 * @see #initializeTestCase 120 */ 121 @Override initialize(TestParameters Param, PrintWriter log)122 protected void initialize(TestParameters Param, PrintWriter log) throws Exception { 123 log.println( "creating a text document" ); 124 xTextDoc = WriterTools.createTextDoc( Param.getMSF()); 125 } 126 } 127