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.awt.tree; 29 30 import com.sun.star.awt.tree.XTreeNode; 31 import com.sun.star.uno.AnyConverter; 32 import lib.MultiMethodTest; 33 import lib.Status; 34 import lib.StatusException; 35 36 /** 37 * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code> 38 * interface methods : 39 * <ul> 40 * <li><code> getChildAt()</code></li> 41 * <li><code> getChildCount()</code></li> 42 * <li><code> getParent()</code></li> 43 * <li><code> getIndex()</code></li> 44 * <li><code> hasChildrenOnDemand()</code></li> 45 * <li><code> getDisplayValue()</code></li> 46 * <li><code> getNodeGraphicURL()</code></li> 47 * <li><code> getExpandedGraphicURL()</code></li> 48 * <li><code> getCollapsedGraphicURL()</code></li> * </ul> <p> 49 * Test is <b> NOT </b> multithread compilant. <p> 50 * 51 * @see com.sun.star.awt.tree.XTreeDataModel 52 */ 53 public class _XTreeNode extends MultiMethodTest { 54 55 public XTreeNode oObj = null; 56 57 private int mCount = 0; 58 59 String msDisplayValue = null; 60 String msExpandedGraphicURL = null; 61 String msCollapsedGraphicURL = null; 62 String msNodeGraphicURL = null; 63 64 65 public void before(){ 66 msDisplayValue = (String) tEnv.getObjRelation("XTreeNode_DisplayValue"); 67 if (msDisplayValue == null){ 68 throw new StatusException(Status.failed( 69 "Couldn't get relation 'XTreeNode_DisplayVlaue'")); 70 } 71 72 msExpandedGraphicURL = (String) tEnv.getObjRelation("XTreeNode_ExpandedGraphicURL"); 73 if (msExpandedGraphicURL == null){ 74 throw new StatusException(Status.failed( 75 "Couldn't get relation 'XTreeNode_ExpandedGraphicURL'")); 76 } 77 78 msCollapsedGraphicURL = (String) tEnv.getObjRelation("XTreeNode_CollapsedGraphicURL"); 79 if (msCollapsedGraphicURL == null){ 80 throw new StatusException(Status.failed( 81 "Couldn't get relation 'XTreeNode_CollapsedGraphicURL'")); 82 } 83 84 msNodeGraphicURL = (String) tEnv.getObjRelation("XTreeNode_NodeGraphicURL"); 85 if(msNodeGraphicURL == null){ 86 throw new StatusException(Status.failed( 87 "Couldn't get relation 'XTreeNode_NodeGraphicURL'")); 88 } 89 90 } 91 92 /** 93 * Gets the title and compares it to the value set in 94 * <code>setTitle</code> method test. <p> 95 * Has <b>OK</b> status is set/get values are equal. 96 * The following method tests are to be completed successfully before : 97 * <ul> 98 * <li> <code> setTitle </code> </li> 99 * </ul> 100 */ 101 public void _getChildAt(){ 102 this.requiredMethod("getChildCount()"); 103 boolean bOK = true; 104 105 for (int i=0; i < mCount ; i++){ 106 XTreeNode xNode = null; 107 try { 108 xNode = oObj.getChildAt(i); 109 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 110 log.println("ERROR: getChildAt(" + i + "): " + ex.toString()); 111 } 112 if (xNode == null){ 113 log.println("ERROR: getChildAt(" + i + ") returns null => FAILED"); 114 bOK = false; 115 } 116 } 117 118 tRes.tested("getChildAt()", bOK); 119 } 120 121 122 public void _getChildCount(){ 123 124 boolean bOK = true; 125 mCount = oObj.getChildCount(); 126 log.println("got count '" + mCount + "' of children"); 127 if (mCount < 1 ) { 128 log.println("ERROR: got a count < 1. The test object must be support morw then zero children => FAILED"); 129 bOK = false; 130 } 131 tRes.tested("getChildCount()", bOK); 132 } 133 134 135 public void _getParent(){ 136 this.requiredMethod("getChildAt()"); 137 138 boolean bOK = true; 139 XTreeNode xNode = null; 140 try { 141 log.println("try to getChildAt(0)"); 142 xNode = oObj.getChildAt(0); 143 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 144 log.println("ERROR: getChildAt(0): " + ex.toString()); 145 } 146 147 log.println("try to get parrent of children"); 148 XTreeNode xParrent = xNode.getParent(); 149 150 151 bOK = oObj.equals(xParrent); 152 log.println("original object and parrent should be the same: " + bOK); 153 tRes.tested("getParent()", bOK); 154 } 155 156 157 public void _getIndex(){ 158 this.requiredMethod("getChildAt()"); 159 160 boolean bOK = true; 161 XTreeNode xNode = null; 162 try { 163 log.println("try to getChildAt(0)"); 164 xNode = oObj.getChildAt(0); 165 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 166 log.println("ERROR: getChildAt(0): " + ex.toString()); 167 } 168 169 log.println("try to get index from child..."); 170 int index = oObj.getIndex(xNode); 171 172 if (index != 0){ 173 log.println("ERROR: getIndex() does not return '0' => FAILED"); 174 bOK = false; 175 } 176 177 tRes.tested("getIndex()", bOK); 178 } 179 180 181 public void _hasChildrenOnDemand(){ 182 183 boolean bOK = true; 184 185 bOK = oObj.hasChildrenOnDemand(); 186 tRes.tested("hasChildrenOnDemand()", bOK); 187 } 188 189 190 public void _getDisplayValue(){ 191 192 boolean bOK = true; 193 String DisplayValue = null; 194 Object dispVal = oObj.getDisplayValue(); 195 196 try { 197 DisplayValue = AnyConverter.toString(dispVal); 198 } catch (com.sun.star.lang.IllegalArgumentException ex) { 199 log.println("ERROR: could not convert the returned object of 'getDisplyValue()' " + 200 "to String with AnyConverter: " + ex.toString()); 201 } 202 203 if ( ! this.msDisplayValue.equals(DisplayValue)){ 204 log.println("ERROR: getNodeGraphicURL() does not return expected value:\n" + 205 "\tExpected: " + this.msDisplayValue +"\n" + 206 "\tGot: " + DisplayValue); 207 bOK = false; 208 } 209 210 tRes.tested("getDisplayValue()", bOK); 211 } 212 213 214 public void _getNodeGraphicURL(){ 215 216 boolean bOK = true; 217 String graphicURL = oObj.getNodeGraphicURL(); 218 219 if ( ! this.msNodeGraphicURL.equals(graphicURL)){ 220 log.println("ERROR: getNodeGraphicURL() does not return expected value:\n" + 221 "\tExpected: " + this.msNodeGraphicURL +"\n" + 222 "\tGot: " + graphicURL); 223 bOK = false; 224 } 225 tRes.tested("getNodeGraphicURL()", bOK); 226 } 227 228 229 public void _getExpandedGraphicURL(){ 230 231 boolean bOK = true; 232 String ExpandedGraphicURL = oObj.getExpandedGraphicURL(); 233 234 if ( ! this.msExpandedGraphicURL.equals(ExpandedGraphicURL)){ 235 log.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" + 236 "\tExpected: " + this.msExpandedGraphicURL +"\n" + 237 "\tGot: " + ExpandedGraphicURL); 238 bOK = false; 239 } 240 241 tRes.tested("getExpandedGraphicURL()", bOK); 242 } 243 244 245 public void _getCollapsedGraphicURL(){ 246 247 boolean bOK = true; 248 249 String CollapsedGraphicURL = oObj.getCollapsedGraphicURL(); 250 251 if ( ! this.msCollapsedGraphicURL.equals(CollapsedGraphicURL)){ 252 log.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" + 253 "\tExpected: " + this.msCollapsedGraphicURL +"\n" + 254 "\tGot: " + CollapsedGraphicURL); 255 bOK = false; 256 } 257 258 tRes.tested("getCollapsedGraphicURL()", bOK); 259 } 260 261 }