fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / qa / complex / dataPilot / _XPropertySet.java
blobc30e17417e6e71ed69fccfc2536bdbef218a055f
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 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;
35 import util.utils;
37 /**
38 * Testing <code>com.sun.star.beans.XPropertySet</code>
39 * interface methods :
40 * <ul>
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>
48 * </ul>
49 * @see com.sun.star.beans.XPropertySet
51 public class _XPropertySet {
53 /**
54 * The object that is testsed.
56 private XPropertySet oObj = null;
58 /**
59 * The test parameters
61 private TestParameters param = null;
63 /**
64 * The log writer
66 // private LogWriter log = null;
68 /**
69 * Flag that indicates change listener was called.
71 boolean propertyChanged = false;
74 /**
75 * The own property change listener
77 XPropertyChangeListener PClistener = new MyChangeListener();
79 /**
80 * Listener that must be called on bound property changing.
82 public class MyChangeListener implements XPropertyChangeListener {
83 /**
84 * Just set <code>propertyChanged</code> flag to true.
86 public void propertyChange(PropertyChangeEvent e) {
87 propertyChanged = true;
89 public void disposing (EventObject obj) {}
93 /**
94 * Flag that indicates veto listener was called.
96 boolean vetoableChanged = false;
98 /**
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) {}
118 * Properties to test
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;
128 String bound = 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) {
139 oObj = xObj;
140 // this.log = log;
141 this.param = 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");
162 PTT.normal=ptt[0];
163 PTT.bound=ptt[1];
164 PTT.constrained=ptt[2];
165 } else {
166 getPropsToTest(propertySetInfo);
169 return true;
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 :
178 * <ul>
179 * <li> <code>getPropertySetInfo</code> : in this method test
180 * one of bound properties is retrieved. </li>
181 * </ul> <p>
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 ***");
192 } else {
193 try {
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+"'");
201 e.printStackTrace();
202 } catch (com.sun.star.lang.IllegalArgumentException e) {
203 System.out.println("Exception occured while trying to change "+
204 "property '"+ PTT.bound+"'");
205 e.printStackTrace();
206 } catch (com.sun.star.beans.UnknownPropertyException e) {
207 System.out.println("Exception occured while trying to change "+
208 "property '"+ PTT.bound+"'");
209 e.printStackTrace();
210 } catch (com.sun.star.lang.WrappedTargetException e) {
211 System.out.println("Exception occured while trying to change "+
212 "property '"+ PTT.bound+"'");
213 e.printStackTrace();
214 } // end of try-catch
215 result = propertyChanged;
216 if (!propertyChanged) {
217 System.out.println("propertyChangeListener wasn't called for '"+
218 PTT.bound+"'");
220 } //endif
222 return result;
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 :
231 * <ul>
232 * <li> <code>getPropertySetInfo</code> : in this method test
233 * one of constrained properties is retrieved. </li>
234 * </ul> <p>
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 ***");
247 } else {
248 try {
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+"'");
256 e.printStackTrace();
257 } catch (com.sun.star.lang.IllegalArgumentException e) {
258 System.out.println("Exception occured while trying to change "+
259 "property '"+ PTT.constrained+"'");
260 e.printStackTrace();
261 } catch (com.sun.star.beans.UnknownPropertyException e) {
262 System.out.println("Exception occured while trying to change "+
263 "property '"+ PTT.constrained+"'");
264 e.printStackTrace();
265 } catch (com.sun.star.lang.WrappedTargetException e) {
266 System.out.println("Exception occured while trying to change "+
267 "property '"+ PTT.constrained+"'");
268 e.printStackTrace();
269 } // end of try-catch
270 result = vetoableChanged;
271 if (!vetoableChanged) {
272 System.out.println("vetoableChangeListener wasn't called for '"+
273 PTT.constrained+"'");
275 } //endif
277 return result;
279 } // end of addVetoableChangeListener()
283 * Tests <code>setPropertyValue</code> method.
284 * Stores value before call, and compares it with value after
285 * call. <p>
286 * Method tests to be successfully completed before :
287 * <ul>
288 * <li> <code>getPropertySetInfo</code> : in this method test
289 * one of normal properties is retrieved. </li>
290 * </ul> <p>
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 ***");
305 } else {
306 try {
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+"'");
314 e.printStackTrace();
315 } catch (com.sun.star.lang.IllegalArgumentException e) {
316 System.out.println("Exception occured while trying to change "+
317 "property '"+ PTT.normal+"'");
318 e.printStackTrace();
319 } catch (com.sun.star.beans.UnknownPropertyException e) {
320 System.out.println("Exception occured while trying to change "+
321 "property '"+ PTT.normal+"'");
322 e.printStackTrace();
323 } catch (com.sun.star.lang.WrappedTargetException e) {
324 System.out.println("Exception occured while trying to change "+
325 "property '"+ PTT.normal+"'");
326 e.printStackTrace();
327 } // end of try-catch
328 result = !gValue.equals(sValue);
329 } //endif
331 return result;
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 :
339 * <ul>
340 * <li> <code>getPropertySetInfo</code> : in this method test
341 * one of normal properties is retrieved. </li>
342 * </ul> <p>
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);
359 try {
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 '"+
363 PTT.normal+"'");
364 e.printStackTrace();
365 result = false;
366 } catch (com.sun.star.lang.WrappedTargetException e) {
367 System.out.println("Exception occured while trying to get property '"+
368 PTT.normal+"'");
369 e.printStackTrace();
370 result = false;
371 } // end of try-catch
373 return result;
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 :
381 * <ul>
382 * <li> <code>addPropertyChangeListener</code> : here listener
383 * was added. </li>
384 * </ul> <p>
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 ***");
397 } else {
398 try {
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+"'");
407 e.printStackTrace();
408 } catch (com.sun.star.lang.IllegalArgumentException e) {
409 System.out.println("Exception occured while trying to change "+
410 "property '"+ PTT.bound+"'");
411 e.printStackTrace();
412 } catch (com.sun.star.beans.UnknownPropertyException e) {
413 System.out.println("Exception occured while trying to change "+
414 "property '"+ PTT.bound+"'");
415 e.printStackTrace();
416 } catch (com.sun.star.lang.WrappedTargetException e) {
417 System.out.println("Exception occured while trying to change "+
418 "property '"+ PTT.bound+"'");
419 e.printStackTrace();
420 } // end of try-catch
422 result = !propertyChanged;
423 if (propertyChanged) {
424 System.out.println("propertyChangeListener was called after removing"+
425 " for '"+PTT.bound+"'");
427 } //endif
429 return result;
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 :
439 * <ul>
440 * <li> <code>addPropertyChangeListener</code> : here vetoable listener
441 * was added. </li>
442 * </ul> <p>
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 ***");
455 } else {
456 try {
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+"'");
464 e.printStackTrace();
465 } catch (com.sun.star.lang.IllegalArgumentException e) {
466 System.out.println("Exception occured while trying to change "+
467 "property '"+ PTT.constrained+"'");
468 e.printStackTrace();
469 } catch (com.sun.star.beans.UnknownPropertyException e) {
470 System.out.println("Exception occured while trying to change "+
471 "property '"+ PTT.constrained+"'");
472 e.printStackTrace();
473 } catch (com.sun.star.lang.WrappedTargetException e) {
474 System.out.println("Exception occured while trying to change "+
475 "property '"+ PTT.constrained+"'");
476 e.printStackTrace();
477 } // end of try-catch
479 result = !vetoableChanged;
480 if (vetoableChanged) {
481 System.out.println("vetoableChangeListener was called after "+
482 "removing for '"+PTT.constrained+"'");
484 } //endif
486 return result;
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();
498 String bound = "";
499 String constrained = "";
500 String normal = "";
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) {
532 bound+=name+";";
535 if ( isWritable && isNotNull && isConstr && canChange) {
536 constrained+=name+";";
539 if ( isWritable && isNotNull && canChange) normal+=name+";";
542 } // endfor
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);
555 return PTT;
560 * Retrieves one random property name from list (property names separated
561 * by ';') of property names.
563 public String getRandomString(String str) {
565 String gRS = "none";
566 Random rnd = new Random();
568 if (str.equals("")) str = "none";
569 StringTokenizer ST=new StringTokenizer(str,";");
570 int nr = rnd.nextInt(ST.countTokens());
571 if (nr < 1) nr+=1;
572 for (int i=1; i<nr+1; i++) gRS = ST.nextToken();
574 return gRS;
578 public boolean isChangeable(String name) {
579 boolean hasChanged = false;
580 try {
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 + "'");
599 e.printStackTrace();
600 } catch (com.sun.star.lang.IllegalArgumentException e) {
601 System.out.println("'" + name + "' throws exception '" + e + "'");
602 e.printStackTrace();
603 } catch (com.sun.star.beans.UnknownPropertyException e) {
604 System.out.println("'" + name + "' throws exception '" + e + "'");
605 e.printStackTrace();
606 } catch (com.sun.star.lang.WrappedTargetException e) {
607 System.out.println("'" + name + "' throws exception '" + e + "'");
608 e.printStackTrace();
609 } catch (com.sun.star.uno.RuntimeException e) {
610 System.out.println("'" + name + "' throws exception '" + e + "'");
611 e.printStackTrace();
612 } catch (java.lang.ArrayIndexOutOfBoundsException e) {
613 System.out.println("'" + name + "' throws exception '" + e + "'");
614 e.printStackTrace();
617 return hasChanged;
621 } // finish class _XPropertySet