Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / AccessiblePresentationOLEShape.java
blob16722f2a9040e7731726d39ff86c8dd82e19e897
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.DrawTools;
29 import util.SOfficeFactory;
30 import util.utils;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.awt.Size;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.beans.XPropertySet;
37 import com.sun.star.drawing.XShape;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 public class AccessiblePresentationOLEShape extends TestCase {
46 static XComponent xDrawDoc;
47 static XModel aModel;
49 @Override
50 protected void initialize( TestParameters tParam, PrintWriter log ) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
54 try {
55 log.println( "creating a drawdoc" );
56 xDrawDoc = SOF.createImpressDoc(null);
57 aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
59 } catch ( com.sun.star.uno.Exception e ) {
60 // Some exception occurs.FAILED
61 e.printStackTrace( log );
62 throw new StatusException( "Couldn't create document", e );
66 /**
67 * Disposes the Draw document loaded before.
69 @Override
70 protected void cleanup( TestParameters tParam, PrintWriter log ) {
71 log.println( " disposing xDrawDoc " );
72 util.DesktopTools.closeDoc(xDrawDoc);
75 @Override
76 protected TestEnvironment createTestEnvironment
77 (TestParameters tParam, PrintWriter log) {
79 XInterface oObj = null;
80 XShape oShape = null;
82 // creation of testobject here
83 // first we write what we are intend to do to log file
84 log.println( "creating a test environment" );
86 XMultiServiceFactory docMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc);
87 try {
88 oShape = UnoRuntime.queryInterface(XShape.class,
89 docMSF.createInstance("com.sun.star.presentation.OLE2Shape"));
90 } catch (com.sun.star.uno.Exception e) {
91 throw new StatusException("couldn't create component", e);
95 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
96 try {
97 oShapeProps.setPropertyValue("IsEmptyPresentationObject", Boolean.FALSE);
98 } catch (com.sun.star.lang.WrappedTargetException e) {
99 } catch (com.sun.star.lang.IllegalArgumentException e) {
100 } catch (com.sun.star.beans.PropertyVetoException e) {
101 } catch (com.sun.star.beans.UnknownPropertyException e) {
104 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
106 try {
107 oShapeProps.setPropertyValue(
108 "CLSID","12DCAE26-281F-416F-a234-c3086127382e");
109 oShapeProps.setPropertyValue("IsEmptyPresentationObject", Boolean.FALSE);
110 } catch (com.sun.star.lang.WrappedTargetException e) {
111 } catch (com.sun.star.lang.IllegalArgumentException e) {
112 } catch (com.sun.star.beans.PropertyVetoException e) {
113 } catch (com.sun.star.beans.UnknownPropertyException e) {
116 XWindow xWindow = AccessibilityTools.getCurrentWindow (aModel);
117 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
118 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
120 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "ImpressOLE");
122 // create test environment here
123 TestEnvironment tEnv = new TestEnvironment( oObj );
125 final XShape fShape = oShape ;
126 tEnv.addObjRelation("EventProducer",
127 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
128 public void fireEvent() {
129 try {
130 Size size = fShape.getSize();
131 size.Width += 100;
132 fShape.setSize(size);
133 } catch(com.sun.star.beans.PropertyVetoException e) {}
137 log.println("Implementation Name: " + utils.getImplName(oObj));
139 return tEnv;
140 } // finish method getTestEnvironment