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 
createTestEnvironment( TestParameters Param, PrintWriter log)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 Param test parameters
97     * @param log writer to log information while testing
98     */
cleanup( TestParameters Param, PrintWriter log)99     protected void cleanup( TestParameters Param, PrintWriter log) {
100         if( xChartDoc!=null ) {
101             log.println( "    closing xChartDoc" );
102             util.DesktopTools.closeDoc(xChartDoc);
103             xChartDoc = null;
104         }
105     }
106 
107     /**
108      * Called while the <code>TestCase</code> initialization.
109      * Creates a chart document.
110      *
111      * @param Param test parameters
112      * @param log writer to log information while testing
113      *
114      * @see #initializeTestCase
115      */
initialize(TestParameters Param, PrintWriter log)116     protected void initialize(TestParameters Param, PrintWriter log) {
117         log.println( "creating a text document" );
118         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
119         try {
120             log.println( "creating a chartdocument" );
121             xChartDoc = SOF.createChartDoc(null);
122         } catch (com.sun.star.uno.Exception e) {
123             // Some exception occures.FAILED
124             e.printStackTrace( log );
125             throw new StatusException( "Couldn't create document", e );
126         }
127     }
128 }
129