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;
52 public void before() {
53 names
= (String
[]) tEnv
.getObjRelation("PropertyNames");
55 throw new StatusException(Status
.failed("No PropertyNames given"));
58 log
.println("Totally " + names
.length
+ " properties encountered:");
60 for (int i
= 0; i
< names
.length
; i
++)
61 log
.print(names
[i
] + " ");
68 * Test calls the method and checks return value.
69 * <code>PropertyDefaults</code> are stored<p>
70 * Has <b> OK </b> status if the method returns not null value
71 * and no exceptions were thrown. <p>
73 public void _getPropertyDefaults() {
74 boolean result
= false;
76 Object
[] defaults
= oObj
.getPropertyDefaults(names
);
77 result
= (defaults
!= null) && defaults
.length
== names
.length
;
78 log
.println("Number of default values: " + defaults
.length
);
79 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
80 log
.println("some properties seem to be unknown: " + e
.toString());
81 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
82 log
.println("Wrapped target Exception was thrown: " + e
.toString());
84 tRes
.tested("getPropertyDefaults()", result
) ;
88 * Test calls the method and checks return value.
89 * Has <b> OK </b> status if the method returns not null value
90 * and no exceptions were thrown. <p>
92 public void _getPropertyStates() {
93 boolean result
= false;
95 states
= oObj
.getPropertyStates(names
);
96 result
= (states
!= null) && (states
.length
== names
.length
);
97 log
.println("Number of states: " + states
.length
);
98 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
99 log
.println("some properties seem to be unknown: " + e
.toString());
101 tRes
.tested("getPropertyStates()", result
) ;
105 * Test calls the method and checks return value.
106 * Has <b> OK </b> status if the Property
107 * has default state afterwards. <p>
109 public void _setPropertiesToDefault() {
110 requiredMethod("getPropertyStates()");
111 // searching for property which currently don't have default value
112 // and preferable has MAYBEDEFAULT attr
113 // if no such properties are found then the first one is selected
115 String ro
= (String
) tEnv
.getObjRelation("allReadOnly");
118 tRes
.tested("setPropertiesToDefault()",Status
.skipped(true));
122 boolean mayBeDef
= false;
123 String propName
= names
[0];
125 for(int i
= 0; i
< names
.length
; i
++) {
126 if (!mayBeDef
&& states
[i
] != PropertyState
.DEFAULT_VALUE
) {
128 XPropertySet xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
129 XPropertySetInfo xPropSetInfo
= xPropSet
.getPropertySetInfo();
130 Property prop
= null;
132 prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
134 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
135 log
.println("couldn't get property info: " + e
.toString());
136 throw new StatusException(Status
.failed
137 ("couldn't get property info"));
139 if ( (prop
.Attributes
& PropertyAttribute
.MAYBEDEFAULT
) != 0){
140 log
.println("Property " + names
[i
] +
141 " 'may be default' and doesn't have default value");
146 log
.println("The property " + propName
+ " selected");
148 boolean result
= false;
150 String
[] the_first
= new String
[1];
151 the_first
[0] = propName
;
152 log
.println("Setting " + propName
+ " to default");
153 oObj
.setPropertiesToDefault(the_first
);
154 result
= (oObj
.getPropertyStates(the_first
)[0].equals
155 (PropertyState
.DEFAULT_VALUE
));
156 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
157 log
.println("some properties seem to be unknown: " + e
.toString());
161 log
.println("The property didn't change its state to default ...");
163 log
.println(" ... and it may be default - FAILED");
165 log
.println(" ... but it may not be default - OK");
170 tRes
.tested("setPropertiesToDefault()", result
) ;
174 * Test calls the method and checks return value.
175 * Has <b> OK </b> status if the all Properties
176 * have default state afterwards. <p>
178 public void _setAllPropertiesToDefault() {
179 requiredMethod("setPropertiesToDefault()");
180 boolean result
= true;
183 oObj
.setAllPropertiesToDefault();
184 } catch(RuntimeException e
) {
185 log
.println("Ignore Runtime Exception: " + e
.getMessage());
187 log
.println("Checking that all properties are now in DEFAULT state" +
188 " excepting may be those which 'cann't be default'");
191 states
= oObj
.getPropertyStates(names
);
192 for (int i
= 0; i
< states
.length
; i
++) {
193 boolean part_result
= states
[i
].equals
194 (PropertyState
.DEFAULT_VALUE
);
196 log
.println("Property '" + names
[i
] +
197 "' wasn't set to default");
198 XPropertySet xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
199 XPropertySetInfo xPropSetInfo
=
200 xPropSet
.getPropertySetInfo();
201 Property prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
202 if ( (prop
.Attributes
&
203 PropertyAttribute
.MAYBEDEFAULT
) != 0 ) {
204 log
.println(" ... and it has MAYBEDEFAULT "+
205 "attribute - FAILED");
207 log
.println(" ... but it has no MAYBEDEFAULT "+
213 result
&= part_result
;
215 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
216 log
.println("some properties seem to be unknown: " + e
.toString());
220 tRes
.tested("setAllPropertiesToDefault()", result
) ;