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_DisplayVlaue'"));
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 be support morw then 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 parrent of children");
140 XTreeNode xParrent
= xNode
.getParent();
143 bOK
= oObj
.equals(xParrent
);
144 log
.println("original object and parrent should be the same: " + bOK
);
145 tRes
.tested("getParent()", bOK
);
149 public void _getIndex(){
150 this.requiredMethod("getChildAt()");
153 XTreeNode xNode
= null;
155 log
.println("try to getChildAt(0)");
156 xNode
= oObj
.getChildAt(0);
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
158 log
.println("ERROR: getChildAt(0): " + ex
.toString());
161 log
.println("try to get index from child...");
162 int index
= oObj
.getIndex(xNode
);
165 log
.println("ERROR: getIndex() does not return '0' => FAILED");
169 tRes
.tested("getIndex()", bOK
);
173 public void _hasChildrenOnDemand(){
177 bOK
= oObj
.hasChildrenOnDemand();
178 tRes
.tested("hasChildrenOnDemand()", bOK
);
182 public void _getDisplayValue(){
185 String DisplayValue
= null;
186 Object dispVal
= oObj
.getDisplayValue();
189 DisplayValue
= AnyConverter
.toString(dispVal
);
190 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
191 log
.println("ERROR: could not convert the returned object of 'getDisplyValue()' " +
192 "to String with AnyConverter: " + ex
.toString());
195 if ( ! this.msDisplayValue
.equals(DisplayValue
)){
196 log
.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
197 "\tExpected: " + this.msDisplayValue
+"\n" +
198 "\tGot: " + DisplayValue
);
202 tRes
.tested("getDisplayValue()", bOK
);
206 public void _getNodeGraphicURL(){
209 String graphicURL
= oObj
.getNodeGraphicURL();
211 if ( ! this.msNodeGraphicURL
.equals(graphicURL
)){
212 log
.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
213 "\tExpected: " + this.msNodeGraphicURL
+"\n" +
214 "\tGot: " + graphicURL
);
217 tRes
.tested("getNodeGraphicURL()", bOK
);
221 public void _getExpandedGraphicURL(){
224 String ExpandedGraphicURL
= oObj
.getExpandedGraphicURL();
226 if ( ! this.msExpandedGraphicURL
.equals(ExpandedGraphicURL
)){
227 log
.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
228 "\tExpected: " + this.msExpandedGraphicURL
+"\n" +
229 "\tGot: " + ExpandedGraphicURL
);
233 tRes
.tested("getExpandedGraphicURL()", bOK
);
237 public void _getCollapsedGraphicURL(){
241 String CollapsedGraphicURL
= oObj
.getCollapsedGraphicURL();
243 if ( ! this.msCollapsedGraphicURL
.equals(CollapsedGraphicURL
)){
244 log
.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
245 "\tExpected: " + this.msCollapsedGraphicURL
+"\n" +
246 "\tGot: " + CollapsedGraphicURL
);
250 tRes
.tested("getCollapsedGraphicURL()", bOK
);