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