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 complex
.dataPilot
;
21 import com
.sun
.star
.beans
.Property
;
22 import com
.sun
.star
.beans
.PropertyAttribute
;
23 import com
.sun
.star
.beans
.PropertyChangeEvent
;
24 import com
.sun
.star
.beans
.XPropertyChangeListener
;
25 import com
.sun
.star
.beans
.XPropertySet
;
26 import com
.sun
.star
.beans
.XPropertySetInfo
;
27 import com
.sun
.star
.beans
.XVetoableChangeListener
;
28 import com
.sun
.star
.lang
.EventObject
;
29 import java
.util
.Random
;
30 import java
.util
.StringTokenizer
;
31 import lib
.TestParameters
;
32 // import share.LogWriter;
33 //import lib.MultiMethodTest;
34 import util
.ValueChanger
;
38 * Testing <code>com.sun.star.beans.XPropertySet</code>
41 * <li><code>getPropertySetInfo()</code></li>
42 * <li><code>setPropertyValue()</code></li>
43 * <li><code>getPropertyValue()</code></li>
44 * <li><code>addPropertyChangeListener()</code></li>
45 * <li><code>removePropertyChangeListener()</code></li>
46 * <li><code>addVetoableChangeListener()</code></li>
47 * <li><code>removeVetoableChangeListener()</code></li>
49 * @see com.sun.star.beans.XPropertySet
51 public class _XPropertySet
{
54 * The object that is testsed.
56 private XPropertySet oObj
= null;
61 private TestParameters param
= null;
66 // private LogWriter log = null;
69 * Flag that indicates change listener was called.
71 boolean propertyChanged
= false;
75 * The own property change listener
77 XPropertyChangeListener PClistener
= new MyChangeListener();
80 * Listener that must be called on bound property changing.
82 public class MyChangeListener
implements XPropertyChangeListener
{
84 * Just set <code>propertyChanged</code> flag to true.
86 public void propertyChange(PropertyChangeEvent e
) {
87 propertyChanged
= true;
89 public void disposing (EventObject obj
) {}
94 * Flag that indicates veto listener was called.
96 boolean vetoableChanged
= false;
99 * The own vetoable change listener
101 XVetoableChangeListener VClistener
= new MyVetoListener();
104 * Listener that must be called on constrained property changing.
106 public class MyVetoListener
implements XVetoableChangeListener
{
108 * Just set <code>vetoableChanged</code> flag to true.
110 public void vetoableChange(PropertyChangeEvent e
) {
111 vetoableChanged
= true;
113 public void disposing (EventObject obj
) {}
120 PropsToTest PTT
= new PropsToTest();
123 * Structure that collects three properties of each type to test :
124 * Constrained, Bound and Normal.
126 public class PropsToTest
{
127 String constrained
= null;
129 String normal
= null;
133 * Constructor: gets the object to test, a logger and the test parameters
134 * @param xObj The test object
135 * @param log A log writer
136 * @param param The test parameters
138 public _XPropertySet(XPropertySet xObj
/*, LogWriter log*/, TestParameters param
) {
145 * Tests method <code>getPropertySetInfo</code>. After test completed
146 * call {@link #getPropsToTest} method to retrieve different kinds
147 * of properties to test then. <p>
148 * Has OK status if not null <code>XPropertySetInfo</code>
149 * object returned.<p>
150 * Since <code>getPropertySetInfo</code> is optional, it may return null,
151 * if it is not implemented. This method uses then an object relation
152 * <code>PTT</code> (Properties To Test) to determine available properties.
153 * All tests for services without <code>getPropertySetInfo</code> must
154 * provide this object relation.
156 public boolean _getPropertySetInfo() {
157 XPropertySetInfo propertySetInfo
= oObj
.getPropertySetInfo();
159 if (propertySetInfo
== null) {
160 System
.out
.println("getPropertySetInfo() method returned null");
161 String
[] ptt
= (String
[]) param
.get("PTT");
164 PTT
.constrained
=ptt
[2];
166 getPropsToTest(propertySetInfo
);
171 } // end of getPropertySetInfo()
174 * Tests change listener which added for bound properties.
175 * Adds listener to bound property (if it exists), then changes
176 * its value and check if listener was called. <p>
177 * Method tests to be successfully completed before :
179 * <li> <code>getPropertySetInfo</code> : in this method test
180 * one of bound properties is retrieved. </li>
182 * Has OK status if NO bound properties exist or if listener
183 * was successfully called.
185 public boolean _addPropertyChangeListener() {
187 propertyChanged
= false;
188 boolean result
= true;
190 if ( PTT
.bound
.equals("none") ) {
191 System
.out
.println("*** No bound properties found ***");
194 oObj
.addPropertyChangeListener(PTT
.bound
,PClistener
);
195 Object gValue
= oObj
.getPropertyValue(PTT
.bound
);
196 oObj
.setPropertyValue(PTT
.bound
,
197 ValueChanger
.changePValue(gValue
));
198 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
199 System
.out
.println("Exception occured while trying to change "+
200 "property '"+ PTT
.bound
+"'");
202 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
203 System
.out
.println("Exception occured while trying to change "+
204 "property '"+ PTT
.bound
+"'");
206 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
207 System
.out
.println("Exception occured while trying to change "+
208 "property '"+ PTT
.bound
+"'");
210 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
211 System
.out
.println("Exception occured while trying to change "+
212 "property '"+ PTT
.bound
+"'");
214 } // end of try-catch
215 result
= propertyChanged
;
216 if (!propertyChanged
) {
217 System
.out
.println("propertyChangeListener wasn't called for '"+
224 } // end of addPropertyChangeListener()
227 * Tests vetoable listener which added for constrained properties.
228 * Adds listener to constrained property (if it exists), then changes
229 * its value and check if listener was called. <p>
230 * Method tests to be successfully completed before :
232 * <li> <code>getPropertySetInfo</code> : in this method test
233 * one of constrained properties is retrieved. </li>
235 * Has OK status if NO constrained properties exist or if listener
236 * was successfully called.
238 public boolean _addVetoableChangeListener() {
240 // requiredMethod("getPropertySetInfo()");
242 vetoableChanged
= false;
243 boolean result
= true;
245 if ( PTT
.constrained
.equals("none") ) {
246 System
.out
.println("*** No constrained properties found ***");
249 oObj
.addVetoableChangeListener(PTT
.constrained
,VClistener
);
250 Object gValue
= oObj
.getPropertyValue(PTT
.constrained
);
251 oObj
.setPropertyValue(PTT
.constrained
,
252 ValueChanger
.changePValue(gValue
));
253 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
254 System
.out
.println("Exception occured while trying to change "+
255 "property '"+ PTT
.constrained
+"'");
257 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
258 System
.out
.println("Exception occured while trying to change "+
259 "property '"+ PTT
.constrained
+"'");
261 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
262 System
.out
.println("Exception occured while trying to change "+
263 "property '"+ PTT
.constrained
+"'");
265 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
266 System
.out
.println("Exception occured while trying to change "+
267 "property '"+ PTT
.constrained
+"'");
269 } // end of try-catch
270 result
= vetoableChanged
;
271 if (!vetoableChanged
) {
272 System
.out
.println("vetoableChangeListener wasn't called for '"+
273 PTT
.constrained
+"'");
279 } // end of addVetoableChangeListener()
283 * Tests <code>setPropertyValue</code> method.
284 * Stores value before call, and compares it with value after
286 * Method tests to be successfully completed before :
288 * <li> <code>getPropertySetInfo</code> : in this method test
289 * one of normal properties is retrieved. </li>
291 * Has OK status if NO normal properties exist or if value before
292 * method call is not equal to value after.
294 public boolean _setPropertyValue() {
296 // requiredMethod("getPropertySetInfo()");
298 Object gValue
= null;
299 Object sValue
= null;
301 boolean result
= true;
303 if ( PTT
.normal
.equals("none") ) {
304 System
.out
.println("*** No changeable properties found ***");
307 gValue
= oObj
.getPropertyValue(PTT
.normal
);
308 sValue
= ValueChanger
.changePValue(gValue
);
309 oObj
.setPropertyValue(PTT
.normal
, sValue
);
310 sValue
= oObj
.getPropertyValue(PTT
.normal
);
311 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
312 System
.out
.println("Exception occured while trying to change "+
313 "property '"+ PTT
.normal
+"'");
315 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
316 System
.out
.println("Exception occured while trying to change "+
317 "property '"+ PTT
.normal
+"'");
319 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
320 System
.out
.println("Exception occured while trying to change "+
321 "property '"+ PTT
.normal
+"'");
323 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
324 System
.out
.println("Exception occured while trying to change "+
325 "property '"+ PTT
.normal
+"'");
327 } // end of try-catch
328 result
= !gValue
.equals(sValue
);
333 } // end of setPropertyValue()
336 * Tests <code>getPropertyValue</code> method.
337 * Just call this method and checks for no exceptions <p>
338 * Method tests to be successfully completed before :
340 * <li> <code>getPropertySetInfo</code> : in this method test
341 * one of normal properties is retrieved. </li>
343 * Has OK status if NO normal properties exist or if no
344 * exceptions were thrown.
346 public boolean _getPropertyValue() {
348 // requiredMethod("getPropertySetInfo()");
350 boolean result
= true;
351 String toCheck
= PTT
.normal
;
353 if ( PTT
.normal
.equals("none") ) {
354 toCheck
= oObj
.getPropertySetInfo().getProperties()[0].Name
;
355 System
.out
.println("All properties are Read Only");
356 System
.out
.println("Using: "+toCheck
);
360 Object gValue
= oObj
.getPropertyValue(toCheck
);
361 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
362 System
.out
.println("Exception occured while trying to get property '"+
366 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
367 System
.out
.println("Exception occured while trying to get property '"+
371 } // end of try-catch
377 * Tests <code>removePropertyChangeListener</code> method.
378 * Removes change listener, then changes bound property value
379 * and checks if the listener was NOT called.
380 * Method tests to be successfully completed before :
382 * <li> <code>addPropertyChangeListener</code> : here listener
385 * Has OK status if NO bound properties exist or if listener
386 * was not called and no exceptions arose.
388 public boolean _removePropertyChangeListener() {
390 // requiredMethod("addPropertyChangeListener()");
392 propertyChanged
= false;
393 boolean result
= true;
395 if ( PTT
.bound
.equals("none") ) {
396 System
.out
.println("*** No bound properties found ***");
399 propertyChanged
= false;
400 oObj
.removePropertyChangeListener(PTT
.bound
,PClistener
);
401 Object gValue
= oObj
.getPropertyValue(PTT
.bound
);
402 oObj
.setPropertyValue(PTT
.bound
,
403 ValueChanger
.changePValue(gValue
));
404 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
405 System
.out
.println("Exception occured while trying to change "+
406 "property '"+ PTT
.bound
+"'");
408 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
409 System
.out
.println("Exception occured while trying to change "+
410 "property '"+ PTT
.bound
+"'");
412 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
413 System
.out
.println("Exception occured while trying to change "+
414 "property '"+ PTT
.bound
+"'");
416 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
417 System
.out
.println("Exception occured while trying to change "+
418 "property '"+ PTT
.bound
+"'");
420 } // end of try-catch
422 result
= !propertyChanged
;
423 if (propertyChanged
) {
424 System
.out
.println("propertyChangeListener was called after removing"+
425 " for '"+PTT
.bound
+"'");
431 } // end of removePropertyChangeListener()
435 * Tests <code>removeVetoableChangeListener</code> method.
436 * Removes vetoable listener, then changes constrained property value
437 * and checks if the listener was NOT called.
438 * Method tests to be successfully completed before :
440 * <li> <code>addPropertyChangeListener</code> : here vetoable listener
443 * Has OK status if NO constrained properties exist or if listener
444 * was NOT called and no exceptions arose.
446 public boolean _removeVetoableChangeListener() {
448 // requiredMethod("addVetoableChangeListener()");
450 vetoableChanged
= false;
451 boolean result
= true;
453 if ( PTT
.constrained
.equals("none") ) {
454 System
.out
.println("*** No constrained properties found ***");
457 oObj
.removeVetoableChangeListener(PTT
.constrained
,VClistener
);
458 Object gValue
= oObj
.getPropertyValue(PTT
.constrained
);
459 oObj
.setPropertyValue(PTT
.constrained
,
460 ValueChanger
.changePValue(gValue
));
461 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
462 System
.out
.println("Exception occured while trying to change "+
463 "property '"+ PTT
.constrained
+"'");
465 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
466 System
.out
.println("Exception occured while trying to change "+
467 "property '"+ PTT
.constrained
+"'");
469 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
470 System
.out
.println("Exception occured while trying to change "+
471 "property '"+ PTT
.constrained
+"'");
473 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
474 System
.out
.println("Exception occured while trying to change "+
475 "property '"+ PTT
.constrained
+"'");
477 } // end of try-catch
479 result
= !vetoableChanged
;
480 if (vetoableChanged
) {
481 System
.out
.println("vetoableChangeListener was called after "+
482 "removing for '"+PTT
.constrained
+"'");
488 } // end of removeVetoableChangeListener()
492 * Gets the properties being tested. Searches and stores by one
493 * property of each kind (Bound, Vetoable, Normal).
495 public PropsToTest
getPropsToTest(XPropertySetInfo xPSI
) {
497 Property
[] properties
= xPSI
.getProperties();
499 String constrained
= "";
502 for (int i
= 0; i
< properties
.length
; i
++) {
504 Property property
= properties
[i
];
505 String name
= property
.Name
;
506 System
.out
.println("Checking '"+name
+"'");
507 boolean isWritable
= ((property
.Attributes
&
508 PropertyAttribute
.READONLY
) == 0);
509 boolean isNotNull
= ((property
.Attributes
&
510 PropertyAttribute
.MAYBEVOID
) == 0);
511 boolean isBound
= ((property
.Attributes
&
512 PropertyAttribute
.BOUND
) != 0);
513 boolean isConstr
= ((property
.Attributes
&
514 PropertyAttribute
.CONSTRAINED
) != 0);
515 boolean canChange
= false;
517 if ( !isWritable
) System
.out
.println("Property '"+name
+"' is READONLY");
519 if (name
.endsWith("URL")) isWritable
= false;
520 if (name
.startsWith("Fill")) isWritable
= false;
521 if (name
.startsWith("Font")) isWritable
= false;
522 if (name
.startsWith("IsNumbering")) isWritable
= false;
523 if (name
.startsWith("LayerName")) isWritable
= false;
524 if (name
.startsWith("Line")) isWritable
= false;
526 //if (name.equals("xinterfaceA") || name.equals("xtypeproviderA")
527 //|| name.equals("arAnyA")) isWritable=false;
529 if ( isWritable
&& isNotNull
) canChange
= isChangeable(name
);
531 if ( isWritable
&& isNotNull
&& isBound
&& canChange
) {
535 if ( isWritable
&& isNotNull
&& isConstr
&& canChange
) {
536 constrained
+=name
+";";
539 if ( isWritable
&& isNotNull
&& canChange
) normal
+=name
+";";
544 //get a random bound property
545 PTT
.bound
=getRandomString(bound
);
546 System
.out
.println("Bound: "+PTT
.bound
);
548 //get a random constrained property
549 PTT
.constrained
=getRandomString(constrained
);
550 System
.out
.println("Constrained: "+PTT
.constrained
);
552 //get a random normal property
553 PTT
.normal
=getRandomString(normal
);
560 * Retrieves one random property name from list (property names separated
561 * by ';') of property names.
563 public String
getRandomString(String str
) {
566 Random rnd
= new Random();
568 if (str
.equals("")) str
= "none";
569 StringTokenizer ST
=new StringTokenizer(str
,";");
570 int nr
= rnd
.nextInt(ST
.countTokens());
572 for (int i
=1; i
<nr
+1; i
++) gRS
= ST
.nextToken();
578 public boolean isChangeable(String name
) {
579 boolean hasChanged
= false;
581 Object getProp
= oObj
.getPropertyValue(name
);
582 System
.out
.println("Getting: "+getProp
);
584 Object setValue
= null;
585 if (getProp
!= null) {
586 if (!utils
.isVoid(getProp
))
587 setValue
= ValueChanger
.changePValue(getProp
);
588 else System
.out
.println("Property '"+name
+
589 "' is void but MAYBEVOID isn't set");
590 } else System
.out
.println("Property '"+name
+"'is null and can't be changed");
591 if (name
.equals("LineStyle")) setValue
= null;
592 if (setValue
!= null) {
593 oObj
.setPropertyValue(name
, setValue
);
594 System
.out
.println("Setting to :"+setValue
);
595 hasChanged
= (! getProp
.equals(oObj
.getPropertyValue(name
)));
596 } else System
.out
.println("Couldn't change Property '"+name
+"'");
597 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
598 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
600 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
601 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
603 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
604 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
606 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
607 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
609 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
610 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
612 } catch (java
.lang
.ArrayIndexOutOfBoundsException e
) {
613 System
.out
.println("'" + name
+ "' throws exception '" + e
+ "'");
621 } // finish class _XPropertySet