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.Size;
40  import com.sun.star.awt.XWindow;
41  import com.sun.star.beans.XPropertySet;
42  import com.sun.star.drawing.XShape;
43  import com.sun.star.frame.XModel;
44  import com.sun.star.lang.XComponent;
45  import com.sun.star.lang.XMultiServiceFactory;
46  import com.sun.star.uno.UnoRuntime;
47  import com.sun.star.uno.XInterface;
48  
49  public class AccessiblePresentationOLEShape extends TestCase {
50  
51      static XComponent xDrawDoc;
52      static XModel aModel;
53  
initialize( TestParameters tParam, PrintWriter log )54      protected void initialize( TestParameters tParam, PrintWriter log ) {
55  
56          SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
57  
58          try {
59              log.println( "creating a drawdoc" );
60              xDrawDoc = SOF.createImpressDoc(null);
61              aModel = (XModel)
62                  UnoRuntime.queryInterface(XModel.class, xDrawDoc);
63  
64          } catch ( com.sun.star.uno.Exception e ) {
65              // Some exception occured.FAILED
66              e.printStackTrace( log );
67              throw new StatusException( "Couldn't create document", e );
68          }
69      }
70  
71      /**
72       * Disposes the Draw document loaded before.
73       */
cleanup( TestParameters tParam, PrintWriter log )74      protected void cleanup( TestParameters tParam, PrintWriter log ) {
75          log.println( "    disposing xDrawDoc " );
76          util.DesktopTools.closeDoc(xDrawDoc);
77      }
78  
createTestEnvironment(TestParameters tParam, PrintWriter log)79      protected TestEnvironment createTestEnvironment
80              (TestParameters tParam, PrintWriter log) {
81  
82          XInterface oObj = null;
83          XShape oShape = 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          XMultiServiceFactory docMSF = (XMultiServiceFactory)
90              UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc);
91          try {
92              oShape = (XShape) UnoRuntime.queryInterface(XShape.class,
93                  docMSF.createInstance("com.sun.star.presentation.OLE2Shape"));
94          } catch (com.sun.star.uno.Exception e) {
95              throw new StatusException("couldn't create component", e);
96          }
97  
98  
99          //DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
100  
101          XPropertySet oShapeProps = (XPropertySet)
102                              UnoRuntime.queryInterface(XPropertySet.class,oShape);
103          try {
104              oShapeProps.setPropertyValue("IsEmptyPresentationObject", new Boolean(false));
105          } catch (com.sun.star.lang.WrappedTargetException e) {
106          } catch (com.sun.star.lang.IllegalArgumentException e) {
107          } catch (com.sun.star.beans.PropertyVetoException e) {
108          } catch (com.sun.star.beans.UnknownPropertyException e) {
109          }
110  
111          DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
112  
113          try {
114              oShapeProps.setPropertyValue(
115                  "CLSID","12DCAE26-281F-416F-a234-c3086127382e");
116              oShapeProps.setPropertyValue("IsEmptyPresentationObject", new Boolean(false));
117          } catch (com.sun.star.lang.WrappedTargetException e) {
118          } catch (com.sun.star.lang.IllegalArgumentException e) {
119          } catch (com.sun.star.beans.PropertyVetoException e) {
120          } catch (com.sun.star.beans.UnknownPropertyException e) {
121          }
122  
123          AccessibilityTools at = new AccessibilityTools();
124  
125          XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
126          XAccessible xRoot = at.getAccessibleObject(xWindow);
127          at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
128  
129  //        oObj = at.getAccessibleObjectForRole
130  //            (xRoot, AccessibleRole.SHAPE, "ImpressOLE");
131          oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "ImpressOLE");
132  
133          // create test environment here
134          TestEnvironment tEnv = new TestEnvironment( oObj );
135  
136          final XShape fShape = oShape ;
137          tEnv.addObjRelation("EventProducer",
138              new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
139                  public void fireEvent() {
140                      try {
141                          Size size = fShape.getSize();
142                          size.Width += 100;
143                          fShape.setSize(size);
144                      } catch(com.sun.star.beans.PropertyVetoException e) {}
145                  }
146              });
147  
148          log.println("Implementation Name: " + utils.getImplName(oObj));
149  
150          return tEnv;
151      } // finish method getTestEnvironment
152  
153  }
154  
155