1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._sch; 28 29 import java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.AccessibilityTools; 36 import util.SOfficeFactory; 37 import util.utils; 38 39 import com.sun.star.accessibility.AccessibleRole; 40 import com.sun.star.accessibility.XAccessible; 41 import com.sun.star.awt.PosSize; 42 import com.sun.star.awt.Rectangle; 43 import com.sun.star.awt.XWindow; 44 import com.sun.star.chart.XChartDocument; 45 import com.sun.star.frame.XModel; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 public class AccessibleDocumentView extends TestCase { 51 52 XChartDocument xChartDoc = null; 53 54 protected TestEnvironment createTestEnvironment( 55 TestParameters Param, PrintWriter log) { 56 57 XInterface oObj = null; 58 59 XModel aModel = (XModel) 60 UnoRuntime.queryInterface(XModel.class, xChartDoc); 61 62 AccessibilityTools at = new AccessibilityTools(); 63 64 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 65 XAccessible xRoot = at.getAccessibleObject(xWindow); 66 67 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); 68 69 oObj = AccessibilityTools.SearchedContext; 70 71 if (oObj == null) { 72 log.println("DocumentView hasn't the role 'Document'"); 73 log.println("trying the role 'Shape'"); 74 at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE); 75 oObj = AccessibilityTools.SearchedContext; 76 } 77 78 log.println("ImplementationName " + utils.getImplName(oObj)); 79 80 TestEnvironment tEnv = new TestEnvironment(oObj); 81 82 final XWindow xDocWin = xWindow; 83 tEnv.addObjRelation("EventProducer", 84 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 85 public void fireEvent() { 86 Rectangle rect = xDocWin.getPosSize(); 87 xDocWin.setPosSize(100,100,100,100,PosSize.POSSIZE); 88 xDocWin.setPosSize(rect.X,rect.Y,rect.Width,rect.Height, 89 PosSize.POSSIZE); 90 } 91 }); 92 93 return tEnv; 94 95 } 96 97 /** 98 * Called while disposing a <code>TestEnvironment</code>. 99 * Disposes text document. 100 * @param tParam test parameters 101 * @param tEnv the environment to cleanup 102 * @param log writer to log information while testing 103 */ 104 protected void cleanup( TestParameters Param, PrintWriter log) { 105 if( xChartDoc!=null ) { 106 log.println( " closing xChartDoc" ); 107 util.DesktopTools.closeDoc(xChartDoc); 108 xChartDoc = null; 109 } 110 } 111 112 /** 113 * Called while the <code>TestCase</code> initialization. 114 * Creates a chart document. 115 * 116 * @param tParam test parameters 117 * @param log writer to log information while testing 118 * 119 * @see #initializeTestCase() 120 */ 121 protected void initialize(TestParameters Param, PrintWriter log) { 122 log.println( "creating a text document" ); 123 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 124 try { 125 log.println( "creating a chartdocument" ); 126 xChartDoc = SOF.createChartDoc(null); 127 } catch (com.sun.star.uno.Exception e) { 128 // Some exception occures.FAILED 129 e.printStackTrace( log ); 130 throw new StatusException( "Couldn't create document", e ); 131 } 132 } 133 } 134