2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
21 import com
.sun
.star
.awt
.tree
.XMutableTreeNode
;
22 import lib
.MultiMethodTest
;
24 import lib
.StatusException
;
27 * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code>
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>
40 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.awt.tree.XTreeDataModel
44 public class _XMutableTreeNode
extends MultiMethodTest
{
46 public XMutableTreeNode oObj
= null;
48 private XMutableTreeNodeCreator nodeCreator
= null;
50 public interface XMutableTreeNodeCreator
{
51 XMutableTreeNode
createNode(String name
);
56 nodeCreator
= (XMutableTreeNodeCreator
) tEnv
.getObjRelation("XMutableTreeNodeCreator");
57 if (nodeCreator
== null){
58 throw new StatusException(Status
.failed(
59 "Couldn't get relation 'XMutableTreeNodeCreator'"));
64 public void _appendChild(){
67 log
.println("try to append a valid node...");
69 XMutableTreeNode myNode
= nodeCreator
.createNode("myNodeToAppend");
72 oObj
.appendChild(myNode
);
73 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
74 log
.println("ERROR: could not appedn a valid node: " + ex
.toString());
78 log
.println("try to append the node a second time...");
81 oObj
.appendChild(myNode
);
82 log
.println("ERROR: expected IllegalArgumentException was not thrown => FAILED");
84 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
85 log
.println("expected IllegalArgumentException was thrown => OK");
88 log
.println("try to append the object itself...");
91 oObj
.appendChild(oObj
);
92 log
.println("ERROR: expected IllegalArgumentException was not thrown => FAILED");
94 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
95 log
.println("expected IllegalArgumentException was thrown => OK");
98 tRes
.tested("appendChild()", bOK
);
101 public void _insertChildByIndex(){
104 XMutableTreeNode myNode
= nodeCreator
.createNode("myNodeToInsert");
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());
112 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
113 log
.println("ERROR: could not insert a valid node on index '0': " + ex
.toString());
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");
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");
129 XMutableTreeNode myNode2
= nodeCreator
.createNode("myNodeToInsert2");
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");
136 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
137 log
.println("ERROR: wrong IllegalArgumentException was thrown. Expected is IndexOutOfBoundsException => FAILED");
139 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
140 log
.println("Expected IndexOutOfBoundsException was thrown => OK");
144 log
.println("try to insert the object itself...");
145 oObj
.insertChildByIndex(0, oObj
);
146 log
.println("ERROR: expected IllegalArgumentException was not thrown => FAILED");
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");
155 tRes
.tested("insertChildByIndex()", bOK
);
158 public void _removeChildByIndex(){
160 requiredMethod("insertChildByIndex()");
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");
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");
176 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
177 log
.println("expected IndexOutOfBoundsException was thrown => OK");
179 tRes
.tested("removeChildByIndex()", bOK
);
182 public void _setHasChildrenOnDemand(){
185 log
.println("setHasChildrenOnDemand(true)");
186 oObj
.setHasChildrenOnDemand(true);
188 log
.println("setHasChildrenOnDemand(false)");
189 oObj
.setHasChildrenOnDemand(false);
191 tRes
.tested("setHasChildrenOnDemand()", bOK
);
194 public void _setDisplayValue(){
197 log
.println("setDisplayValue(\"MyTestValue\")");
198 oObj
.setDisplayValue("MyTestValue");
200 log
.println("setDisplayValue(null)");
201 oObj
.setDisplayValue(null);
203 log
.println("oObj.setDisplayValue(oObj)");
204 oObj
.setDisplayValue(oObj
);
206 tRes
.tested("setDisplayValue()", bOK
);
209 public void _setNodeGraphicURL(){
212 log
.println("setNodeGraphicURL(\"MyTestURL\")");
213 oObj
.setNodeGraphicURL("MyTestURL");
215 log
.println("setNodeGraphicURL(null)");
216 oObj
.setNodeGraphicURL(null);
218 tRes
.tested("setNodeGraphicURL()", bOK
);
221 public void _setExpandedGraphicURL(){
224 log
.println("setExpandedGraphicURL(\"myExpandedURL\")");
225 oObj
.setExpandedGraphicURL("myExpandedURL");
227 log
.println("setExpandedGraphicURL(null)");
228 oObj
.setExpandedGraphicURL(null);
230 tRes
.tested("setExpandedGraphicURL()", bOK
);
233 public void _setCollapsedGraphicURL(){
236 log
.println("setCollapsedGraphicURL(\"myCollapsedURL\")");
237 oObj
.setCollapsedGraphicURL("myCollapsedURL");
239 log
.println("setCollapsedGraphicURL(null)");
240 oObj
.setCollapsedGraphicURL(null);
242 tRes
.tested("setCollapsedGraphicURL()", bOK
);
245 public void _DataValue(){
248 log
.println("setDataValue(\"myDataValue\")");
249 oObj
.setDataValue("myDataValue");
251 String sDataValue
= (String
) oObj
.getDataValue();
253 if ( ! sDataValue
.equals("myDataValue")) {
254 log
.println("ERROR: getDataVlaue does not return the value which is inserted before:\n" +
255 "\texpected: myDataValue\n" +
256 "\tgot: " + sDataValue
);
260 log
.println("setDataValue(null)");
261 oObj
.setDataValue(null);
263 Object oDataValue
= oObj
.getDataValue();
264 if ( oDataValue
!= null) {
265 log
.println("ERROR: getDataVlaue does not return the value which is inserted before:\n" +
266 "\texpected: null\n" +
267 "\tgot: " + oDataValue
.toString());
271 log
.println("oObj.setDisplayValue(oObj)");
272 oObj
.setDisplayValue(oObj
);
274 oDataValue
= oObj
.getDataValue();
275 if ( oDataValue
!= null) {
276 log
.println("ERROR: getDataVlaue does not return the value which is inserted before:\n" +
277 "\texpected: " + oObj
.toString() +"\n" +
278 "\tgot: " + oDataValue
.toString());
282 tRes
.tested("DataValue()", bOK
);