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