tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XFastPropertySet.java
blob12f4a1bdc282b64a824edeba76bc14e1d78e5ff7
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 ifc.beans;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Random;
24 import java.util.Set;
26 import lib.MultiMethodTest;
27 import lib.StatusException;
28 import util.ValueChanger;
30 import com.sun.star.beans.Property;
31 import com.sun.star.beans.PropertyAttribute;
32 import com.sun.star.beans.XFastPropertySet;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.beans.XPropertySetInfo;
35 import com.sun.star.uno.UnoRuntime;
37 /**
38 * Testing <code>com.sun.star.beans.XFastPropertySet</code>
39 * interface methods :
40 * <ul>
41 * <li><code> setFastPropertyValue()</code></li>
42 * <li><code> getFastPropertyValue()</code></li>
43 * </ul> <p>
44 * Required relations :
45 * <ul>
46 * <li> <code>'XFastPropertySet.ExcludeProps'</code>
47 * <b>(optional) </b> : java.util.Set.
48 * Has property names which must be skipped from testing in
49 * some reasons (for example property accepts restricted set
50 * of values).
51 * </li>
52 * <ul> <p>
53 * @see com.sun.star.beans.XFastPropertySet
55 public class _XFastPropertySet extends MultiMethodTest {
56 public Random rnd = new Random();
58 private static final class Prop {
59 public final int handle;
60 public final String name;
62 public Prop(int handle, String name) {
63 this.handle = handle;
64 this.name = name;
68 public XFastPropertySet oObj = null;
69 private final List<Prop> props = new ArrayList<Prop>();
70 private Prop prop;
71 private Set<String> exclude = null ;
73 /**
74 * Retrieves relation.
76 @SuppressWarnings("unchecked")
77 @Override
78 protected void before() {
79 exclude = (Set<String>) tEnv.getObjRelation("XFastPropertySet.ExcludeProps") ;
80 if (exclude == null) {
81 exclude = new java.util.HashSet<String>() ;
85 /**
86 * Test selects random property which can not be VOID and
87 * is writable, then change property value using <code>
88 * get/set</code> methods, and checks if value properly changed.
89 * Has <b> OK </b> status if value after change is not equal to value
90 * before and no exceptions were thrown. <p>
92 public void _setFastPropertyValue() {
93 XPropertySet PS = UnoRuntime.queryInterface
94 (XPropertySet.class, oObj);
95 XPropertySetInfo propertySetInfo = PS.getPropertySetInfo();
97 if (propertySetInfo == null) {
98 log.println("getPropertySetInfo() method returned null");
99 tRes.tested("setFastPropertyValue()", false) ;
101 getPropsToTest(propertySetInfo);
103 Object gValue = null;
104 Object sValue = null;
106 if ( prop.handle == -1) {
107 log.println("*** No changeable properties found ***");
108 tRes.tested("setFastPropertyValue()", false) ;
109 } else {
110 try {
111 gValue = oObj.getFastPropertyValue(prop.handle);
112 sValue = ValueChanger.changePValue(gValue, prop.name);
113 oObj.setFastPropertyValue(prop.handle, sValue);
114 sValue = oObj.getFastPropertyValue(prop.handle);
115 } catch (com.sun.star.beans.UnknownPropertyException e) {
116 log.println("Exception occurred while trying to change property with handle = " + prop.handle);
117 e.printStackTrace(log);
118 } catch (com.sun.star.lang.WrappedTargetException e) {
119 log.println("Exception occurred while trying to change property with handle = " + prop.handle);
120 e.printStackTrace(log);
121 } catch (com.sun.star.beans.PropertyVetoException e) {
122 log.println("Exception occurred while trying to change property with handle = " + prop.handle);
123 e.printStackTrace(log);
124 } catch (com.sun.star.lang.IllegalArgumentException e) {
125 log.println("Exception occurred while trying to change property with handle = " + prop.handle);
126 e.printStackTrace(log);
129 tRes.tested("setFastPropertyValue()",(!gValue.equals(sValue)));
134 * Test selects random property which can not be VOID and
135 * is writable, then calls the method and checks that
136 * no exceptions were thrown. <p>
137 * Has <b> OK </b> status if exceptions were thrown. <p>
139 public void _getFastPropertyValue() {
140 XPropertySet PS = UnoRuntime.queryInterface
141 (XPropertySet.class, oObj);
142 XPropertySetInfo propertySetInfo = PS.getPropertySetInfo();
144 if (propertySetInfo == null) {
145 log.println("getPropertySetInfo() method returned null");
146 tRes.tested("getFastPropertyValue()", false) ;
149 getPropsToTest(propertySetInfo);
151 try {
152 oObj.getFastPropertyValue(prop.handle);
153 tRes.tested("getFastPropertyValue()",true);
154 } catch (com.sun.star.beans.UnknownPropertyException e) {
155 log.println("Exception occurred while trying to get property '"
156 + prop.handle +"'");
157 e.printStackTrace(log);
158 tRes.tested("getFastPropertyValue()",false);
159 } catch (com.sun.star.lang.WrappedTargetException e) {
160 log.println("Exception occurred while trying to get property '"
161 + prop.handle +"'");
162 e.printStackTrace(log);
163 tRes.tested("getFastPropertyValue()",false);
168 //Get the properties being tested
169 private void getPropsToTest(XPropertySetInfo xPSI) {
171 Property[] properties = xPSI.getProperties();
173 for (int i = 0; i < properties.length; i++) {
174 if (exclude.contains(properties[i].Name)) continue ;
175 Property property = properties[i];
176 String name = property.Name;
177 int handle = property.Handle;
178 log.println("Checking '" + name + "' with handle = " + handle);
179 boolean isWritable =
180 ((property.Attributes & PropertyAttribute.READONLY) == 0);
181 boolean isNotNull =
182 ((property.Attributes & PropertyAttribute.MAYBEVOID) == 0);
183 boolean canChange = false;
184 if ( isWritable && isNotNull )
185 canChange = isChangeable(handle, name);
186 if ( isWritable && isNotNull && canChange)
187 props.add(new Prop(handle, name));
188 } // endfor
190 int nr = rnd.nextInt(props.size());
191 prop = props.get(nr);
194 private boolean isChangeable(int handle, String name) {
195 boolean hasChanged = false;
196 try {
197 Object getProp = oObj.getFastPropertyValue(handle);
198 Object setValue = null;
200 if (getProp != null)
201 setValue = ValueChanger.changePValue(getProp, name);
202 else
203 log.println("Property with handle = " + handle
204 + " is null but 'MAYBEVOID' isn't set");
205 if (setValue != null) {
206 oObj.setFastPropertyValue(handle, setValue);
207 hasChanged =
208 (!getProp.equals(oObj.getFastPropertyValue(handle)));
210 else
211 log.println("Couldn't change Property with handle " + handle);
212 } catch(com.sun.star.lang.WrappedTargetException e) {
213 log.println("Property with handle " + handle + " throws exception");
214 e.printStackTrace(log);
215 throw new StatusException("Property with handle " + handle
216 + " throws exception", e);
217 } catch(com.sun.star.lang.IllegalArgumentException e) {
218 log.println("Property with handle " + handle + " throws exception");
219 e.printStackTrace(log);
220 throw new StatusException("Property with handle " + handle
221 + " throws exception", e);
222 } catch(com.sun.star.beans.PropertyVetoException e) {
223 log.println("Property with handle " + handle + " throws exception");
224 e.printStackTrace(log);
225 throw new StatusException("Property with handle " + handle
226 + " throws exception", e);
227 } catch(com.sun.star.beans.UnknownPropertyException e) {
228 log.println("Property with handle " + handle + " throws exception");
229 e.printStackTrace(log);
230 throw new StatusException("Property with handle " + handle
231 + " throws exception", e);
234 return hasChanged;