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 import util.ValueChanger; 30 import util.ValueComparer; 31 32 import com.sun.star.ui.dialogs.XFilePickerControlAccess; 33 34 /** 35 * Testing <code>com.sun.star.ui.XFilePickerControlAccess</code> 36 * interface methods : 37 * <ul> 38 * <li><code> setValue()</code></li> 39 * <li><code> getValue()</code></li> 40 * <li><code> setLabel()</code></li> 41 * <li><code> getLabel()</code></li> 42 * <li><code> getFocused()</code></li> 43 * <li><code> enableControl()</code></li> 44 * </ul> <p> 45 * This test needs the following object relations : 46 * <ul> 47 * <li> <code>'XFilePickerControlAccess.ControlID'</code> (of type 48 * <code>Short</code>) : control identifier in the extended 49 * FilePicker dialog. </li> 50 * <li> <code>'XFilePickerControlAccess.ControlValue'</code> (of type 51 * <code>Object</code>) <b>optional</b> (but mostly desirable 52 * since the control has emtpy initial value): 53 * the value which can set for the control . </li> 54 * <ul> <p> 55 * Test is <b> NOT </b> multithread compilant. <p> 56 * @see com.sun.star.ui.XFilePickerControlAccess 57 */ 58 public class _XFilePickerControlAccess extends MultiMethodTest { 59 60 public XFilePickerControlAccess oObj = null; 61 private short cntlID = -1 ; 62 private Object oldVal = null ; 63 private String oldLab = null ; 64 65 /** 66 * Retrieves object relations. 67 * @throws StatusException If one of relations not found. 68 */ before()69 public void before() { 70 Short ID = (Short) tEnv.getObjRelation 71 ("XFilePickerControlAccess.ControlID") ; 72 if (ID == null) { 73 log.println("!!! Relation not found !!!") ; 74 throw new StatusException(Status.failed("Relation not found")) ; 75 } 76 77 cntlID = ID.shortValue() ; 78 } 79 80 /** 81 * Gets the value of the control and stores it. <p> 82 * Has <b>OK</b> status if no runtime exceptions occurred. 83 */ _getValue()84 public void _getValue() { 85 boolean result = true ; 86 87 try { 88 oldVal = oObj.getValue(cntlID,(short)0); 89 } catch (Exception e) { 90 e.printStackTrace(log) ; 91 result = false ; 92 } 93 94 tRes.tested("getValue()", result) ; 95 } 96 97 /** 98 * Changes the value gotten by <code>getValue</code> method, 99 * or gets the value from relation if it exits. 100 * Sets this value and then check if it was properly set. <p> 101 * Has <b>OK</b> status if <code>getValue</code> method returns 102 * the same value which was set. <p> 103 * The following method tests are to be completed successfully before : 104 * <ul> 105 * <li> <code> getValue </code> </li> 106 * </ul> 107 */ _setValue()108 public void _setValue() { 109 requiredMethod("getValue()") ; 110 boolean result = true ; 111 112 Object newVal = tEnv.getObjRelation 113 ("XFilePickerControlAccess.ControlValue"); 114 if (newVal == null) { 115 newVal = ValueChanger.changePValue(oldVal) ; 116 } 117 118 Object getVal = null ; 119 120 try { 121 oObj.setValue(cntlID, (short)0 , newVal) ; 122 getVal = oObj.getValue(cntlID,(short)0) ; 123 } catch (Exception e) { 124 e.printStackTrace(log) ; 125 result = false ; 126 } 127 128 result &= ValueComparer.equalValue(newVal, getVal) ; 129 130 tRes.tested("setValue()", result) ; 131 } 132 133 /** 134 * Gets the label of the control and stores it. <p> 135 * Has <b>OK</b> status if no runtime exceptions occurred. 136 */ _getLabel()137 public void _getLabel() { 138 139 try { 140 oldLab = oObj.getLabel(cntlID); 141 } catch (Exception e) { 142 e.printStackTrace(log) ; 143 } 144 145 tRes.tested("getLabel()", oldLab != null) ; 146 } 147 148 /** 149 * Changes the label gotten by <code>getLabel</code> method, 150 * set this label and then check if it was properly set. <p> 151 * Has <b>OK</b> status if <code>getLael</code> method returns 152 * the same value which was set. <p> 153 * The following method tests are to be completed successfully before : 154 * <ul> 155 * <li> <code> getLabel </code> </li> 156 * </ul> 157 */ _setLabel()158 public void _setLabel() { 159 requiredMethod("getLabel()") ; 160 boolean result = true ; 161 162 String newVal = oldLab + "_" ; 163 String getVal = null ; 164 165 try { 166 oObj.setLabel(cntlID, newVal) ; 167 getVal = oObj.getLabel(cntlID) ; 168 } catch (Exception e) { 169 e.printStackTrace(log) ; 170 result = false ; 171 } 172 173 result &= newVal.equals(getVal) ; 174 175 tRes.tested("setLabel()", result) ; 176 } 177 178 /** 179 * Disables and then enables the control. Can be checked only 180 * interactively. <p> 181 * Has <b>OK</b> status if no runtime exceptions occurred. 182 */ _enableControl()183 public void _enableControl() { 184 boolean result = true ; 185 186 try { 187 oObj.enableControl(cntlID, false) ; 188 oObj.enableControl(cntlID, true) ; 189 } catch (Exception e) { 190 e.printStackTrace(log) ; 191 result = false ; 192 } 193 194 tRes.tested("enableControl()", result) ; 195 } 196 } 197 198 199