tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XPropertyState.java
blobca7337a7417a28bb6fb4a3f2679f009ecf90a69c
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 lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.beans.Property;
26 import com.sun.star.beans.PropertyAttribute;
27 import com.sun.star.beans.PropertyState;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.beans.XPropertySetInfo;
30 import com.sun.star.beans.XPropertyState;
31 import com.sun.star.uno.Any;
32 import com.sun.star.uno.UnoRuntime;
35 /**
36 * Testing <code>com.sun.star.beans.XPropertyState</code>
37 * interface methods :
38 * <ul>
39 * <li><code> getPropertyState()</code></li>
40 * <li><code> getPropertyStates()</code></li>
41 * <li><code> setPropertyToDefault()</code></li>
42 * <li><code> getPropertyDefault()</code></li>
43 * </ul>
44 * Test is <b> NOT </b> multithread compliant. <p>
45 * After test completion object environment has to be recreated. <p>
46 * <b>Note:</b> object tested must also implement
47 * <code>com.sun.star.beans.XPropertySet</code> interface.
48 * @see com.sun.star.beans.XPropertyState
50 public class _XPropertyState extends MultiMethodTest {
52 public XPropertyState oObj = null;
54 private XPropertySet oPS = null ;
55 private XPropertySetInfo propertySetInfo = null;
56 private Property[] properties = null ;
57 private String pName = null ;
58 private Object propDef = null ;
60 /**
61 * Queries object for <code>XPropertySet</code> interface and
62 * initializes some fields used by all methods. <p>
64 * Searches property which is not READONLY and MAYBEDEFAULT, if
65 * such property is not found, then uses property with only
66 * READONLY attribute. This property name is stored and is used
67 * by all tests.
69 * @throws StatusException If <code>XPropertySet</code> is not
70 * implemented by object.
72 @Override
73 public void before() throws StatusException {
74 oPS = UnoRuntime.queryInterface( XPropertySet.class, oObj );
75 if (oPS == null)
76 throw new StatusException
77 ("XPropertySet interface isn't implemented.",
78 new NullPointerException
79 ("XPropertySet interface isn't implemented.")) ;
81 propertySetInfo = oPS.getPropertySetInfo();
82 properties = propertySetInfo.getProperties();
83 Property prop = null;
84 for (int i=0;i<properties.length;i++) {
85 try {
86 prop = propertySetInfo.getPropertyByName
87 (properties[i].Name);
88 } catch (com.sun.star.beans.UnknownPropertyException e) {
89 log.println("Unknown Property "+prop.Name);
91 boolean readOnly = (prop.Attributes &
92 PropertyAttribute.READONLY) != 0;
93 boolean maybeDefault = (prop.Attributes &
94 PropertyAttribute.MAYBEDEFAULT) != 0;
95 if (!readOnly && maybeDefault) {
96 pName = properties[i].Name;
97 log.println("Property '" + pName + "' has attributes "+
98 prop.Attributes);
99 break ;
100 } else
101 if (!readOnly) {
102 pName = properties[i].Name;
103 log.println("Property '" + pName +
104 "' is not readonly, may be used ...");
105 } else {
106 log.println("Skipping property '" + properties[i].Name +
107 "' Readonly: " + readOnly + ", MaybeDefault: " +
108 maybeDefault);
115 * Test calls the method and checks that no exceptions were thrown. <p>
116 * Has <b> OK </b> status if no exceptions were thrown. <p>
118 public void _getPropertyDefault(){
119 boolean result = true ;
120 String localName = pName;
121 if (localName == null) {
122 localName = propertySetInfo.getProperties()[0].Name;
124 try {
125 propDef = oObj.getPropertyDefault(localName);
126 log.println("Default property value is : '" + propDef + "'");
127 } catch (com.sun.star.beans.UnknownPropertyException e) {
128 log.println("Exception " + e +
129 "occurred while getting Property default");
130 result=false;
131 } catch (com.sun.star.lang.WrappedTargetException e) {
132 log.println("Exception " + e +
133 "occurred while getting Property default");
134 result=false;
136 tRes.tested("getPropertyDefault()", result);
140 * Test calls the method and checks return value and that
141 * no exceptions were thrown. <p>
142 * Has <b> OK </b> status if the method returns not null value
143 * and no exceptions were thrown. <p>
145 public void _getPropertyState(){
146 boolean result = true ;
148 String localName = pName;
149 if (localName == null) {
150 localName = propertySetInfo.getProperties()[0].Name;
153 try {
154 PropertyState ps = oObj.getPropertyState(localName);
155 if (ps == null) {
156 log.println("!!! Returned value == null") ;
157 result = false ;
159 } catch (com.sun.star.beans.UnknownPropertyException e) {
160 log.println("Exception " + e +
161 "occurred while getting Property state");
162 result = false;
164 tRes.tested("getPropertyState()", result);
168 * Test calls the method with array of one property name
169 * and checks return value and that no exceptions were thrown. <p>
170 * Has <b> OK </b> status if the method returns array with one
171 * PropertyState and no exceptions were thrown. <p>
173 public void _getPropertyStates(){
174 boolean result = true ;
176 String localName = pName;
177 if (localName == null) {
178 localName = propertySetInfo.getProperties()[0].Name;
181 try {
182 PropertyState[] ps = oObj.getPropertyStates
183 (new String[] {localName});
184 if (ps == null) {
185 log.println("!!! Returned value == null") ;
186 result = false ;
187 } else {
188 if (ps.length != 1) {
189 log.println("!!! Array length returned is invalid - " +
190 ps.length) ;
191 result = false ;
194 } catch (com.sun.star.beans.UnknownPropertyException e) {
195 log.println("Exception " + e +
196 "occurred while getting Property state");
197 result = false;
200 tRes.tested("getPropertyStates()", result);
205 * Sets the property to default, then compares the current property
206 * value to value received by method <code>getPropertyDefault</code>.
207 * Has <b> OK </b> status if the current property value equals to
208 * default property. <p>
209 * The following method tests are to be completed successfully before :
210 * <ul>
211 * <li> <code>getPropertyDefault</code>: we have to know what is
212 * default value</li></ul>
214 public void _setPropertyToDefault(){
215 requiredMethod("getPropertyDefault()") ;
217 if (pName == null) {
218 log.println("all found properties are read only");
219 tRes.tested("setPropertyToDefault()",Status.skipped(true));
220 return;
223 boolean result = true ;
224 try {
225 try {
226 oObj.setPropertyToDefault(pName);
228 catch(RuntimeException e) {
229 System.out.println("Ignoring RuntimeException: " + e.getMessage());
231 if ((properties[0].Attributes &
232 PropertyAttribute.MAYBEDEFAULT) != 0) {
233 Object actualDef = propDef ;
234 if (propDef instanceof Any) {
235 actualDef = ((Any)propDef).getObject() ;
237 Object actualVal = oPS.getPropertyValue(pName) ;
238 if (actualVal instanceof Any) {
239 actualVal = ((Any)actualVal).getObject() ;
241 result = util.ValueComparer.equalValue
242 (actualDef,actualVal) ;
243 log.println("Default value = '" + actualDef +
244 "', returned value = '"
245 + actualVal + "' for property " + pName) ;
247 } catch (com.sun.star.beans.UnknownPropertyException e) {
248 log.println("Exception " + e +
249 "occurred while setting Property to default");
250 result=false;
251 } catch (com.sun.star.lang.WrappedTargetException e) {
252 log.println("Exception " + e +
253 "occurred while testing property value");
254 result=false;
257 tRes.tested("setPropertyToDefault()", result);
260 @Override
261 public void after() {
262 disposeEnvironment() ;
265 }// EOF _XPropertyState