1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMultiPropertyStates.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.beans
.Property
;
38 import com
.sun
.star
.beans
.PropertyAttribute
;
39 import com
.sun
.star
.beans
.PropertyState
;
40 import com
.sun
.star
.beans
.XMultiPropertyStates
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.beans
.XPropertySetInfo
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
46 * Testing <code>com.sun.star.beans.XMultiPropertyStates</code>
49 * <li><code> getPropertyStates()</code></li>
50 * <li><code> setAllPropertiesToDefault()</code></li>
51 * <li><code> getPropertyValues()</code></li>
52 * <li><code> setPropertiesToDefault()</code></li>
53 * <li><code> getPropertyDefaults()</code></li>
55 * @see com.sun.star.beans.XMultiPropertyStates
57 public class _XMultiPropertyStates
extends MultiMethodTest
{
59 public XMultiPropertyStates oObj
= null;
61 Object
[] defaults
= null;
62 PropertyState
[] states
= null;
63 String
[] names
= null;
65 public void before() {
66 names
= (String
[]) tEnv
.getObjRelation("PropertyNames");
68 throw new StatusException(Status
.failed("No PropertyNames given"));
71 log
.println("Totally " + names
.length
+ " properties encountered:");
73 for (int i
= 0; i
< names
.length
; i
++)
74 log
.print(names
[i
] + " ");
81 * Test calls the method and checks return value.
82 * <code>PropertyDefaults</code> are stored<p>
83 * Has <b> OK </b> status if the method returns not null value
84 * and no exceptions were thrown. <p>
86 public void _getPropertyDefaults() {
87 boolean result
= false;
89 defaults
= oObj
.getPropertyDefaults(names
);
90 result
= (defaults
!= null) && defaults
.length
== names
.length
;
91 log
.println("Number of default values: " + defaults
.length
);
92 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
93 log
.println("some properties seem to be unknown: " + e
.toString());
94 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
95 log
.println("Wrapped target Exception was thrown: " + e
.toString());
97 tRes
.tested("getPropertyDefaults()", result
) ;
101 * Test calls the method and checks return value.
102 * Has <b> OK </b> status if the method returns not null value
103 * and no exceptions were thrown. <p>
105 public void _getPropertyStates() {
106 boolean result
= false;
108 states
= oObj
.getPropertyStates(names
);
109 result
= (states
!= null) && (states
.length
== names
.length
);
110 log
.println("Number of states: " + states
.length
);
111 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
112 log
.println("some properties seem to be unknown: " + e
.toString());
114 tRes
.tested("getPropertyStates()", result
) ;
118 * Test calls the method and checks return value.
119 * Has <b> OK </b> status if the Property
120 * has default state afterwards. <p>
122 public void _setPropertiesToDefault() {
123 requiredMethod("getPropertyStates()");
124 // searching for property which currently don't have default value
125 // and preferable has MAYBEDEFAULT attr
126 // if no such properties are found then the first one is selected
128 String ro
= (String
) tEnv
.getObjRelation("allReadOnly");
131 tRes
.tested("setPropertiesToDefault()",Status
.skipped(true));
135 boolean mayBeDef
= false;
136 String propName
= names
[0];
138 for(int i
= 0; i
< names
.length
; i
++) {
139 if (!mayBeDef
&& states
[i
] != PropertyState
.DEFAULT_VALUE
) {
141 XPropertySet xPropSet
= (XPropertySet
)
142 UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
143 XPropertySetInfo xPropSetInfo
= xPropSet
.getPropertySetInfo();
144 Property prop
= null;
146 prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
148 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
149 log
.println("couldn't get property info: " + e
.toString());
150 throw new StatusException(Status
.failed
151 ("couldn't get property info"));
153 if ( (prop
.Attributes
& PropertyAttribute
.MAYBEDEFAULT
) != 0){
154 log
.println("Property " + names
[i
] +
155 " 'may be default' and doesn't have default value");
160 log
.println("The property " + propName
+ " selected");
162 boolean result
= false;
164 String
[] the_first
= new String
[1];
165 the_first
[0] = propName
;
166 log
.println("Setting " + propName
+ " to default");
167 oObj
.setPropertiesToDefault(the_first
);
168 result
= (oObj
.getPropertyStates(the_first
)[0].equals
169 (PropertyState
.DEFAULT_VALUE
));
170 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
171 log
.println("some properties seem to be unknown: " + e
.toString());
175 log
.println("The property didn't change its state to default ...");
177 log
.println(" ... and it may be default - FAILED");
179 log
.println(" ... but it may not be default - OK");
184 tRes
.tested("setPropertiesToDefault()", result
) ;
188 * Test calls the method and checks return value.
189 * Has <b> OK </b> status if the all Properties
190 * have default state afterwards. <p>
192 public void _setAllPropertiesToDefault() {
193 requiredMethod("setPropertiesToDefault()");
194 boolean result
= true;
197 oObj
.setAllPropertiesToDefault();
198 } catch(RuntimeException e
) {
199 log
.println("Ignore Runtime Exception: " + e
.getMessage());
201 log
.println("Checking that all properties are now in DEFAULT state" +
202 " excepting may be those which 'cann't be default'");
205 states
= oObj
.getPropertyStates(names
);
206 for (int i
= 0; i
< states
.length
; i
++) {
207 boolean part_result
= states
[i
].equals
208 (PropertyState
.DEFAULT_VALUE
);
210 log
.println("Property '" + names
[i
] +
211 "' wasn't set to default");
212 XPropertySet xPropSet
= (XPropertySet
)
213 UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
214 XPropertySetInfo xPropSetInfo
=
215 xPropSet
.getPropertySetInfo();
216 Property prop
= xPropSetInfo
.getPropertyByName(names
[i
]);
217 if ( (prop
.Attributes
&
218 PropertyAttribute
.MAYBEDEFAULT
) != 0 ) {
219 log
.println(" ... and it has MAYBEDEFAULT "+
220 "attribute - FAILED");
222 log
.println(" ... but it has no MAYBEDEFAULT "+
228 result
&= part_result
;
230 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
231 log
.println("some properties seem to be unknown: " + e
.toString());
235 tRes
.tested("setAllPropertiesToDefault()", result
) ;