1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._sw; 24 25 import java.io.PrintWriter; 26 27 import lib.StatusException; 28 import lib.TestCase; 29 import lib.TestEnvironment; 30 import lib.TestParameters; 31 import util.AccessibilityTools; 32 import util.WriterTools; 33 import util.utils; 34 35 import com.sun.star.accessibility.AccessibleRole; 36 import com.sun.star.accessibility.XAccessible; 37 import com.sun.star.awt.XWindow; 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.container.XNameAccess; 40 import com.sun.star.frame.XModel; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.style.XStyle; 43 import com.sun.star.style.XStyleFamiliesSupplier; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.uno.AnyConverter; 46 import com.sun.star.uno.Type; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 /** 51 * Test of accessible object for a header of a text document.<p> 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li> 55 * </ul> 56 * @see com.sun.star.accessibility.XAccessible 57 */ 58 public class SwAccessibleHeaderView extends TestCase { 59 60 XTextDocument xTextDoc = null; 61 62 /** 63 * Called to create an instance of <code>TestEnvironment</code> 64 * with an object to test and related objects. Obtains style 65 * <code>Standard</code> from style family <code>PageStyles</code>. 66 * Changes values of properties <code>HeaderIsOn</code> and 67 * <code>FooterIsOn</code> by <code>true</code>. Obtains accessible component 68 * for header. 69 * 70 * @param tParam test parameters 71 * @param log writer to log information while testing 72 * 73 * @see TestEnvironment 74 * @see #getTestEnvironment() 75 */ 76 protected TestEnvironment createTestEnvironment( 77 TestParameters Param, PrintWriter log) { 78 79 XInterface oObj = null; 80 XNameAccess PageStyles = null; 81 XStyle StdStyle = null; 82 83 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 84 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc); 85 XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 86 87 // obtains style 'Standatd' from style family 'PageStyles' 88 try { 89 PageStyles = (XNameAccess) AnyConverter.toObject( 90 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 91 StdStyle = (XStyle) AnyConverter.toObject( 92 new Type(XStyle.class),PageStyles.getByName("Standard")); 93 } catch ( com.sun.star.lang.WrappedTargetException e ) { 94 e.printStackTrace(log); 95 throw new StatusException("Error getting style by name!", e); 96 } catch ( com.sun.star.container.NoSuchElementException e ) { 97 e.printStackTrace(log); 98 throw new StatusException("Error, no such style name! ", e); 99 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 100 e.printStackTrace(log); 101 throw new StatusException("Error getting style by name!", e); 102 } 103 104 final XPropertySet PropSet = (XPropertySet) 105 UnoRuntime.queryInterface( XPropertySet.class, StdStyle); 106 107 // changing/getting some properties 108 try { 109 log.println( "Switching on header" ); 110 PropSet.setPropertyValue("HeaderIsOn", new Boolean(true)); 111 } catch ( com.sun.star.lang.WrappedTargetException e ) { 112 e.printStackTrace(log); 113 throw new StatusException("Couldn't set propertyValue...", e); 114 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 115 e.printStackTrace(log); 116 throw new StatusException("Couldn't set propertyValue...", e); 117 } catch ( com.sun.star.beans.PropertyVetoException e ) { 118 e.printStackTrace(log); 119 throw new StatusException("Couldn't set propertyValue...", e); 120 } catch ( com.sun.star.beans.UnknownPropertyException e ) { 121 e.printStackTrace(log); 122 throw new StatusException("Couldn't set propertyValue...", e); 123 } 124 125 XModel aModel = (XModel) 126 UnoRuntime.queryInterface(XModel.class, xTextDoc); 127 128 AccessibilityTools at = new AccessibilityTools(); 129 130 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 131 XAccessible xRoot = at.getAccessibleObject(xWindow); 132 133 at.getAccessibleObjectForRole(xRoot, AccessibleRole.HEADER); 134 135 oObj = AccessibilityTools.SearchedContext; 136 137 log.println("ImplementationName " + utils.getImplName(oObj)); 138 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 139 140 TestEnvironment tEnv = new TestEnvironment(oObj); 141 142 tEnv.addObjRelation("EventProducer", 143 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 144 public void fireEvent() { 145 try { 146 PropSet.setPropertyValue("HeaderLeftMargin", 147 new Integer(1000)); 148 } catch (com.sun.star.uno.Exception e) { 149 e.printStackTrace(); 150 throw new StatusException("Cann't change footer.", e); 151 } 152 } 153 }); 154 155 return tEnv; 156 157 } 158 159 /** 160 * Called while disposing a <code>TestEnvironment</code>. 161 * Disposes text document. 162 * @param tParam test parameters 163 * @param tEnv the environment to cleanup 164 * @param log writer to log information while testing 165 */ 166 protected void cleanup( TestParameters Param, PrintWriter log) { 167 log.println("dispose text document"); 168 util.DesktopTools.closeDoc(xTextDoc); 169 } 170 171 /** 172 * Called while the <code>TestCase</code> initialization. 173 * Creates a text document. 174 * 175 * @param tParam test parameters 176 * @param log writer to log information while testing 177 * 178 * @see #initializeTestCase() 179 */ 180 protected void initialize(TestParameters Param, PrintWriter log) { 181 log.println( "creating a text document" ); 182 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF()); 183 } 184 } 185