bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / SmEditAccessible.java
blob68ad155820d8e073caeeddd688e23a6cac2dd5c4
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._sm;
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.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.accessibility.XAccessibleContext;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
45 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
46 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
47 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
48 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
49 * </ul> <p>
51 * @see com.sun.star.accessibility.XAccessible
52 * @see com.sun.star.accessibility.XAccessibleComponent
53 * @see com.sun.star.accessibility.XAccessibleContext
54 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
55 * @see com.sun.star.accessibility.XAccessibleText
56 * @see ifc.accessibility._XAccessible
57 * @see ifc.accessibility._XAccessibleComponent
58 * @see ifc.accessibility._XAccessibleContext
59 * @see ifc.accessibility._XAccessibleEventBroadcaster
60 * @see ifc.accessibility._XAccessibleText
62 public class SmEditAccessible extends TestCase {
63 XComponent xMathDoc;
65 /**
66 * Creates a <code>StarMath</code> document and obtains an accessibility
67 * component with the role <code>AccessibleRole.PANEL</code>.
69 @Override
70 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() );
73 try {
74 xMathDoc = SOF.openDoc("smath","_blank");
75 } catch (com.sun.star.lang.IllegalArgumentException ex) {
76 ex.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", ex );
78 } catch (com.sun.star.io.IOException ex) {
79 ex.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", ex );
81 } catch (com.sun.star.uno.Exception ex) {
82 ex.printStackTrace( log );
83 throw new StatusException( "Couldn't create document", ex );
86 // setting a formula in document
87 final String expFormula = "sum hat a";
88 final XPropertySet xPS = UnoRuntime.queryInterface
89 (XPropertySet.class, xMathDoc);
90 try {
91 xPS.setPropertyValue("Formula", expFormula);
92 } catch(com.sun.star.lang.WrappedTargetException e) {
93 log.println("Couldn't set property value");
94 e.printStackTrace(log);
95 } catch(com.sun.star.lang.IllegalArgumentException e) {
96 log.println("Couldn't set property value");
97 e.printStackTrace(log);
98 } catch(com.sun.star.beans.PropertyVetoException e) {
99 log.println("Couldn't set property value");
100 e.printStackTrace(log);
101 } catch(com.sun.star.beans.UnknownPropertyException e) {
102 log.println("Couldn't set property value");
103 e.printStackTrace(log);
106 XInterface oObj = null;
108 XModel aModel = UnoRuntime.queryInterface(XModel.class, xMathDoc);
111 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
112 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
114 oObj = AccessibilityTools.getAccessibleObjectForRole
115 (xRoot, AccessibleRole.PANEL, "", "SmEditAccessible");
117 log.println("ImplementationName " + utils.getImplName(oObj));
118 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
119 TestEnvironment tEnv = new TestEnvironment(oObj);
121 tEnv.addObjRelation("Destroy", Boolean.TRUE);
123 final XAccessibleContext con = UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
124 tEnv.addObjRelation("EventProducer",
125 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
126 public void fireEvent() {
127 try {
128 System.out.println("Children "+con.getAccessibleChildCount());
129 xPS.setPropertyValue("Formula", "sum hat x \n int a \n sum b");
130 util.utils.pause(1000);
131 System.out.println("Children "+con.getAccessibleChildCount());
132 xPS.setPropertyValue("Formula", expFormula);
133 util.utils.pause(1000);
134 } catch(com.sun.star.lang.WrappedTargetException e) {
135 } catch(com.sun.star.lang.IllegalArgumentException e) {
136 } catch(com.sun.star.beans.PropertyVetoException e) {
137 } catch(com.sun.star.beans.UnknownPropertyException e) {
142 return tEnv;
146 * Disposes the document created in <code>createTestEnvironment</code>
147 * method.
149 @Override
150 protected void cleanup( TestParameters Param, PrintWriter log) {
152 log.println( " disposing xMathDoc " );
153 xMathDoc.dispose();
155 } // finish class SmModel