tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XMultiPropertyStates.java
blob884fb27afb8de452cedb1f17467f48d2de9c11d2
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.XMultiPropertyStates;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.beans.XPropertySetInfo;
31 import com.sun.star.uno.UnoRuntime;
33 /**
34 * Testing <code>com.sun.star.beans.XMultiPropertyStates</code>
35 * interface methods :
36 * <ul>
37 * <li><code> getPropertyStates()</code></li>
38 * <li><code> setAllPropertiesToDefault()</code></li>
39 * <li><code> getPropertyValues()</code></li>
40 * <li><code> setPropertiesToDefault()</code></li>
41 * <li><code> getPropertyDefaults()</code></li>
42 * </ul>
43 * @see com.sun.star.beans.XMultiPropertyStates
45 public class _XMultiPropertyStates extends MultiMethodTest {
47 public XMultiPropertyStates oObj = null;
49 private PropertyState[] states = null;
50 private String[] names = null;
52 @Override
53 public void before() {
54 names = (String[]) tEnv.getObjRelation("PropertyNames");
55 if (names == null) {
56 throw new StatusException(Status.failed("No PropertyNames given"));
59 log.println("Totally " + names.length + " properties encountered:");
60 log.print("{");
61 for (int i = 0; i < names.length; i++)
62 log.print(names[i] + " ");
63 log.print("}");
64 log.println("");
68 /**
69 * Test calls the method and checks return value.
70 * <code>PropertyDefaults</code> are stored<p>
71 * Has <b> OK </b> status if the method returns not null value
72 * and no exceptions were thrown. <p>
74 public void _getPropertyDefaults() {
75 boolean result = false;
76 try {
77 Object[] defaults = oObj.getPropertyDefaults(names);
78 log.println("Number of default values: " + defaults.length);
79 result = defaults.length == names.length;
80 } catch (com.sun.star.beans.UnknownPropertyException e) {
81 log.println("some properties seem to be unknown: " + e.toString());
82 } catch (com.sun.star.lang.WrappedTargetException e) {
83 log.println("Wrapped target Exception was thrown: " + e.toString());
85 tRes.tested("getPropertyDefaults()", result) ;
88 /**
89 * Test calls the method and checks return value.
90 * Has <b> OK </b> status if the method returns not null value
91 * and no exceptions were thrown. <p>
93 public void _getPropertyStates() {
94 boolean result = false;
95 try {
96 states = oObj.getPropertyStates(names);
97 result = (states != null) && (states.length == names.length);
98 if (states != null) {
99 log.println("Number of states: " + states.length);
101 else {
102 log.println("Number of states: <null>");
104 } catch (com.sun.star.beans.UnknownPropertyException e) {
105 log.println("some properties seem to be unknown: " + e.toString());
107 tRes.tested("getPropertyStates()", result) ;
111 * Test calls the method and checks return value.
112 * Has <b> OK </b> status if the Property
113 * has default state afterwards. <p>
115 public void _setPropertiesToDefault() {
116 requiredMethod("getPropertyStates()");
117 // searching for property which currently don't have default value
118 // and preferable has MAYBEDEFAULT attr
119 // if no such properties are found then the first one is selected
121 String ro = (String) tEnv.getObjRelation("allReadOnly");
122 if (ro != null) {
123 log.println(ro);
124 tRes.tested("setPropertiesToDefault()",Status.skipped(true));
125 return;
128 boolean mayBeDef = false;
129 String propName = names[0];
131 for(int i = 0; i < names.length; i++) {
132 if (!mayBeDef && states[i] != PropertyState.DEFAULT_VALUE ) {
133 propName = names[i];
134 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
135 XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo();
136 Property prop = null;
137 try {
138 prop = xPropSetInfo.getPropertyByName(names[i]);
140 catch(com.sun.star.beans.UnknownPropertyException e) {
141 throw new StatusException(e, Status.failed("couldn't get property info"));
143 if ( (prop.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0){
144 log.println("Property " + names[i] +
145 " 'may be default' and doesn't have default value");
146 mayBeDef = true;
150 log.println("The property " + propName + " selected");
152 boolean result = false;
153 try {
154 String[] the_first = new String[1];
155 the_first[0] = propName;
156 log.println("Setting " + propName + " to default");
157 oObj.setPropertiesToDefault(the_first);
158 result = oObj.getPropertyStates(the_first)[0].equals(PropertyState.DEFAULT_VALUE);
159 } catch (com.sun.star.beans.UnknownPropertyException e) {
160 log.println("some properties seem to be unknown: " + e.toString());
163 if (!result) {
164 log.println("The property didn't change its state to default ...");
165 if (mayBeDef) {
166 log.println(" ... and it may be default - FAILED");
167 } else {
168 log.println(" ... but it may not be default - OK");
169 result = true;
173 tRes.tested("setPropertiesToDefault()", result) ;
177 * Test calls the method and checks return value.
178 * Has <b> OK </b> status if the all Properties
179 * have default state afterwards. <p>
181 public void _setAllPropertiesToDefault() {
182 requiredMethod("setPropertiesToDefault()");
183 boolean result = true;
185 try {
186 oObj.setAllPropertiesToDefault();
187 } catch(RuntimeException e) {
188 log.println("Ignore Runtime Exception: " + e.getMessage());
190 log.println("Checking that all properties are now in DEFAULT state" +
191 " excepting may be those which 'can't be default'");
193 try {
194 states = oObj.getPropertyStates(names);
195 for (int i = 0; i < states.length; i++) {
196 boolean part_result = states[i].equals
197 (PropertyState.DEFAULT_VALUE);
198 if (!part_result) {
199 log.println("Property '" + names[i] +
200 "' wasn't set to default");
201 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
202 XPropertySetInfo xPropSetInfo =
203 xPropSet.getPropertySetInfo();
204 Property prop = xPropSetInfo.getPropertyByName(names[i]);
205 if ( (prop.Attributes &
206 PropertyAttribute.MAYBEDEFAULT) != 0 ) {
207 log.println(" ... and it has MAYBEDEFAULT "+
208 "attribute - FAILED");
209 } else {
210 log.println(" ... but it has no MAYBEDEFAULT "+
211 "attribute - OK");
212 part_result = true;
216 result &= part_result;
218 } catch (com.sun.star.beans.UnknownPropertyException e) {
219 log.println("some properties seem to be unknown: " + e.toString());
220 result=false;
223 tRes.tested("setAllPropertiesToDefault()", result) ;