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