Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / tree / _XTreeNode.java
blob498a9ecb70197baea5ec1bff0ddfab0a42fcf697
1 /*
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 .
19 package ifc.awt.tree;
21 import com.sun.star.awt.tree.XTreeNode;
22 import com.sun.star.uno.AnyConverter;
23 import lib.MultiMethodTest;
24 import lib.Status;
25 import lib.StatusException;
27 /**
28 * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code>
29 * interface methods :
30 * <ul>
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;
56 @Override
57 public void before(){
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'"));
84 /**
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 :
89 * <ul>
90 * <li> <code> setTitle </code> </li>
91 * </ul>
93 public void _getChildAt(){
94 this.requiredMethod("getChildCount()");
95 boolean bOK = true;
97 for (int i=0; i < mCount ; i++){
98 XTreeNode xNode = null;
99 try {
100 xNode = oObj.getChildAt(i);
101 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
102 log.println("ERROR: getChildAt(" + i + "): " + ex.toString());
104 if (xNode == null){
105 log.println("ERROR: getChildAt(" + i + ") returns null => FAILED");
106 bOK = false;
110 tRes.tested("getChildAt()", bOK);
114 public void _getChildCount(){
116 boolean bOK = true;
117 mCount = oObj.getChildCount();
118 log.println("got count '" + mCount + "' of children");
119 if (mCount < 1 ) {
120 log.println("ERROR: got a count < 1. The test object must be support morw then zero children => FAILED");
121 bOK = false;
123 tRes.tested("getChildCount()", bOK);
127 public void _getParent(){
128 this.requiredMethod("getChildAt()");
130 boolean bOK = true;
131 XTreeNode xNode = null;
132 try {
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()");
152 boolean bOK = true;
153 XTreeNode xNode = null;
154 try {
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);
164 if (index != 0){
165 log.println("ERROR: getIndex() does not return '0' => FAILED");
166 bOK = false;
169 tRes.tested("getIndex()", bOK);
173 public void _hasChildrenOnDemand(){
175 boolean bOK = true;
177 bOK = oObj.hasChildrenOnDemand();
178 tRes.tested("hasChildrenOnDemand()", bOK);
182 public void _getDisplayValue(){
184 boolean bOK = true;
185 String DisplayValue = null;
186 Object dispVal = oObj.getDisplayValue();
188 try {
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);
199 bOK = false;
202 tRes.tested("getDisplayValue()", bOK);
206 public void _getNodeGraphicURL(){
208 boolean bOK = true;
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);
215 bOK = false;
217 tRes.tested("getNodeGraphicURL()", bOK);
221 public void _getExpandedGraphicURL(){
223 boolean bOK = true;
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);
230 bOK = false;
233 tRes.tested("getExpandedGraphicURL()", bOK);
237 public void _getCollapsedGraphicURL(){
239 boolean bOK = true;
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);
247 bOK = false;
250 tRes.tested("getCollapsedGraphicURL()", bOK);