1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package complex.path_settings; 24 25 import com.sun.star.beans.Property; 26 import com.sun.star.beans.PropertyVetoException; 27 import com.sun.star.beans.UnknownPropertyException; 28 import com.sun.star.beans.XFastPropertySet; 29 import com.sun.star.beans.XMultiPropertySet; 30 import com.sun.star.beans.XPropertySet; 31 import com.sun.star.beans.XPropertiesChangeListener; 32 import com.sun.star.beans.XPropertyChangeListener; 33 import com.sun.star.beans.XVetoableChangeListener; 34 import com.sun.star.lang.WrappedTargetException; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.uno.UnoRuntime; 37 import com.sun.star.uno.AnyConverter; 38 39 // ---------- junit imports ----------------- 40 import java.util.ArrayList; 41 import java.util.StringTokenizer; 42 import java.util.logging.Level; 43 import java.util.logging.Logger; 44 import org.junit.After; 45 import org.junit.AfterClass; 46 import org.junit.Before; 47 import org.junit.BeforeClass; 48 import org.junit.Test; 49 import org.openoffice.test.OfficeConnection; 50 import static org.junit.Assert.*; 51 // ------------------------------------------ 52 53 public class PathSettingsTest 54 { 55 56 private static XMultiServiceFactory xMSF; 57 // the test object: an instance of the tested service 58 private static Object aPathSettings = null; 59 // the properties of the service 60 private static Property[] xPropertyInfoOfPathSettings = null; 61 private static String[] aPathSettingNames = null; 62 private static String[] availablePropNames = new String[] 63 { 64 "Addin", 65 "AutoCorrect", 66 "AutoText", 67 "Backup", 68 "Basic", 69 "Bitmap", 70 "Config", 71 "Dictionary", 72 "Favorite", 73 "Filter", 74 "Fingerprint", 75 "Gallery", 76 "Graphic", 77 "Help", 78 "Linguistic", 79 "Module", 80 "Palette", 81 "Plugin", 82 "Storage", 83 "Temp", 84 "Template", 85 "UIConfig", 86 "UserConfig", 87 "Work", 88 }; 89 // every path name from availablePropNames exist in this characteristics 90 // name 91 // name_internal 92 // name_user 93 // name_writable 94 private static String[] availablePropNameExtensions = new String[] 95 { 96 "", 97 "_internal", 98 "_user", 99 "_writable" 100 }; 101 private static String[] aPathSettingValues = null; 102 ArrayList<Property> aListOfWorkingProperty; 103 104 /** 105 * A function to tell the framework, which test functions are available. 106 * Right now, it's only 'checkComplexTemplateState'. 107 * @return All test methods. 108 */ 109 // public String[] getTestMethodNames() { 110 // return new String[]{"checkXFastPropertySet", 111 // "checkXMultiPropertySet", 112 // "checkXPropertySet" 113 // }; 114 // } 115 /** 116 * Initialize before the tests start: this has to be done only once. 117 * This methods sets the 'aPathSettings' and 'xPropertyInfoOfPathSettings' variables. 118 */ 119 @Before before()120 public void before() 121 { 122 try 123 { 124 xMSF = getMSF(); 125 // aPathSettings = xMSF.createInstance("com.sun.star.util.PathSettings"); 126 aPathSettings = xMSF.createInstance("com.sun.star.comp.framework.PathSettings"); 127 assertNotNull("Can't instantiate com.sun.star.util.PathSettings.", aPathSettings); 128 // System.out.println("Implementation: " + util.utils.getImplName(aPathSettings)); 129 // System.out.println("Service: "); 130 util.dbg.getSuppServices(aPathSettings); 131 final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings); 132 133 xPropertyInfoOfPathSettings = xPropSet_of_PathSettings.getPropertySetInfo().getProperties(); 134 aPathSettingNames = new String[xPropertyInfoOfPathSettings.length]; 135 aPathSettingValues = new String[xPropertyInfoOfPathSettings.length]; 136 137 aListOfWorkingProperty = new ArrayList<Property>(); 138 139 // get intitial values and create new ones 140 for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++) 141 { 142 final String sName = xPropertyInfoOfPathSettings[i].Name; 143 // System.out.println(sName); 144 aPathSettingNames[i] = sName; 145 Object o = xPropSet_of_PathSettings.getPropertyValue(sName); 146 147 String sValue = convertToString(o); 148 aPathSettingValues[i] = sValue; 149 aListOfWorkingProperty.add(xPropertyInfoOfPathSettings[i]); 150 } 151 } 152 catch (com.sun.star.uno.Exception e) 153 { 154 System.out.println(e.getClass().getName()); 155 System.out.println("Message: " + e.getMessage()); 156 // fail("Could not create an instance of the test object."); 157 } 158 catch (Exception e) 159 { 160 fail("What exception?"); 161 } 162 } 163 convertToString(Object o)164 private String convertToString(Object o) 165 { 166 String sValue = ""; 167 try 168 { 169 if (AnyConverter.isString(o)) 170 { 171 sValue = AnyConverter.toString(o); 172 } 173 else if (AnyConverter.isArray(o)) 174 { 175 Object oValueList = AnyConverter.toArray(o); 176 String[] aValueList = (String[]) oValueList; 177 String sValues = ""; 178 for (int j = 0; j < aValueList.length; j++) 179 { 180 if (sValues.length() > 0) 181 { 182 sValues += ";"; 183 } 184 sValues += aValueList[j]; 185 } 186 sValue = sValues; 187 } 188 else 189 { 190 System.out.println("Can't convert Object to String"); 191 } 192 } 193 catch (com.sun.star.uno.Exception e) 194 { 195 /* ignore */ 196 } 197 return sValue; 198 } 199 200 /** 201 * Simple existence test, if this fails, the Lists must update 202 */ 203 @Test checkInternalListConsistence()204 public void checkInternalListConsistence() 205 { 206 // check if all Properties are in the internal test list 207 for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++) 208 { 209 final String sName = xPropertyInfoOfPathSettings[i].Name; 210 boolean bOccur = checkIfNameExistsInList(sName, availablePropNames, availablePropNameExtensions); 211 assertTrue("TEST IS WRONG, Name:='" + sName + "' doesn't exist in internal Test list.", bOccur); 212 } 213 214 // check if all properties in the internal list also exist in real life 215 for (int i = 0; i < availablePropNames.length; i++) 216 { 217 final String aListName = availablePropNames[i]; 218 for (int j = 0; j < availablePropNameExtensions.length; j++) 219 { 220 final String aSubListName = availablePropNameExtensions[j]; 221 final String aName = aListName + aSubListName; 222 boolean bOccur = checkIfNameExistsInList(aName, aPathSettingNames, new String[] 223 { 224 "" 225 } /* list must not empty! */); 226 assertTrue("TEST IS WRONG, Name:='" + aName + "' from the internal test list do not occur in real life path settings.", bOccur); 227 } 228 } 229 } 230 231 /** 232 * Simple O(n^n) check if a given String (_sNameMustOccur) exist in the given list(+SubList) values. 233 * @param _sNameMustOccur 234 * @param _aList 235 * @param _aSubList 236 * @return true, if name occur 237 */ checkIfNameExistsInList(String _sNameMustOccur, String[] _aList, String[] _aSubList)238 private boolean checkIfNameExistsInList(String _sNameMustOccur, String[] _aList, String[] _aSubList) 239 { 240 for (int i = 0; i < _aList.length; i++) 241 { 242 final String aListName = _aList[i]; 243 for (int j = 0; j < _aSubList.length; j++) 244 { 245 final String aSubListName = _aSubList[j]; 246 final String aName = aListName + aSubListName; 247 if (aName.equals(_sNameMustOccur)) 248 { 249 return true; 250 } 251 } 252 } 253 return false; 254 } 255 getPropertyValueAsString(String _sName)256 private String getPropertyValueAsString(String _sName) 257 { 258 final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings); 259 String sValue = ""; 260 { 261 Object o; 262 try 263 { 264 o = xPropSet_of_PathSettings.getPropertyValue(_sName); 265 sValue = convertToString(o); 266 } 267 catch (UnknownPropertyException ex) 268 { 269 } 270 catch (WrappedTargetException ex) 271 { 272 } 273 } 274 return sValue; 275 } 276 277 /** 278 * Shows the path settings 279 * @throws UnknownPropertyException 280 * @throws WrappedTargetException 281 */ 282 @Test showPathSettings()283 public void showPathSettings() throws UnknownPropertyException, WrappedTargetException 284 { 285 System.out.println("\n---- All properties ----"); 286 final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings); 287 288 // for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++) 289 for (int i = 0; i < aListOfWorkingProperty.size(); i++) 290 { 291 final String sName = aListOfWorkingProperty.get(i).Name; 292 // aPathSettingWorkingNames[i] = sName; 293 // System.out.print("PathSettings: Name:="); 294 System.out.print(sName); 295 Object o = xPropSet_of_PathSettings.getPropertyValue(sName); 296 297 // System.out.println("#### Object: '" + o.getClass().getName() + "' - '" + o.toString() + "'"); 298 try 299 { 300 final String sValue = AnyConverter.toString(o); 301 // aPathSettingValues[i] = sValue; 302 // System.out.println("#### String " + sValue); 303 // System.out.println("Property Name: " + sName); 304 // System.out.println("Property Value: " + sValue); 305 // System.out.print(" ==> "); 306 // System.out.print(sValue); 307 } 308 catch (com.sun.star.uno.Exception e) 309 { 310 // System.out.print(" FAILED "); 311 } 312 System.out.println(); 313 } 314 System.out.println("---- Finish showing properties ----\n"); 315 } 316 checkPaths(Object _o, Object _o2)317 private boolean checkPaths(Object _o, Object _o2) 318 { 319 String sLeftPath = ""; 320 String sRightPath = ""; 321 if (AnyConverter.isArray(_o)) 322 { 323 try 324 { 325 Object oValues = AnyConverter.toArray(_o); 326 sLeftPath = convertToString(oValues); 327 } 328 catch (com.sun.star.lang.IllegalArgumentException e) 329 { 330 } 331 } 332 else if (AnyConverter.isString(_o)) 333 { 334 try 335 { 336 sLeftPath = AnyConverter.toString(_o); 337 } 338 catch (com.sun.star.lang.IllegalArgumentException e) 339 { 340 } 341 } 342 343 if (AnyConverter.isArray(_o2)) 344 { 345 try 346 { 347 Object oValues = AnyConverter.toArray(_o2); 348 sRightPath = convertToString(oValues); 349 } 350 catch (com.sun.star.lang.IllegalArgumentException e) 351 { 352 } 353 } 354 else if (AnyConverter.isString(_o2)) 355 { 356 try 357 { 358 sRightPath = AnyConverter.toString(_o2); 359 } 360 catch (com.sun.star.lang.IllegalArgumentException e) 361 { 362 } 363 } 364 return checkPaths(sLeftPath, sRightPath); 365 } 366 367 /** 368 * Check 2 given paths if the _aOtherPath exists in _aPath, _aPath could be a list separated by ';' 369 * @param _aPath 370 * @param _aOtherPath 371 * @return true, if _aOtherPath found 372 */ checkPaths(String _aPath, String _aOtherPath)373 private boolean checkPaths(String _aPath, String _aOtherPath) 374 { 375 if (_aOtherPath.contains(";")) 376 { 377 StringTokenizer aToken = new StringTokenizer(_aOtherPath, ";"); 378 int nCount = 0; 379 int nFound = 0; 380 while (aToken.hasMoreElements()) 381 { 382 String sPath = (String)aToken.nextElement(); 383 nCount ++; 384 if (checkPaths(_aPath, sPath)) 385 { 386 nFound++; 387 } 388 } 389 if (nFound == nCount) 390 { 391 return true; 392 } 393 } 394 else if(_aPath.contains(";")) 395 { 396 StringTokenizer aToken = new StringTokenizer(_aPath, ";"); 397 while (aToken.hasMoreElements()) 398 { 399 String sToken = (String)aToken.nextElement(); 400 if (sToken.equals(_aOtherPath)) 401 { 402 return true; 403 } 404 } 405 return false; 406 } 407 else if (_aPath.equals(_aOtherPath)) 408 { 409 return true; 410 } 411 return false; 412 } 413 414 /** 415 * This tests the XFastPropertySet interface implementation. 416 */ 417 @Test checkXFastPropertySet()418 public void checkXFastPropertySet() 419 { 420 System.out.println("---- Testing the XFastPropertySet interface ----"); 421 422 423 // do for all properties 424 // xPropertyInfoOfPathSettings.length 425 for (int i = 0; i < aListOfWorkingProperty.size(); i++) 426 { 427 final Property property = aListOfWorkingProperty.get(i); // xPropertyInfoOfPathSettings[i]; 428 String name = property.Name; 429 // get property name and initial value 430 System.out.println("Test property with name: " + name); 431 boolean bResult; 432 if (name.endsWith("_writable")) 433 { 434 bResult = checkStringProperty(property); 435 } 436 else if (name.endsWith("_user")) 437 { 438 bResult = checkStringListProperty(property); 439 } 440 else if (name.endsWith("_internal")) 441 { 442 bResult = checkStringListProperty(property); 443 } 444 else 445 { 446 // old path settings 447 bResult = checkStringProperty(property); 448 } 449 System.out.print(" Test of property " + name + " finished"); 450 if (bResult) 451 { 452 System.out.println(" [ok]"); 453 } 454 else 455 { 456 System.out.println(" [FAILED]"); 457 } 458 System.out.println(); 459 } 460 System.out.println("---- Test of XFastPropertySet finished ----\n"); 461 } 462 checkStringListProperty(Property property)463 private boolean checkStringListProperty(Property property) 464 { 465 // creating instances 466 boolean bResult = true; 467 XFastPropertySet xFPS = UnoRuntime.queryInterface(XFastPropertySet.class, aPathSettings); 468 469 String name = property.Name; 470 int handle = property.Handle; 471 472 Object oValue; 473 try 474 { 475 oValue = xFPS.getFastPropertyValue(handle); 476 } 477 catch (UnknownPropertyException ex) 478 { 479 return false; 480 } 481 catch (WrappedTargetException ex) 482 { 483 return false; 484 } 485 486 if (!AnyConverter.isArray(oValue)) 487 { 488 System.out.println(" Internal error, type wrong. PathSetting property with name:" + name + " should be an array."); 489 return false; 490 } 491 492 String val; 493 try 494 { 495 Object oValues = AnyConverter.toArray(oValue); 496 497 498 final String[] aValues = (String[])oValues; 499 500 // aNewValues contains a deep copy of aValues 501 String[] aNewValues = new String[aValues.length]; 502 System.arraycopy(aValues, 0, aNewValues, 0, aValues.length); 503 if (aValues.length > 0) 504 { 505 val = aValues[0]; 506 } 507 else 508 { 509 val = null; 510 aNewValues = new String[1]; // create a String list 511 } 512 System.out.println(" Property has initial value: '" + val + "'"); 513 514 // set to a new correct value 515 String newVal = changeToCorrectValue(val); 516 assertFalse("newVal must not equal val.", newVal.equals(val)); 517 518 System.out.println(" Try to change to a correct value '" + newVal + "'"); 519 aNewValues[0] = newVal; 520 521 try 522 { 523 try 524 { 525 xFPS.setFastPropertyValue(handle, aNewValues); 526 } 527 catch (com.sun.star.lang.WrappedTargetException e) 528 { 529 System.out.println(" FAIL: setFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage()); 530 bResult = false; 531 } 532 533 // Property_internal can't change we will not arrive bejond this line 534 535 // check the change 536 Object oObj = xFPS.getFastPropertyValue(handle); 537 if (!checkPaths(oObj, aNewValues)) 538 { 539 System.out.println(" FAIL: Did not change value on property " + name + "."); 540 bResult = false; 541 } 542 543 // set back to initial setting 544 System.out.println(" Try to check"); 545 try 546 { 547 xFPS.setFastPropertyValue(handle, oValue); 548 } 549 catch (com.sun.star.beans.PropertyVetoException e) 550 { 551 // should not occur 552 System.out.println(" FAIL: PropertyVetoException caught: " + e.getMessage()); 553 bResult = false; 554 } 555 } 556 catch (com.sun.star.beans.PropertyVetoException e) 557 { 558 if (!name.endsWith("_internal")) 559 { 560 // should not occur 561 System.out.println(" FAIL: PropertyVetoException caught: " + e.getMessage()); 562 bResult = false; 563 } 564 else 565 { 566 System.out.println(" OK: PropertyVetoException caught: " + e.getMessage() + " it seems not allowed to change internal values."); 567 } 568 } 569 570 // check if changed 571 Object checkVal3 = xFPS.getFastPropertyValue(handle); 572 if (!checkPaths(checkVal3, oValues)) 573 { 574 System.out.println(" FAIL: Can't change value back to original on property " + name); 575 bResult = false; 576 } 577 } 578 catch (com.sun.star.uno.Exception e) 579 { 580 System.out.println(" FAIL: getFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage()); 581 bResult = false; 582 } 583 return bResult; 584 } 585 checkStringProperty(Property property)586 private boolean checkStringProperty(Property property) 587 { 588 boolean bResult = true; 589 XFastPropertySet xFPS = UnoRuntime.queryInterface(XFastPropertySet.class, aPathSettings); 590 String name = property.Name; 591 int handle = property.Handle; 592 Object oValue; 593 try 594 { 595 oValue = xFPS.getFastPropertyValue(handle); 596 } 597 catch (UnknownPropertyException ex) 598 { 599 return false; 600 } 601 catch (WrappedTargetException ex) 602 { 603 return false; 604 } 605 606 607 try 608 { 609 String val = ""; 610 val = AnyConverter.toString(oValue); 611 System.out.println(" Property has initial value: '" + val + "'"); 612 613 // set to a new correct value 614 String newVal = changeToCorrectValue(val); 615 System.out.println(" Try to change to a correct value '" + newVal + "'"); 616 xFPS.setFastPropertyValue(handle, newVal); 617 618 // check the change 619 String checkVal = (String) xFPS.getFastPropertyValue(handle); 620 if (!checkPaths(checkVal, newVal)) 621 { 622 System.out.println(" FAIL: Did not change value on property " + name + "."); 623 bResult = false; 624 } 625 newVal = changeToIncorrectValue(val); 626 System.out.println(" Try to change to incorrect value '" + newVal + "'"); 627 try 628 { 629 xFPS.setFastPropertyValue(handle, newVal); 630 } 631 catch (com.sun.star.lang.IllegalArgumentException e) 632 { 633 System.out.println(" Correctly thrown Exception caught."); 634 } 635 636 // check if changed 637 String checkVal2 = (String) xFPS.getFastPropertyValue(handle); 638 if (!checkPaths(checkVal2, checkVal)) 639 { 640 System.out.println(" FAIL: Value did change on property " + name + " though it should not have."); 641 bResult = false; 642 } 643 else 644 { 645 System.out.println(" OK: Incorrect value was not set."); 646 } 647 // set back to initial setting 648 System.out.println(" Set back to initial value."); 649 try 650 { 651 xFPS.setFastPropertyValue(handle, val); 652 } 653 catch (com.sun.star.lang.IllegalArgumentException e) 654 { 655 System.out.println(" IllegalArgumentException caught: " + e.getMessage()); 656 bResult = false; 657 } 658 // check if changed 659 String checkVal3 = (String) xFPS.getFastPropertyValue(handle); 660 if (!checkVal3.equals(val)) 661 { 662 if (!checkPaths(checkVal3, val)) 663 { 664 System.out.println(" FAIL: Can't change value back to original on property " + name); 665 System.out.println(" Value is: " + checkVal3); 666 667 bResult = false; 668 } 669 else 670 { 671 System.out.println(" OK: the pathsettings contains the original path."); 672 System.out.println(" Value is: " + checkVal3); 673 System.out.println(" Value should be: " + val); 674 } 675 } 676 else 677 { 678 System.out.println(" OK: Change value back to original on property " + name); 679 } 680 } 681 catch (com.sun.star.uno.Exception e) 682 { 683 System.out.println(" FAIL: getFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage()); 684 bResult = false; 685 } 686 return bResult; 687 } 688 689 // ____________________ 690 /** 691 * This tests the XMultiPropertySet interface implementation. 692 */ 693 694 // The test checkXMultiPropertySet() has been marked as outdated! 695 696 // @Test 697 // public void checkXMultiPropertySet() 698 // { 699 // System.out.println("---- Testing the XMultiPropertySet interface ----"); 700 // XMultiPropertySet xMPS = UnoRuntime.queryInterface(XMultiPropertySet.class, aPathSettings); 701 // 702 // // xPropertyInfoOfPathSettings.length 703 // String[] propertiesToTest = new String[1]; 704 // propertiesToTest[0] = availablePropNames[0]; 705 // 706 // String[] correctVals = new String[propertiesToTest.length]; 707 // String[] incorrectVals = new String[propertiesToTest.length]; 708 // 709 // String[] aPathSettingWorkingNames = null; 710 // aPathSettingWorkingNames = new String[propertiesToTest.length]; 711 // 712 // // get intitial values and create new ones 713 // for (int i = 0; i < propertiesToTest.length; i++) 714 // { 715 // // Property aProp = aListOfWorkingProperty.get(i); 716 // final String sName = propertiesToTest[i]; 717 // final String sValue = getPropertyValueAsString(sName); 718 // aPathSettingWorkingNames[i] = sName; 719 // correctVals[i] = changeToCorrectValue(sValue); 720 // incorrectVals[i] = changeToIncorrectValue(sValue); 721 // } 722 // 723 // try 724 // { 725 // // add a change listener 726 // MyChangeListener mListener = new MyChangeListener(); 727 // xMPS.addPropertiesChangeListener(aPathSettingWorkingNames, mListener); 728 // 729 // // first change xPropertyInfoOfPathSettings to correct values 730 // System.out.println("Change to correct values."); 731 // xMPS.setPropertyValues(aPathSettingWorkingNames, correctVals); 732 // assertTrue("Could not change to correct values with XMultiPropertySet.", 733 // verifyPropertySet(xMPS, aPathSettingWorkingNames, correctVals) > 0); 734 // 735 // // second, change to incorrect values: expect an exception 736 // System.out.println("Try to change to incorrect values."); 737 // try 738 // { 739 // xMPS.setPropertyValues(aPathSettingWorkingNames, incorrectVals); 740 // } 741 // catch (com.sun.star.lang.IllegalArgumentException r) 742 // { 743 // System.out.println("Correctly thrown Exception caught."); 744 // } 745 // assertTrue("Did change to incorrect values with XMultiPropertySet," 746 // + " but should not have.", 747 // verifyPropertySet(xMPS, aPathSettingWorkingNames, correctVals) > 0); 748 // 749 // // third, change back to initial values 750 // System.out.println("Change back to initial values."); 751 // xMPS.setPropertyValues(aPathSettingWorkingNames, aPathSettingValues); 752 // assertTrue("Could not change back to initial values with" 753 // + " XMultiPropertySet.", 754 // verifyPropertySet(xMPS, aPathSettingWorkingNames, aPathSettingValues) > 0); 755 // 756 // // fire the event for the listener 757 // System.out.println("Fire event."); 758 // xMPS.firePropertiesChangeEvent(aPathSettingWorkingNames, mListener); 759 // assertTrue("Event was not fired on XMultiPropertySet.", 760 // mListener.changePropertiesEventFired()); 761 // } 762 // catch (com.sun.star.uno.Exception e) 763 // { 764 //// e.printStackTrace(); 765 // System.out.println(e.getClass().getName()); 766 // System.out.println("Message: " + e.getMessage()); 767 // fail("Unexpected exception on XMultiPropertySet."); 768 // } 769 // 770 // // test finished 771 // System.out.println("---- Test of XMultiPropertySet finished ----\n"); 772 // } 773 774 /** 775 * Verify if the values of xPropSet_of_PathSettings are the same as vals. 776 * @param xPropSet_of_PathSettings A XMultiPropertySet. 777 * @param aPathSettingWorkingNames An array with property names. 778 * @param vals An array with values of the properties 779 * @return -1 if none are equal, 1 if all are equal, 0 if some were equal 780 * and some not. 781 * @throws com.sun.star.lang.IllegalArgumentException 782 */ 783 // private int verifyPropertySet(XMultiPropertySet xProp, 784 // String[] propNames, String[] vals) 785 // { 786 // int ret = 0; 787 // if (vals.length != propNames.length) 788 // { 789 // System.out.println("Length of array parameters must be equal."); 790 // return ret; 791 // } 792 // for (int i = 0; i < vals.length; i++) 793 // { 794 // Object[] objs = xProp.getPropertyValues(new String[] 795 // { 796 // propNames[i] 797 // }); 798 // String retVal = (String) objs[0]; 799 // boolean nCheck = retVal.equals(vals[i]); 800 // if (!nCheck) 801 // { 802 // System.out.println("Property '" + propNames[i] 803 // + "' was supposed to have value:"); 804 // System.out.println(vals[i]); 805 // System.out.println("but has value:"); 806 // System.out.println(retVal); 807 // } 808 // // initialize 809 // if (i == 0) 810 // { 811 // ret = nCheck ? 1 : -1; 812 // continue; 813 // } 814 // // return 0 if equal state changes compared to initial value 815 // if ((nCheck && ret < 0) || (!nCheck && ret > 0)) 816 // { 817 // ret = 0; 818 // } 819 // } 820 // return ret; 821 // } 822 823 // ____________________ 824 /** 825 * This tests the XPropertySet interface implementation. 826 */ 827 828 // The test checkXPropertySet() has been marked as outdated! 829 830 831 // @Test 832 // public void checkXPropertySet() 833 // { 834 // System.out.println("---- Testing the XPropertySet interface ----"); 835 // 836 // XPropertySet xPS = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings); 837 // 838 // MyChangeListener mListener1 = new MyChangeListener(); 839 // MyChangeListener mListener2 = new MyChangeListener(); 840 // 841 // for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++) 842 // { 843 // // adding listeners 844 // String name = aPathSettingNames[i]; 845 // System.out.println("Testing property '" + name + "'"); 846 // try 847 // { 848 // System.out.println("Add 2 Listeners."); 849 // xPS.addPropertyChangeListener(name, mListener1); 850 // xPS.addVetoableChangeListener(name, mListener1); 851 // xPS.addPropertyChangeListener(name, mListener2); 852 // xPS.addVetoableChangeListener(name, mListener2); 853 // 854 // // change the property 855 // System.out.println("Change value."); 856 // String changeVal = changeToCorrectValue(aPathSettingValues[i]); 857 // xPS.setPropertyValue(name, changeVal); 858 // String newVal = (String) xPS.getPropertyValue(name); 859 // 860 // assertTrue("Value did not change on property " + name + ".", 861 // newVal.equals(changeVal)); 862 // 863 // assertTrue("Listener 1 was not called.", checkListener(mListener1)); 864 // assertTrue("Listener 2 was not called.", checkListener(mListener2)); 865 // 866 // mListener1.resetListener(); 867 // mListener2.resetListener(); 868 // 869 // System.out.println("Remove Listener 1."); 870 // 871 // xPS.removePropertyChangeListener(name, mListener1); 872 // xPS.removeVetoableChangeListener(name, mListener1); 873 // 874 // // change the property 875 // System.out.println("Change value back."); 876 // xPS.setPropertyValue(name, aPathSettingValues[i]); 877 // newVal = (String) xPS.getPropertyValue(name); 878 // assertTrue("Value did not change on property " + name, 879 // newVal.equals(aPathSettingValues[i])); 880 // 881 // assertTrue("Listener was called, although it was removed on" 882 // + " property " + name + ".", !checkListener(mListener1)); 883 // assertTrue("Listener 2 was not called on property " + name + ".", 884 // checkListener(mListener2)); 885 // } 886 // catch (com.sun.star.uno.Exception e) 887 // { 888 // System.out.println(e.getClass().getName()); 889 // System.out.println("Message: " + e.getMessage()); 890 // fail("Unexpcted exception on property " + name); 891 // } 892 // System.out.println("Finish testing property '" + aPathSettingNames[i] + "'\n"); 893 // } 894 // System.out.println("---- Test of XPropertySet finished ----\n"); 895 // 896 // } 897 898 // private boolean checkListener(MyChangeListener ml) 899 // { 900 // return ml.changePropertyEventFired() 901 // || ml.changePropertiesEventFired() 902 // || ml.vetoableChangeEventFired(); 903 // } 904 905 // ____________________ 906 /** 907 * Change the given String to a correct path URL. 908 * @return The changed path URL. 909 */ changeToCorrectValue(String path)910 private String changeToCorrectValue(String path) 911 { 912 // the simplest possibility 913 if (path == null || path.equals("")) 914 { 915 String sTempDir = System.getProperty("java.io.tmpdir"); 916 sTempDir = util.utils.getFullURL(sTempDir); 917 return sTempDir; // "file:///tmp"; 918 } 919 return graphical.FileHelper.appendPath(path, "tmp"); 920 } 921 922 /** 923 * Change the given String to an incorrect path URL. 924 * @return The changed path URL. 925 */ changeToIncorrectValue(String path)926 private String changeToIncorrectValue(String path) 927 { 928 // return an illegal path 929 return "fileblablabla"; 930 } 931 932 /** 933 * Listener implementation which sets a flag when 934 * listener was called. 935 */ 936 public class MyChangeListener implements XPropertiesChangeListener, 937 XPropertyChangeListener, 938 XVetoableChangeListener 939 { 940 941 private boolean propChanged = false; 942 private boolean propertiesChanged = false; 943 private boolean disposeCalled = false; 944 private boolean vetoableChanged = false; 945 propertiesChange( com.sun.star.beans.PropertyChangeEvent[] e)946 public void propertiesChange( 947 com.sun.star.beans.PropertyChangeEvent[] e) 948 { 949 propertiesChanged = true; 950 } 951 vetoableChange(com.sun.star.beans.PropertyChangeEvent pE)952 public void vetoableChange(com.sun.star.beans.PropertyChangeEvent pE) 953 throws com.sun.star.beans.PropertyVetoException 954 { 955 vetoableChanged = true; 956 } 957 propertyChange(com.sun.star.beans.PropertyChangeEvent pE)958 public void propertyChange(com.sun.star.beans.PropertyChangeEvent pE) 959 { 960 propChanged = true; 961 } 962 disposing(com.sun.star.lang.EventObject eventObject)963 public void disposing(com.sun.star.lang.EventObject eventObject) 964 { 965 disposeCalled = true; 966 } 967 resetListener()968 public void resetListener() 969 { 970 propChanged = false; 971 propertiesChanged = false; 972 disposeCalled = false; 973 vetoableChanged = false; 974 } 975 changePropertyEventFired()976 public boolean changePropertyEventFired() 977 { 978 return propChanged; 979 } 980 changePropertiesEventFired()981 public boolean changePropertiesEventFired() 982 { 983 return propertiesChanged; 984 } 985 vetoableChangeEventFired()986 public boolean vetoableChangeEventFired() 987 { 988 return vetoableChanged; 989 } 990 } 991 getMSF()992 private XMultiServiceFactory getMSF() 993 { 994 final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 995 return xMSF1; 996 } 997 998 // setup and close connections 999 @BeforeClass setUpConnection()1000 public static void setUpConnection() throws Exception 1001 { 1002 System.out.println("setUpConnection()"); 1003 connection.setUp(); 1004 } 1005 1006 @AfterClass tearDownConnection()1007 public static void tearDownConnection() 1008 throws InterruptedException, com.sun.star.uno.Exception 1009 { 1010 System.out.println("tearDownConnection()"); 1011 connection.tearDown(); 1012 } 1013 private static final OfficeConnection connection = new OfficeConnection(); 1014 } 1015