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