| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package ifc.awt.tree; |
| 20 |
|
| 21 |
import com.sun.star.awt.tree.XMutableTreeNode; |
| 22 |
import lib.MultiMethodTest; |
| 23 |
import lib.Status; |
| 24 |
import lib.StatusException; |
| 25 |
|
| 26 |
/** |
| 27 |
* Testing <code>com.sun.star.awt.tree.XTreeDataModel</code> |
| 28 |
* interface methods : |
| 29 |
* <ul> |
| 30 |
* <li><code> appendChild()</code></li> |
| 31 |
* <li><code> insertChildByIndex()</code></li> |
| 32 |
* <li><code> removeChildByIndex()</code></li> |
| 33 |
* <li><code> setHasChildrenOnDemand()</code></li> |
| 34 |
* <li><code> setDisplayValue()</code></li> |
| 35 |
* <li><code> setNodeGraphicURL()</code></li> |
| 36 |
* <li><code> setExpandedGraphicURL()</code></li> |
| 37 |
* <li><code> setCollapsedGraphicURL()</code></li> |
| 38 |
* <li><code> DataValue()</code></li> |
| 39 |
* </ul> <p> |
| 40 |
* Test is <b> NOT </b> multithread compliant. <p> |
| 41 |
* |
| 42 |
* @see com.sun.star.awt.tree.XTreeDataModel |
| 43 |
*/ |
| 44 |
public class _XMutableTreeNode extends MultiMethodTest { |
| 45 |
|
| 46 |
public XMutableTreeNode oObj = null; |
| 47 |
|
| 48 |
private XMutableTreeNodeCreator nodeCreator = null; |
| 49 |
|
| 50 |
public interface XMutableTreeNodeCreator{ |
| 51 |
XMutableTreeNode createNode(String name); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void before(){ |
| 56 |
nodeCreator = (XMutableTreeNodeCreator) tEnv.getObjRelation("XMutableTreeNodeCreator"); |
| 57 |
if (nodeCreator == null){ |
| 58 |
throw new StatusException(Status.failed( |
| 59 |
"Couldn't get relation 'XMutableTreeNodeCreator'")); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
public void _appendChild(){ |
| 65 |
boolean bOK = true; |
| 66 |
|
| 67 |
log.println("try to append a valid node..."); |
| 68 |
|
| 69 |
XMutableTreeNode myNode = nodeCreator.createNode("myNodeToAppend"); |
| 70 |
|
| 71 |
try { |
| 72 |
oObj.appendChild(myNode); |
| 73 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 74 |
log.println("ERROR: could not append a valid node: " + ex.toString()); |
| 75 |
bOK = false; |
| 76 |
} |
| 77 |
|
| 78 |
log.println("try to append the node a second time..."); |
| 79 |
try { |
| 80 |
|
| 81 |
oObj.appendChild(myNode); |
| 82 |
log.println("ERROR: expected IllegalArgumentException was not thrown => FAILED"); |
| 83 |
bOK = false; |
| 84 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 85 |
log.println("expected IllegalArgumentException was thrown => OK"); |
| 86 |
} |
| 87 |
|
| 88 |
log.println("try to append the object itself..."); |
| 89 |
try { |
| 90 |
|
| 91 |
oObj.appendChild(oObj); |
| 92 |
log.println("ERROR: expected IllegalArgumentException was not thrown => FAILED"); |
| 93 |
bOK = false; |
| 94 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 95 |
log.println("expected IllegalArgumentException was thrown => OK"); |
| 96 |
} |
| 97 |
|
| 98 |
tRes.tested("appendChild()", bOK); |
| 99 |
} |
| 100 |
|
| 101 |
public void _insertChildByIndex(){ |
| 102 |
boolean bOK = true; |
| 103 |
|
| 104 |
XMutableTreeNode myNode = nodeCreator.createNode("myNodeToInsert"); |
| 105 |
|
| 106 |
try { |
| 107 |
log.println("try to insert a valid node..."); |
| 108 |
oObj.insertChildByIndex(0, myNode); |
| 109 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 110 |
log.println("ERROR: could not insert a valid node: " + ex.toString()); |
| 111 |
bOK = false; |
| 112 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 113 |
log.println("ERROR: could not insert a valid node on index '0': " + ex.toString()); |
| 114 |
bOK = false; |
| 115 |
} |
| 116 |
|
| 117 |
try { |
| 118 |
log.println("try to insert a valid node a second time..."); |
| 119 |
oObj.insertChildByIndex(0, myNode); |
| 120 |
log.println("ERROR: expected IllegalArgumentException was not thrown => FAILED"); |
| 121 |
bOK = false; |
| 122 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 123 |
log.println("expected IllegalArgumentException wa thrown => OK"); |
| 124 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 125 |
log.println("ERROR: wrong IndexOutOfBoundsException was thrown. Expected is IllegalArgumentException => FAILED"); |
| 126 |
bOK = false; |
| 127 |
} |
| 128 |
|
| 129 |
XMutableTreeNode myNode2 = nodeCreator.createNode("myNodeToInsert2"); |
| 130 |
|
| 131 |
try { |
| 132 |
log.println("try to insert a valid node on invalid index '-3'..."); |
| 133 |
oObj.insertChildByIndex(-3, myNode2); |
| 134 |
log.println("ERROR: expected IndexOutOfBoundsException was not thrown => FAILED"); |
| 135 |
bOK = false; |
| 136 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 137 |
log.println("ERROR: wrong IllegalArgumentException was thrown. Expected is IndexOutOfBoundsException => FAILED"); |
| 138 |
bOK = false; |
| 139 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 140 |
log.println("Expected IndexOutOfBoundsException was thrown => OK"); |
| 141 |
} |
| 142 |
|
| 143 |
try { |
| 144 |
log.println("try to insert the object itself..."); |
| 145 |
oObj.insertChildByIndex(0, oObj); |
| 146 |
log.println("ERROR: expected IllegalArgumentException was not thrown => FAILED"); |
| 147 |
bOK = false; |
| 148 |
} catch (com.sun.star.lang.IllegalArgumentException ex) { |
| 149 |
log.println("expected IllegalArgumentException was thrown => OK"); |
| 150 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 151 |
log.println("unexpected IndexOutOfBoundsException was thrown, expected was IllegalArgumentException => FAILED"); |
| 152 |
bOK = false; |
| 153 |
} |
| 154 |
|
| 155 |
tRes.tested("insertChildByIndex()", bOK); |
| 156 |
} |
| 157 |
|
| 158 |
public void _removeChildByIndex(){ |
| 159 |
|
| 160 |
requiredMethod("insertChildByIndex()"); |
| 161 |
boolean bOK = true; |
| 162 |
|
| 163 |
try { |
| 164 |
log.println("try to remove node at index '0'..."); |
| 165 |
oObj.removeChildByIndex(0); |
| 166 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 167 |
log.println("ERROR: IndexOutOfBoundsException was thrown => FAILED"); |
| 168 |
bOK = false; |
| 169 |
} |
| 170 |
|
| 171 |
try { |
| 172 |
log.println("try to remove node at invalid index '-3'"); |
| 173 |
oObj.removeChildByIndex(-3); |
| 174 |
log.println("ERROR: expected IndexOutOfBoundsException was not thrown => FAILED"); |
| 175 |
bOK = false; |
| 176 |
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) { |
| 177 |
log.println("expected IndexOutOfBoundsException was thrown => OK"); |
| 178 |
} |
| 179 |
tRes.tested("removeChildByIndex()", bOK); |
| 180 |
} |
| 181 |
|
| 182 |
public void _setHasChildrenOnDemand(){ |
| 183 |
boolean bOK = true; |
| 184 |
|
| 185 |
log.println("setHasChildrenOnDemand(true)"); |
| 186 |
oObj.setHasChildrenOnDemand(true); |
| 187 |
|
| 188 |
log.println("setHasChildrenOnDemand(false)"); |
| 189 |
oObj.setHasChildrenOnDemand(false); |
| 190 |
|
| 191 |
tRes.tested("setHasChildrenOnDemand()", bOK); |
| 192 |
} |
| 193 |
|
| 194 |
public void _setDisplayValue(){ |
| 195 |
boolean bOK = true; |
| 196 |
|
| 197 |
log.println("setDisplayValue(\"MyTestValue\")"); |
| 198 |
oObj.setDisplayValue("MyTestValue"); |
| 199 |
|
| 200 |
log.println("setDisplayValue(null)"); |
| 201 |
oObj.setDisplayValue(null); |
| 202 |
|
| 203 |
log.println("oObj.setDisplayValue(oObj)"); |
| 204 |
oObj.setDisplayValue(oObj); |
| 205 |
|
| 206 |
tRes.tested("setDisplayValue()", bOK); |
| 207 |
} |
| 208 |
|
| 209 |
public void _setNodeGraphicURL(){ |
| 210 |
boolean bOK = true; |
| 211 |
|
| 212 |
log.println("setNodeGraphicURL(\"MyTestURL\")"); |
| 213 |
oObj.setNodeGraphicURL("MyTestURL"); |
| 214 |
|
| 215 |
log.println("setNodeGraphicURL(null)"); |
| 216 |
oObj.setNodeGraphicURL(null); |
| 217 |
|
| 218 |
tRes.tested("setNodeGraphicURL()", bOK); |
| 219 |
} |
| 220 |
|
| 221 |
public void _setExpandedGraphicURL(){ |
| 222 |
boolean bOK = true; |
| 223 |
|
| 224 |
log.println("setExpandedGraphicURL(\"myExpandedURL\")"); |
| 225 |
oObj.setExpandedGraphicURL("myExpandedURL"); |
| 226 |
|
| 227 |
log.println("setExpandedGraphicURL(null)"); |
| 228 |
oObj.setExpandedGraphicURL(null); |
| 229 |
|
| 230 |
tRes.tested("setExpandedGraphicURL()", bOK); |
| 231 |
} |
| 232 |
|
| 233 |
public void _setCollapsedGraphicURL(){ |
| 234 |
boolean bOK = true; |
| 235 |
|
| 236 |
log.println("setCollapsedGraphicURL(\"myCollapsedURL\")"); |
| 237 |
oObj.setCollapsedGraphicURL("myCollapsedURL"); |
| 238 |
|
| 239 |
log.println("setCollapsedGraphicURL(null)"); |
| 240 |
oObj.setCollapsedGraphicURL(null); |
| 241 |
|
| 242 |
tRes.tested("setCollapsedGraphicURL()", bOK); |
| 243 |
} |
| 244 |
|
| 245 |
public void _DataValue(){ |
| 246 |
boolean bOK = true; |
| 247 |
|
| 248 |
log.println("setDataValue(\"myDataValue\")"); |
| 249 |
oObj.setDataValue("myDataValue"); |
| 250 |
|
| 251 |
String sDataValue = (String) oObj.getDataValue(); |
| 252 |
|
| 253 |
if ( ! sDataValue.equals("myDataValue")) { |
| 254 |
log.println("ERROR: getDataValue does not return the value which is inserted before:\n" + |
| 255 |
"\texpected: myDataValue\n" + |
| 256 |
"\tgot: " + sDataValue); |
| 257 |
bOK = false; |
| 258 |
} |
| 259 |
|
| 260 |
log.println("setDataValue(null)"); |
| 261 |
oObj.setDataValue(null); |
| 262 |
|
| 263 |
Object oDataValue = oObj.getDataValue(); |
| 264 |
if ( oDataValue != null) { |
| 265 |
log.println("ERROR: getDataValue does not return the value which is inserted before:\n" + |
| 266 |
"\texpected: null\n" + |
| 267 |
"\tgot: " + oDataValue.toString()); |
| 268 |
bOK = false; |
| 269 |
} |
| 270 |
|
| 271 |
log.println("oObj.setDisplayValue(oObj)"); |
| 272 |
oObj.setDisplayValue(oObj); |
| 273 |
|
| 274 |
oDataValue = oObj.getDataValue(); |
| 275 |
if ( oDataValue != null) { |
| 276 |
log.println("ERROR: getDataValue does not return the value which is inserted before:\n" + |
| 277 |
"\texpected: " + oObj.toString() +"\n" + |
| 278 |
"\tgot: " + oDataValue.toString()); |
| 279 |
bOK = false; |
| 280 |
} |
| 281 |
|
| 282 |
tRes.tested("DataValue()", bOK); |
| 283 |
} |
| 284 |
|
| 285 |
} |