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