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._sch; 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.SOfficeFactory; 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.PosSize; 38 import com.sun.star.awt.Rectangle; 39 import com.sun.star.awt.XWindow; 40 import com.sun.star.chart.XChartDocument; 41 import com.sun.star.frame.XModel; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 public class AccessibleDocumentView extends TestCase { 47 48 XChartDocument xChartDoc = null; 49 50 protected TestEnvironment createTestEnvironment( 51 TestParameters Param, PrintWriter log) { 52 53 XInterface oObj = null; 54 55 XModel aModel = (XModel) 56 UnoRuntime.queryInterface(XModel.class, xChartDoc); 57 58 AccessibilityTools at = new AccessibilityTools(); 59 60 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 61 XAccessible xRoot = at.getAccessibleObject(xWindow); 62 63 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); 64 65 oObj = AccessibilityTools.SearchedContext; 66 67 if (oObj == null) { 68 log.println("DocumentView hasn't the role 'Document'"); 69 log.println("trying the role 'Shape'"); 70 at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE); 71 oObj = AccessibilityTools.SearchedContext; 72 } 73 74 log.println("ImplementationName " + utils.getImplName(oObj)); 75 76 TestEnvironment tEnv = new TestEnvironment(oObj); 77 78 final XWindow xDocWin = xWindow; 79 tEnv.addObjRelation("EventProducer", 80 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 81 public void fireEvent() { 82 Rectangle rect = xDocWin.getPosSize(); 83 xDocWin.setPosSize(100,100,100,100,PosSize.POSSIZE); 84 xDocWin.setPosSize(rect.X,rect.Y,rect.Width,rect.Height, 85 PosSize.POSSIZE); 86 } 87 }); 88 89 return tEnv; 90 91 } 92 93 /** 94 * Called while disposing a <code>TestEnvironment</code>. 95 * Disposes text document. 96 * @param tParam test parameters 97 * @param tEnv the environment to cleanup 98 * @param log writer to log information while testing 99 */ 100 protected void cleanup( TestParameters Param, PrintWriter log) { 101 if( xChartDoc!=null ) { 102 log.println( " closing xChartDoc" ); 103 util.DesktopTools.closeDoc(xChartDoc); 104 xChartDoc = null; 105 } 106 } 107 108 /** 109 * Called while the <code>TestCase</code> initialization. 110 * Creates a chart document. 111 * 112 * @param tParam test parameters 113 * @param log writer to log information while testing 114 * 115 * @see #initializeTestCase() 116 */ 117 protected void initialize(TestParameters Param, PrintWriter log) { 118 log.println( "creating a text document" ); 119 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 120 try { 121 log.println( "creating a chartdocument" ); 122 xChartDoc = SOF.createChartDoc(null); 123 } catch (com.sun.star.uno.Exception e) { 124 // Some exception occures.FAILED 125 e.printStackTrace( log ); 126 throw new StatusException( "Couldn't create document", e ); 127 } 128 } 129 } 130