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 28 package ifc.ui.dialogs; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 34 import com.sun.star.ui.dialogs.XControlAccess; 35 import com.sun.star.ui.dialogs.XControlInformation; 36 import com.sun.star.uno.UnoRuntime; 37 38 /** 39 * Testing <code>com.sun.star.ui.XFilePicker</code> 40 * interface methods : 41 * <ul> 42 * <li><code> setControlProperty()</code></li> 43 * <li><code> getControlProperty()</code></li> 44 * </ul> <p> 45 * 46 * For testing this interface the component must implement 47 * <code>com.sun.star.ui.dialogs.XControlInformation</code> 48 * interface. <p> 49 * 50 * Test is <b> NOT </b> multithread compilant. <p> 51 * @see com.sun.star.ui.XFolderPicker 52 */ 53 public class _XControlAccess extends MultiMethodTest { 54 55 public XControlAccess oObj = null; 56 private XControlInformation xCI = null ; 57 private String[] supControls = null ; 58 private String[][] supProperties = null ; 59 60 /** 61 * Tries to query <code>com.sun.star.ui.dialogs.XControlInformation</code> 62 * interface, and obtain properties' names of each available 63 * control. <p> 64 * 65 * @throw StatusException if interface is not supported or 66 * properties couldn't be get. 67 */ 68 protected void before() { 69 xCI = (XControlInformation) UnoRuntime.queryInterface 70 (XControlInformation.class, oObj); 71 72 if (xCI == null) throw new StatusException 73 (Status.failed("XControlInformation not supported")) ; 74 75 supControls = xCI.getSupportedControls(); 76 supProperties = new String[supControls.length][]; 77 for (int i = 0; i < supControls.length; i++) { 78 try { 79 supProperties[i] = 80 xCI.getSupportedControlProperties(supControls[i]); 81 } catch (com.sun.star.lang.IllegalArgumentException e) { 82 e.printStackTrace(log); 83 throw new StatusException 84 ("Exception while init.", e) ; 85 } 86 } 87 } 88 89 /** 90 * Tries to change each property of each control. 91 * Has <b>OK</b> status if values are properly changed. 92 */ 93 public void _setControlProperty() { 94 boolean result = true ; 95 String error = ""; 96 97 for (int i = 0; i < supControls.length; i++) { 98 log.println("Checking properties for control " + supControls[i]); 99 for (int j = 0; j < supProperties[i].length; j++) { 100 log.println("\t" + supProperties[i][j]); 101 try { 102 Object oldVal = oObj.getControlProperty(supControls[i], 103 supProperties[i][j]); 104 Object newVal = util.ValueChanger.changePValue(oldVal); 105 if (supProperties[i][j].startsWith("Help")) { 106 newVal = "HID:133"; 107 } 108 oObj.setControlProperty 109 (supControls[i], supProperties[i][j], newVal) ; 110 Object resVal = oObj.getControlProperty(supControls[i], 111 supProperties[i][j]); 112 log.println("\t Old:" + oldVal + ",New:" + newVal 113 + ",Result:" + resVal); 114 if (!util.ValueComparer.equalValue(newVal, resVal)) { 115 error += "####Property '"+supProperties[i][j]+ 116 " of "+supControls[i]+" didn't work\n\r"+ 117 "\t Old:" + oldVal + ",New:" + newVal 118 + ",Result:" + resVal+ "\n\r"; 119 } 120 result &= util.ValueComparer.equalValue(newVal, resVal); 121 } catch (com.sun.star.lang.IllegalArgumentException e) { 122 log.println("Unexpected exception:" ); 123 e.printStackTrace(log); 124 result = false ; 125 } 126 } 127 } 128 129 log.println(error); 130 131 tRes.tested("setControlProperty()", result) ; 132 tRes.tested("getControlProperty()", result) ; 133 } 134 135 /** 136 * Does nothing. Testing performed in <code>setControlProperty</code> 137 * method test. 138 */ 139 public void _getControlProperty() {} 140 } 141 142 143