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