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 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.AccessibilityTools;
33 import util.DrawTools;
34 import util.SOfficeFactory;
35 import util.utils;
36 
37 import com.sun.star.accessibility.AccessibleRole;
38 import com.sun.star.accessibility.XAccessible;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.drawing.XDrawPage;
42 import com.sun.star.frame.XModel;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 public class AccessiblePageShape extends TestCase {
49 
50     static XComponent xDrawDoc;
51     static XModel aModel;
52 
initialize( TestParameters tParam, PrintWriter log )53     protected void initialize( TestParameters tParam, PrintWriter log ) {
54 
55         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
56 
57         try {
58             log.println( "creating a drawdoc" );
59             xDrawDoc = SOF.createDrawDoc(null);
60             aModel = (XModel)
61                 UnoRuntime.queryInterface(XModel.class, xDrawDoc);
62 
63         } catch ( com.sun.star.uno.Exception e ) {
64             // Some exception occured.FAILED
65             e.printStackTrace( log );
66             throw new StatusException( "Couldn't create document", e );
67         }
68     }
69 
70     /**
71      * Disposes the Draw document loaded before.
72      */
cleanup( TestParameters tParam, PrintWriter log )73     protected void cleanup( TestParameters tParam, PrintWriter log ) {
74         log.println( "    disposing xDrawDoc " );
75         util.DesktopTools.closeDoc(xDrawDoc);
76     }
77 
createTestEnvironment(TestParameters tParam, PrintWriter log)78     protected TestEnvironment createTestEnvironment
79             (TestParameters tParam, PrintWriter log) {
80 
81         XInterface oObj = null;
82         //XShape oShape = null;
83         XDrawPage oPage = null;
84 
85         // creation of testobject here
86         // first we write what we are intend to do to log file
87         log.println( "creating a test environment" );
88 
89         AccessibilityTools at = new AccessibilityTools();
90 
91         XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
92         XAccessible xRoot = at.getAccessibleObject(xWindow);
93 
94         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
95 
96 //        oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE,
97 //            "PageShape");
98         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "PageShape");
99 
100         // create test environment here
101         TestEnvironment tEnv = new TestEnvironment( oObj );
102 
103         //at.getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLLBAR);
104         //final XAccessibleValue xAccVal = (XAccessibleValue)
105         //  UnoRuntime.queryInterface
106         //    (XAccessibleValue.class, at.SearchedContext) ;
107         oPage = DrawTools.getDrawPage(xDrawDoc,0);
108         final XPropertySet PageProps = (XPropertySet)
109             UnoRuntime.queryInterface(XPropertySet.class, oPage);
110 
111         tEnv.addObjRelation("EventProducer",
112             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
113                 public void fireEvent() {
114                     try {
115                         PageProps.setPropertyValue("Height",new Integer(5000));
116                     } catch (com.sun.star.beans.UnknownPropertyException upe) {
117                         System.out.println("Don't no the Property Height");
118                     } catch (com.sun.star.beans.PropertyVetoException pve) {
119                         System.out.println(
120                         "PropertyVetoException Exception while changing Height");
121                     } catch (com.sun.star.lang.IllegalArgumentException iae) {
122                         System.out.println(
123                         "IllegalArgumentException Exception while changing Height");
124                     } catch (com.sun.star.lang.WrappedTargetException wte) {
125                         System.out.println(
126                         "WrappedTargetException Exception while changing Height");
127                     }
128                 }
129             });
130 
131         log.println("Implementation Name: " + utils.getImplName(oObj));
132 
133         return tEnv;
134     } // finish method getTestEnvironment
135 
136 }
137 
138