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