Update git submodules
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / tree / _XMutableTreeNode.java
blob76c7e6cac8de22e58c6186baa95843ee1029594a
1 /*
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 .
19 package ifc.awt.tree;
21 import com.sun.star.awt.tree.XMutableTreeNode;
22 import lib.MultiMethodTest;
23 import lib.Status;
24 import lib.StatusException;
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>
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);
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'"));
64 public void _appendChild(){
65 boolean bOK = true;
67 log.println("try to append a valid node...");
69 XMutableTreeNode myNode = nodeCreator.createNode("myNodeToAppend");
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;
78 log.println("try to append the node a second time...");
79 try {
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");
88 log.println("try to append the object itself...");
89 try {
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");
98 tRes.tested("appendChild()", bOK);
101 public void _insertChildByIndex(){
102 boolean bOK = true;
104 XMutableTreeNode myNode = nodeCreator.createNode("myNodeToInsert");
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;
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;
129 XMutableTreeNode myNode2 = nodeCreator.createNode("myNodeToInsert2");
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");
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;
155 tRes.tested("insertChildByIndex()", bOK);
158 public void _removeChildByIndex(){
160 requiredMethod("insertChildByIndex()");
161 boolean bOK = true;
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;
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");
179 tRes.tested("removeChildByIndex()", bOK);
182 public void _setHasChildrenOnDemand(){
183 boolean bOK = true;
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(){
195 boolean bOK = true;
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(){
210 boolean bOK = true;
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(){
222 boolean bOK = true;
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(){
234 boolean bOK = true;
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(){
246 boolean bOK = true;
248 log.println("setDataValue(\"myDataValue\")");
249 oObj.setDataValue("myDataValue");
251 String sDataValue = (String) oObj.getDataValue();
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;
260 log.println("setDataValue(null)");
261 oObj.setDataValue(null);
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;
271 log.println("oObj.setDisplayValue(oObj)");
272 oObj.setDisplayValue(oObj);
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;
282 tRes.tested("DataValue()", bOK);