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
.XTreeNode
;
22 import com
.sun
.star
.uno
.AnyConverter
;
23 import lib
.MultiMethodTest
;
25 import lib
.StatusException
;
28 * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code>
31 * <li><code> getChildAt()</code></li>
32 * <li><code> getChildCount()</code></li>
33 * <li><code> getParent()</code></li>
34 * <li><code> getIndex()</code></li>
35 * <li><code> hasChildrenOnDemand()</code></li>
36 * <li><code> getDisplayValue()</code></li>
37 * <li><code> getNodeGraphicURL()</code></li>
38 * <li><code> getExpandedGraphicURL()</code></li>
39 * <li><code> getCollapsedGraphicURL()</code></li> * </ul> <p>
40 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.awt.tree.XTreeDataModel
44 public class _XTreeNode
extends MultiMethodTest
{
46 public XTreeNode oObj
= null;
48 private int mCount
= 0;
50 String msDisplayValue
= null;
51 String msExpandedGraphicURL
= null;
52 String msCollapsedGraphicURL
= null;
53 String msNodeGraphicURL
= null;
58 msDisplayValue
= (String
) tEnv
.getObjRelation("XTreeNode_DisplayValue");
59 if (msDisplayValue
== null){
60 throw new StatusException(Status
.failed(
61 "Couldn't get relation 'XTreeNode_DisplayValue'"));
64 msExpandedGraphicURL
= (String
) tEnv
.getObjRelation("XTreeNode_ExpandedGraphicURL");
65 if (msExpandedGraphicURL
== null){
66 throw new StatusException(Status
.failed(
67 "Couldn't get relation 'XTreeNode_ExpandedGraphicURL'"));
70 msCollapsedGraphicURL
= (String
) tEnv
.getObjRelation("XTreeNode_CollapsedGraphicURL");
71 if (msCollapsedGraphicURL
== null){
72 throw new StatusException(Status
.failed(
73 "Couldn't get relation 'XTreeNode_CollapsedGraphicURL'"));
76 msNodeGraphicURL
= (String
) tEnv
.getObjRelation("XTreeNode_NodeGraphicURL");
77 if(msNodeGraphicURL
== null){
78 throw new StatusException(Status
.failed(
79 "Couldn't get relation 'XTreeNode_NodeGraphicURL'"));
85 * Gets the title and compares it to the value set in
86 * <code>setTitle</code> method test. <p>
87 * Has <b>OK</b> status is set/get values are equal.
88 * The following method tests are to be completed successfully before :
90 * <li> <code> setTitle </code> </li>
93 public void _getChildAt(){
94 this.requiredMethod("getChildCount()");
97 for (int i
=0; i
< mCount
; i
++){
98 XTreeNode xNode
= null;
100 xNode
= oObj
.getChildAt(i
);
101 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
102 log
.println("ERROR: getChildAt(" + i
+ "): " + ex
.toString());
105 log
.println("ERROR: getChildAt(" + i
+ ") returns null => FAILED");
110 tRes
.tested("getChildAt()", bOK
);
114 public void _getChildCount(){
117 mCount
= oObj
.getChildCount();
118 log
.println("got count '" + mCount
+ "' of children");
120 log
.println("ERROR: got a count < 1. The test object must support more than zero children => FAILED");
123 tRes
.tested("getChildCount()", bOK
);
127 public void _getParent(){
128 this.requiredMethod("getChildAt()");
131 XTreeNode xNode
= null;
133 log
.println("try to getChildAt(0)");
134 xNode
= oObj
.getChildAt(0);
135 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
136 log
.println("ERROR: getChildAt(0): " + ex
.toString());
139 log
.println("try to get parent of children");
141 log
.println("missing xNode");
142 tRes
.tested("getParent()", false);
145 XTreeNode xParrent
= xNode
.getParent();
148 bOK
= oObj
.equals(xParrent
);
149 log
.println("original object and parent should be the same: " + bOK
);
150 tRes
.tested("getParent()", bOK
);
155 public void _getIndex(){
156 this.requiredMethod("getChildAt()");
159 XTreeNode xNode
= null;
161 log
.println("try to getChildAt(0)");
162 xNode
= oObj
.getChildAt(0);
163 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
164 log
.println("ERROR: getChildAt(0): " + ex
.toString());
167 log
.println("try to get index from child...");
168 int index
= oObj
.getIndex(xNode
);
171 log
.println("ERROR: getIndex() does not return '0' => FAILED");
175 tRes
.tested("getIndex()", bOK
);
179 public void _hasChildrenOnDemand(){
183 bOK
= oObj
.hasChildrenOnDemand();
184 tRes
.tested("hasChildrenOnDemand()", bOK
);
188 public void _getDisplayValue(){
191 String DisplayValue
= null;
192 Object dispVal
= oObj
.getDisplayValue();
195 DisplayValue
= AnyConverter
.toString(dispVal
);
196 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
197 log
.println("ERROR: could not convert the returned object of 'getDisplayValue()' " +
198 "to String with AnyConverter: " + ex
.toString());
201 if ( ! this.msDisplayValue
.equals(DisplayValue
)){
202 log
.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
203 "\tExpected: " + this.msDisplayValue
+"\n" +
204 "\tGot: " + DisplayValue
);
208 tRes
.tested("getDisplayValue()", bOK
);
212 public void _getNodeGraphicURL(){
215 String graphicURL
= oObj
.getNodeGraphicURL();
217 if ( ! this.msNodeGraphicURL
.equals(graphicURL
)){
218 log
.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
219 "\tExpected: " + this.msNodeGraphicURL
+"\n" +
220 "\tGot: " + graphicURL
);
223 tRes
.tested("getNodeGraphicURL()", bOK
);
227 public void _getExpandedGraphicURL(){
230 String ExpandedGraphicURL
= oObj
.getExpandedGraphicURL();
232 if ( ! this.msExpandedGraphicURL
.equals(ExpandedGraphicURL
)){
233 log
.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
234 "\tExpected: " + this.msExpandedGraphicURL
+"\n" +
235 "\tGot: " + ExpandedGraphicURL
);
239 tRes
.tested("getExpandedGraphicURL()", bOK
);
243 public void _getCollapsedGraphicURL(){
247 String CollapsedGraphicURL
= oObj
.getCollapsedGraphicURL();
249 if ( ! this.msCollapsedGraphicURL
.equals(CollapsedGraphicURL
)){
250 log
.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
251 "\tExpected: " + this.msCollapsedGraphicURL
+"\n" +
252 "\tGot: " + CollapsedGraphicURL
);
256 tRes
.tested("getCollapsedGraphicURL()", bOK
);