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 .
21 import lib
.MultiMethodTest
;
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
;
34 * Testing <code>com.sun.star.beans.XMultiPropertyStates</code>
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>
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;
53 public void before() {
54 names
= (String
[]) tEnv
.getObjRelation("PropertyNames");
56 throw new StatusException(Status
.failed("No PropertyNames given"));
59 log
.println("Totally " + names
.length
+ " properties encountered:");
61 for (int i
= 0; i
< names
.length
; i
++)
62 log
.print(names
[i
] + " ");
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;
77 Object
[] defaults
= oObj
.getPropertyDefaults(names
);
78 result
= (defaults
!= null) && defaults
.length
== names
.length
;
79 log
.println("Number of default values: " + defaults
.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
) ;
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;
96 states
= oObj
.getPropertyStates(names
);
97 result
= (states
!= null) && (states
.length
== names
.length
);
98 log
.println("Number of states: " + states
.length
);
99 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
100 log
.println("some properties seem to be unknown: " + e
.toString());
102 tRes
.tested("getPropertyStates()", result
) ;
106 * Test calls the method and checks return value.
107 * Has <b> OK </b> status if the Property
108 * has default state afterwards. <p>
110 public void _setPropertiesToDefault() {
111 requiredMethod("getPropertyStates()");
112 // searching for property which currently don't have default value
113 // and preferable has MAYBEDEFAULT attr
114 // if no such properties are found then the first one is selected
116 String ro
= (String
) tEnv
.getObjRelation("allReadOnly");
119 tRes
.tested("setPropertiesToDefault()",Status
.skipped(true));
123 boolean mayBeDef
= false;
124 String propName
= names
[0];
126 for(int i
= 0; i
< names
.length
; i
++) {
127 if (!mayBeDef
&& states
[i
] != PropertyState
.DEFAULT_VALUE
) {
129 XPropertySet xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
130 XPropertySetInfo xPropSetInfo
= xPropSet
.getPropertySetInfo();
131 Property prop
= null;
133 prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
135 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
136 throw new StatusException(e
, Status
.failed("couldn't get property info"));
138 if ( (prop
.Attributes
& PropertyAttribute
.MAYBEDEFAULT
) != 0){
139 log
.println("Property " + names
[i
] +
140 " 'may be default' and doesn't have default value");
145 log
.println("The property " + propName
+ " selected");
147 boolean result
= false;
149 String
[] the_first
= new String
[1];
150 the_first
[0] = propName
;
151 log
.println("Setting " + propName
+ " to default");
152 oObj
.setPropertiesToDefault(the_first
);
153 result
= (oObj
.getPropertyStates(the_first
)[0].equals
154 (PropertyState
.DEFAULT_VALUE
));
155 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
156 log
.println("some properties seem to be unknown: " + e
.toString());
160 log
.println("The property didn't change its state to default ...");
162 log
.println(" ... and it may be default - FAILED");
164 log
.println(" ... but it may not be default - OK");
169 tRes
.tested("setPropertiesToDefault()", result
) ;
173 * Test calls the method and checks return value.
174 * Has <b> OK </b> status if the all Properties
175 * have default state afterwards. <p>
177 public void _setAllPropertiesToDefault() {
178 requiredMethod("setPropertiesToDefault()");
179 boolean result
= true;
182 oObj
.setAllPropertiesToDefault();
183 } catch(RuntimeException e
) {
184 log
.println("Ignore Runtime Exception: " + e
.getMessage());
186 log
.println("Checking that all properties are now in DEFAULT state" +
187 " excepting may be those which 'cann't be default'");
190 states
= oObj
.getPropertyStates(names
);
191 for (int i
= 0; i
< states
.length
; i
++) {
192 boolean part_result
= states
[i
].equals
193 (PropertyState
.DEFAULT_VALUE
);
195 log
.println("Property '" + names
[i
] +
196 "' wasn't set to default");
197 XPropertySet xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
198 XPropertySetInfo xPropSetInfo
=
199 xPropSet
.getPropertySetInfo();
200 Property prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
201 if ( (prop
.Attributes
&
202 PropertyAttribute
.MAYBEDEFAULT
) != 0 ) {
203 log
.println(" ... and it has MAYBEDEFAULT "+
204 "attribute - FAILED");
206 log
.println(" ... but it has no MAYBEDEFAULT "+
212 result
&= part_result
;
214 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
215 log
.println("some properties seem to be unknown: " + e
.toString());
219 tRes
.tested("setAllPropertiesToDefault()", result
) ;