merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / view / _XSelectionSupplier.java
bloba4f9c777a87f6de547df8889ba54f22eaced45de
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSelectionSupplier.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.view;
33 import com.sun.star.lang.EventObject;
34 import com.sun.star.view.XSelectionChangeListener;
35 import com.sun.star.view.XSelectionSupplier;
36 import java.util.Comparator;
37 import lib.MultiMethodTest;
38 import lib.Status;
39 import lib.StatusException;
42 /**
43 * Testing <code>com.sun.star.view.XSelectionSupplier</code>
44 * interface methods :
45 * <ul>
46 * <li><code> select()</code></li>
47 * <li><code> getSelection()</code></li>
48 * <li><code> addSelectionChangeListener()</code></li>
49 * <li><code> removeSelectionChangeListener()</code></li>
50 * </ul>
51 * This test needs the following object relations :
52 * <ul>
53 * <li> <code>'Selections'</code> of type <code>Object[]</code> :
54 * the array of the instances which can be selected.</li>
55 * <li> <code>'Comparer'</code> of type <code>Comparator</code> :
56 * the interface for comparing of selected instances</li>
57 * <ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.view.XSelectionSupplier
61 public class _XSelectionSupplier extends MultiMethodTest {
63 public XSelectionSupplier oObj = null;
64 public boolean selectionChanged = false;
65 Object[] selections = null;
66 Comparator ObjCompare = null;
68 protected void before() {
69 selections = (Object[])tEnv.getObjRelation("Selections");
70 if (selections == null) {
71 throw new StatusException(Status.failed(
72 "Couldn't get relation 'Selections'"));
75 ObjCompare = (Comparator)tEnv.getObjRelation("Comparer");
78 protected void after() {
79 disposeEnvironment();
82 /**
83 * Listener implementation which just set flag when listener
84 * method is called.
86 public class MyChangeListener implements XSelectionChangeListener {
87 public void disposing( EventObject oEvent ) {}
88 public void selectionChanged(EventObject ev) {
89 log.println("listener called");
90 selectionChanged = true;
95 XSelectionChangeListener listener = new MyChangeListener();
97 /**
98 * Test adds listener to the object, then selects first and
99 * then second instances to be sure that selection was changed.<p>
100 * Has <b>OK</b> status if selection lisener was called.
102 public void _addSelectionChangeListener(){
103 boolean res = true;
104 try {
105 selectionChanged = false;
106 oObj.addSelectionChangeListener(listener);
107 oObj.select(selections[0]);
108 oObj.select(selections[1]);
109 res = selectionChanged;
110 } catch (com.sun.star.lang.IllegalArgumentException ex) {
111 log.println("Exception occured during addSelectionChangeListener()");
112 ex.printStackTrace(log);
113 res = false;
115 tRes.tested("addSelectionChangeListener()", res);
119 * Selects an instance from relation 'First'. <p>
120 * Has <b> OK </b> status if no exceptions were thrown. <p>
122 public void _select() {
123 boolean res = true;
124 boolean locRes = true;
125 boolean compRes = true;
126 Object oldSelection = null;
127 try {
128 for(int i = 0; i < selections.length; i++) {
129 oldSelection = oObj.getSelection();
130 locRes = oObj.select(selections[i]);
131 log.println("select #" + i + ": " + locRes);
132 Object curSelection = oObj.getSelection();
133 if (locRes) {
135 if (ObjCompare != null) {
136 ObjCompare.compare(selections[i], curSelection);
137 } else {
138 compRes = util.ValueComparer.equalValue(selections[i], curSelection);
140 log.println("selected object and current selection are equal: "+compRes);
141 if (!compRes) {
142 if ((selections[i]) instanceof Object[]){
143 if (((Object[])selections[i])[0] instanceof Integer) {
144 log.println("Getting: "+((Integer) ((Object[])curSelection)[0]).intValue());
145 log.println("Expected: "+((Integer) ((Object[])selections[i])[0]).intValue());
149 res &= compRes;
150 } else {
151 compRes = util.ValueComparer.equalValue(curSelection, oldSelection);
152 log.println("previous selection and current selection are equal: "+compRes);
153 res &= compRes;
156 } catch (com.sun.star.lang.IllegalArgumentException ex) {
157 log.println("Exception occured during select()");
158 ex.printStackTrace(log);
159 res = false;
162 tRes.tested("select()", res);
166 * Test removes listener, then selects first and
167 * then second instances to be sure that selection was changed.<p>
168 * Has <b>OK</b> status if selection lisener was not called.
169 * The following method tests are to be completed successfully before :
170 * <ul>
171 * <li> <code> addSelectionChangeListener() </code> : to have
172 * the listener added. </li>
173 * </ul>
175 public void _removeSelectionChangeListener() {
176 boolean res = false;
177 requiredMethod("addSelectionChangeListener()");
178 try {
179 selectionChanged = false;
180 oObj.removeSelectionChangeListener(listener);
181 oObj.select(selections[0]);
182 oObj.select(selections[1]);
183 res = !selectionChanged;
184 } catch (com.sun.star.lang.IllegalArgumentException ex) {
185 log.println("Exception occured during removeSelectionChangeListener()");
186 ex.printStackTrace(log);
187 res = false;
189 tRes.tested("removeSelectionChangeListener()", res);
193 * First test changes selection of the object : if nothing is
194 * currently selected or first instance ('First' relation) is
195 * selected then selects second instance; if second instance
196 * is currently selected then the first instance is selected. <p>
197 * Then <code>getSelection</code> is called and values set and
198 * get are compared. Comparison has some special cases. For
199 * example if selection is a Cell, then the values contained
200 * in cells are compared. <p>
201 * Has <b>OK</b> status if selection changed properly.
203 public void _getSelection() {
204 requiredMethod("select()");
205 tRes.tested("getSelection()", true);
208 } // finish class _XSelectionSupplier