Update git submodules
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / tree / _XTreeControl.java
blobe3c124d0a668706c1d8c0eb9193fafee57483ade
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.ExpandVetoException;
22 import com.sun.star.awt.tree.TreeExpansionEvent;
23 import com.sun.star.awt.tree.XMutableTreeNode;
24 import com.sun.star.awt.tree.XTreeControl;
25 import com.sun.star.awt.tree.XTreeEditListener;
26 import com.sun.star.awt.tree.XTreeExpansionListener;
27 import com.sun.star.awt.tree.XTreeNode;
28 import com.sun.star.lang.EventObject;
29 import com.sun.star.util.VetoException;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
34 /**
35 * Testing <code>com.sun.star.awt.tree.XTreeControl</code>
36 * interface methods :
37 * <ul>
38 * <li><code> isNodeExpanded()</code></li>
39 * <li><code> isNodeCollapsed()</code></li>
40 * <li><code> makeNodeVisible()</code></li>
41 * <li><code> isNodeVisible()</code></li>
42 * <li><code> expandNode()</code></li>
43 * <li><code> collapseNode()</code></li>
44 * <li><code> addTreeExpansionListener()</code></li>
45 * <li><code> removeTreeExpansionListener()</code></li>
46 * <li><code> getNodeForLocation()</code></li>
47 * <li><code> getClosestNodeForLocation()</code></li>
48 * <li><code> isEditing()</code></li>
49 * <li><code> stopEditing()</code></li>
50 * <li><code> cancelEditing()</code></li>
51 * <li><code> startEditingAtNode()</code></li>
52 * <li><code> addTreeEditListener()</code></li>
53 * <li><code> removeTreeEditListener()</code></li>
54 * <li><code> DefaultExpandedGraphicURL()</code></li>
55 * <li><code> DefaultCollapsedGraphicURL()</code></li>* </ul> <p>
56 * Test is <b> NOT </b> multithread compliant. <p>
58 * @see com.sun.star.awt.tree.XTreeControl
60 public class _XTreeControl extends MultiMethodTest {
62 public XTreeControl oObj = null;
64 private XMutableTreeNode mXNode = null;
66 XTreeExpansionListener mTreeExpansionListener1 = new TreeExpansionListenerImpl1();
68 XTreeExpansionListener mTreeExpansionListener2 = new TreeExpansionListenerImpl2();
70 XTreeEditListener mTreeEditListener1 = new TreeEditListenerImpl1();
72 XTreeEditListener mTreeEditListener2 = new TreeEditListenerImpl2();
74 boolean mTreeExpanded1 = false;
75 boolean mTreeExpanding1 = false;
76 boolean mTreeCollapsed1 = false;
77 boolean mTreeCollapsing1 = false;
79 boolean mTreeExpanded2 = false;
80 boolean mTreeExpanding2 = false;
81 boolean mTreeCollapsed2 = false;
82 boolean mTreeCollapsing2 = false;
84 public interface XTreeDataModelListenerEvent{
85 void fireEvent();
88 public class TreeExpansionListenerImpl1 implements XTreeExpansionListener{
89 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent) {
90 log.println("event at ExpansionListener 1: requestChildNodes");
93 public void treeExpanding(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
94 log.println("event at ExpansionListener 1: treeExpanding");
95 mTreeExpanding1 = true;
98 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
99 log.println("event at ExpansionListener 1: treeCollapsing");
100 mTreeCollapsing1 = true;
103 public void treeExpanded(TreeExpansionEvent treeExpansionEvent) {
104 log.println("event at ExpansionListener 1: treeExpanded");
105 mTreeExpanded1 = true;
108 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) {
109 log.println("event at ExpansionListener 1: treeCollapsed");
110 mTreeCollapsed1 = true;
113 public void disposing(EventObject eventObject) {
114 log.println("event at ExpansionListener 1: disposing");
118 public class TreeExpansionListenerImpl2 implements XTreeExpansionListener{
119 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent) {
120 log.println("event at ExpansionListener 2: requestChildNodes");
123 public void treeExpanding(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
124 log.println("event at ExpansionListener 2: treeExpanding");
125 mTreeExpanding2 = true;
128 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
129 log.println("event at ExpansionListener 2: treeCollapsing");
130 mTreeCollapsing2 = true;
133 public void treeExpanded(TreeExpansionEvent treeExpansionEvent) {
134 log.println("event at ExpansionListener 2: treeExpanded");
135 mTreeExpanded2 = true;
138 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) {
139 log.println("event at ExpansionListener 2: treeCollapsed");
140 mTreeCollapsed2 = true;
143 public void disposing(EventObject eventObject) {
144 log.println("event at ExpansionListener 2: disposing");
149 public class TreeEditListenerImpl1 implements XTreeEditListener{
150 public void nodeEditing(XTreeNode xTreeNode) throws VetoException {
151 log.println("event at EditListener 1: nodeEditing");
154 public void nodeEdited(XTreeNode xTreeNode, String string) {
155 log.println("event at EditListener 1: nodeEdited");
158 public void disposing(EventObject eventObject) {
159 log.println("event at EditListener 1: disposing");
163 public class TreeEditListenerImpl2 implements XTreeEditListener{
164 public void nodeEditing(XTreeNode xTreeNode) throws VetoException {
165 log.println("event at EditListener 2: nodeEditing");
168 public void nodeEdited(XTreeNode xTreeNode, String string) {
169 log.println("event at EditListener 2: nodeEdited");
172 public void disposing(EventObject eventObject) {
173 log.println("event at EditListener 2: disposing");
177 private void resetTreeExpandingListener(){
178 mTreeExpanded1 = false;
179 mTreeExpanded2 = false;
180 mTreeCollapsed1 = false;
181 mTreeCollapsed2 = false;
182 mTreeExpanding1 = false;
183 mTreeExpanding2 = false;
184 mTreeCollapsing1 = false;
185 mTreeCollapsing2 = false;
188 @Override
189 public void before(){
190 mXNode = (XMutableTreeNode) tEnv.getObjRelation("XTreeControl_Node");
191 if (mXNode == null) {
192 throw new StatusException(Status.failed("ERROR: could not get object relation 'XTreeControl_Node'"));
196 public void _isNodeExpanded() {
198 boolean bOK = true;
200 boolean isExpanded = false;
202 try {
203 isExpanded = oObj.isNodeExpanded(mXNode);
204 log.println("node is expanded: " + isExpanded);
206 } catch (com.sun.star.lang.IllegalArgumentException ex) {
207 bOK = false;
208 log.println("ERROR: could not query for 'isNodeExpanded()': " + ex.toString());
211 if (isExpanded)
212 try {
214 log.println("try to collapse node...");
215 oObj.collapseNode(mXNode);
217 } catch (ExpandVetoException ex) {
218 bOK = false;
219 log.println("ERROR: could not collapse node: " + ex.toString());
220 } catch (com.sun.star.lang.IllegalArgumentException ex) {
221 bOK = false;
222 log.println("ERROR: could not collapse node: " + ex.toString());
224 else
225 try {
227 log.println("try to expand node...");
228 oObj.expandNode(mXNode);
230 } catch (ExpandVetoException ex) {
231 bOK = false;
232 log.println("ERROR: could not expand node: " + ex.toString());
233 } catch (com.sun.star.lang.IllegalArgumentException ex) {
234 bOK = false;
235 log.println("ERROR: could not expand node: " + ex.toString());
238 try {
240 boolean isAlsoExpanded = oObj.isNodeExpanded(mXNode);
242 bOK &= (isExpanded != isAlsoExpanded);
244 log.println("node is expanded: " + isAlsoExpanded + " => " + bOK);
246 } catch (com.sun.star.lang.IllegalArgumentException ex) {
247 bOK = false;
248 log.println("ERROR: could not query for 'isNodeExpanded()': " + ex.toString());
251 tRes.tested("isNodeExpanded()", bOK);
254 public void _isNodeCollapsed(){
256 boolean bOK = true;
258 boolean isCollapsed = false;
260 try {
261 isCollapsed = oObj.isNodeCollapsed(mXNode);
262 log.println("node is Collapsed: " + isCollapsed);
264 } catch (com.sun.star.lang.IllegalArgumentException ex) {
265 bOK = false;
266 log.println("ERROR: could not query for 'isNodeCollapsed()': " + ex.toString());
269 if ( ! isCollapsed)
270 try {
272 log.println("try to collapse node...");
273 oObj.collapseNode(mXNode);
275 } catch (ExpandVetoException ex) {
276 bOK = false;
277 log.println("ERROR: could not collapse node: " + ex.toString());
278 } catch (com.sun.star.lang.IllegalArgumentException ex) {
279 bOK = false;
280 log.println("ERROR: could not collapse node: " + ex.toString());
282 else
283 try {
285 log.println("try to expand node...");
286 oObj.expandNode(mXNode);
288 } catch (ExpandVetoException ex) {
289 bOK = false;
290 log.println("ERROR: could not expand node: " + ex.toString());
291 } catch (com.sun.star.lang.IllegalArgumentException ex) {
292 bOK = false;
293 log.println("ERROR: could not expand node: " + ex.toString());
296 try {
298 boolean isAlsoCollapsed = oObj.isNodeCollapsed(mXNode);
300 bOK &= (isCollapsed != isAlsoCollapsed);
302 log.println("node is Collapsed: " + isAlsoCollapsed + " => " + bOK);
304 } catch (com.sun.star.lang.IllegalArgumentException ex) {
305 bOK = false;
306 log.println("ERROR: could not query for 'isNodeCollapsed()': " + ex.toString());
309 tRes.tested("isNodeCollapsed()", bOK);
312 public void _makeNodeVisible(){
314 boolean bOK = true;
315 try {
317 oObj.makeNodeVisible(mXNode);
318 } catch (ExpandVetoException ex) {
319 bOK = false;
320 log.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex.toString());
321 } catch (com.sun.star.lang.IllegalArgumentException ex) {
322 bOK = false;
323 log.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex.toString());
325 try {
327 bOK &= oObj.isNodeVisible(mXNode);
328 } catch (com.sun.star.lang.IllegalArgumentException ex) {
329 bOK = false;
330 log.println("ERROR: could not call method 'isNodeVisible()' successfully: " + ex.toString());
333 tRes.tested("makeNodeVisible()", bOK);
336 public void _isNodeVisible(){
338 this.requiredMethod("makeNodeVisible()");
340 boolean bOK = true;
341 log.println("since required method 'makeNodeVisible()' uses method 'isNodeVisible()' this test is ok.");
342 tRes.tested("isNodeVisible()", bOK);
346 public void _expandNode(){
348 this.requiredMethod("isNodeExpanded()");
350 boolean bOK = true;
351 log.println("since required method 'isnodeExpanded()' uses method 'expandNode()' this test is ok.");
352 tRes.tested("expandNode()", bOK);
356 public void _collapseNode(){
358 this.requiredMethod("isNodeCollapsed()");
360 boolean bOK = true;
361 log.println("since required method 'isnodeCollapsed()' uses method 'expandNode()' this test is ok.");
362 tRes.tested("collapseNode()", bOK);
366 public void _addTreeExpansionListener(){
368 boolean bOK = true;
370 log.println("collapse Node to get an initial status...");
371 try {
373 oObj.collapseNode(mXNode);
374 } catch (ExpandVetoException ex) {
375 bOK = false;
376 log.println("ERROR: could not collapse node: " + ex.toString());
377 } catch (com.sun.star.lang.IllegalArgumentException ex) {
378 bOK = false;
379 log.println("ERROR: could not collapse node: " + ex.toString());
382 log.println("add mTreeExpansionListener1...");
383 oObj.addTreeExpansionListener(mTreeExpansionListener1);
385 log.println("add mTreeExpansionListener2");
386 oObj.addTreeExpansionListener(mTreeExpansionListener2);
388 resetTreeExpandingListener();
390 log.println("expand Node...");
391 try {
393 oObj.expandNode(mXNode);
395 } catch (ExpandVetoException ex) {
396 bOK = false;
397 log.println("ERROR: could not expand node: " + ex.toString());
398 } catch (com.sun.star.lang.IllegalArgumentException ex) {
399 bOK = false;
400 log.println("ERROR: could not expand node: " + ex.toString());
403 bOK &= mTreeExpanded1 & mTreeExpanded2 & ! mTreeCollapsed1 & ! mTreeCollapsed2
404 & mTreeExpanding1 & mTreeExpanding2 & ! mTreeCollapsing1 & ! mTreeCollapsing2;
406 resetTreeExpandingListener();
408 log.println("collapse Node...");
409 try {
411 oObj.collapseNode(mXNode);
412 } catch (ExpandVetoException ex) {
413 bOK = false;
414 log.println("ERROR: could not collapse node: " + ex.toString());
415 } catch (com.sun.star.lang.IllegalArgumentException ex) {
416 bOK = false;
417 log.println("ERROR: could not collapse node: " + ex.toString());
420 bOK &= ! mTreeExpanded1 & ! mTreeExpanded2 & mTreeCollapsed1 & mTreeCollapsed2
421 & ! mTreeExpanding1 & ! mTreeExpanding2 & mTreeCollapsing1 & mTreeCollapsing2;
423 tRes.tested("addTreeExpansionListener()", bOK);
427 public void _removeTreeExpansionListener(){
429 this.requiredMethod("addTreeExpansionListener()");
431 boolean bOK = true;
433 log.println("collapse Node to get an initial status...");
434 try {
436 oObj.collapseNode(mXNode);
437 } catch (ExpandVetoException ex) {
438 bOK = false;
439 log.println("ERROR: could not collapse node: " + ex.toString());
440 } catch (com.sun.star.lang.IllegalArgumentException ex) {
441 bOK = false;
442 log.println("ERROR: could not collapse node: " + ex.toString());
445 resetTreeExpandingListener();
447 log.println("remove mTreeExpansionListener2 ...");
448 oObj.removeTreeExpansionListener(mTreeExpansionListener2);
450 log.println("expand Node...");
451 try {
453 oObj.expandNode(mXNode);
455 } catch (ExpandVetoException ex) {
456 bOK = false;
457 log.println("ERROR: could not expand node: " + ex.toString());
458 } catch (com.sun.star.lang.IllegalArgumentException ex) {
459 bOK = false;
460 log.println("ERROR: could not expand node: " + ex.toString());
463 bOK &= mTreeExpanded1 & ! mTreeExpanded2 & ! mTreeCollapsed1 & ! mTreeCollapsed2
464 & mTreeExpanding1 & ! mTreeExpanding2 & ! mTreeCollapsing1 & ! mTreeCollapsing2;
466 resetTreeExpandingListener();
468 log.println("collapse Node...");
469 try {
471 oObj.collapseNode(mXNode);
472 } catch (ExpandVetoException ex) {
473 bOK = false;
474 log.println("ERROR: could not collapse node: " + ex.toString());
475 } catch (com.sun.star.lang.IllegalArgumentException ex) {
476 bOK = false;
477 log.println("ERROR: could not collapse node: " + ex.toString());
480 bOK &= ! mTreeExpanded1 & ! mTreeExpanded2 & mTreeCollapsed1 & ! mTreeCollapsed2
481 & ! mTreeExpanding1 & ! mTreeExpanding2 & mTreeCollapsing1 & ! mTreeCollapsing2;
483 log.println("remove mTreeExpansionListener2 ...");
484 oObj.removeTreeExpansionListener(mTreeExpansionListener2);
486 tRes.tested("removeTreeExpansionListener()", bOK);
490 public void _getNodeForLocation(){
492 boolean bOK = false;
495 tRes.tested("getNodeForLocation()", bOK);
499 public void _getClosestNodeForLocation(){
501 boolean bOK = false;
503 log.println("try to get Node for location 100,100");
504 XTreeNode myNode = oObj.getClosestNodeForLocation(100,100);
506 bOK &= (myNode != null);
508 tRes.tested("getClosestNodeForLocation()", bOK);
512 public void _isEditing(){
514 boolean bOK = false;
516 log.println("not ready because of i78701");
518 tRes.tested("isEditing()", bOK);
522 public void _stopEditing(){
524 boolean bOK = false;
525 log.println("not ready because of i78701");
528 tRes.tested("stopEditing()", bOK);
532 public void _cancelEditing(){
534 boolean bOK = false;
536 log.println("not ready because of i78701");
538 tRes.tested("cancelEditing()", bOK);
542 public void _startEditingAtNode(){
544 boolean bOK = false;
546 log.println("not ready because of i78701");
548 tRes.tested("startEditingAtNode()", bOK);
552 public void _addTreeEditListener(){
554 boolean bOK = true;
556 log.println("add EditListener 1...");
557 oObj.addTreeEditListener(mTreeEditListener1);
559 log.println("add EditListener 2...");
560 oObj.addTreeEditListener(mTreeEditListener2);
562 try {
563 oObj.startEditingAtNode(mXNode);
564 } catch (com.sun.star.lang.IllegalArgumentException ex) {
565 log.println("ERROR: could not start editing at node: " + ex.toString());
566 bOK = false;
569 log.println("not ready because of i78701");
570 bOK = false;
573 tRes.tested("addTreeEditListener()", bOK);
577 public void _removeTreeEditListener(){
579 boolean bOK = false;
581 log.println("not ready because of i78701");
583 tRes.tested("removeTreeEditListener()", bOK);
587 public void _DefaultExpandedGraphicURL(){
589 boolean bOK = true;
591 String current = oObj.getDefaultExpandedGraphicURL();
592 log.println("current DefaultExpandedGraphicURL: " + current);
594 String changeUrl = null;
596 if (current.equals("private:graphicrepository/sd/res/triangle_right.png"))
597 changeUrl = "private:graphicrepository/sd/res/triangle_down.png";
598 else changeUrl = "private:graphicrepository/sd/res/triangle_right.png";
600 log.println("try to set '" + changeUrl + "' as new DefaultExpandedGraphicURL");
602 oObj.setDefaultExpandedGraphicURL(changeUrl);
604 String newUrl = oObj.getDefaultExpandedGraphicURL();
606 log.println("new DefaultExpandedGraphicURL: " + newUrl);
608 bOK &= ! newUrl.equals(current);
610 tRes.tested("DefaultExpandedGraphicURL()", bOK);
614 public void _DefaultCollapsedGraphicURL(){
616 boolean bOK = true;
618 String current = oObj.getDefaultCollapsedGraphicURL();
619 log.println("current DefaultCollapsedGraphicURL: " + current);
621 String changeUrl = null;
623 if (current.equals("private:graphicrepository/sd/res/triangle_right.png"))
624 changeUrl = "private:graphicrepository/sd/res/triangle_down.png";
625 else changeUrl = "private:graphicrepository/sd/res/triangle_right.png";
627 log.println("try to set '" + changeUrl + "' as new DefaultCollapsedGraphicURL");
628 oObj.setDefaultCollapsedGraphicURL(changeUrl);
630 String newUrl = oObj.getDefaultCollapsedGraphicURL();
632 log.println("new DefaultCollapsedGraphicURL: " + newUrl);
634 bOK &= ! newUrl.equals(current);
636 tRes.tested("DefaultCollapsedGraphicURL()", bOK);