tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / view / _XSelectionSupplier.java
blobcc6bc4120a7c401e9f8e595b98123cc2f02f3d8e
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.view;
21 import com.sun.star.lang.EventObject;
22 import com.sun.star.view.XSelectionChangeListener;
23 import com.sun.star.view.XSelectionSupplier;
24 import java.util.Comparator;
25 import lib.MultiMethodTest;
26 import lib.Status;
27 import lib.StatusException;
30 /**
31 * Testing <code>com.sun.star.view.XSelectionSupplier</code>
32 * interface methods :
33 * <ul>
34 * <li><code> select()</code></li>
35 * <li><code> getSelection()</code></li>
36 * <li><code> addSelectionChangeListener()</code></li>
37 * <li><code> removeSelectionChangeListener()</code></li>
38 * </ul>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'Selections'</code> of type <code>Object[]</code> :
42 * the array of the instances which can be selected.</li>
43 * <li> <code>'Comparer'</code> of type <code>Comparator</code> :
44 * the interface for comparing of selected instances</li>
45 * <ul> <p>
46 * Test is <b> NOT </b> multithread compliant. <p>
47 * @see com.sun.star.view.XSelectionSupplier
49 public class _XSelectionSupplier extends MultiMethodTest {
51 public XSelectionSupplier oObj = null;
52 public boolean selectionChanged = false;
53 Object[] selections = null;
54 Comparator<Object> ObjCompare = null;
56 @SuppressWarnings("unchecked")
57 @Override
58 protected void before() {
59 selections = (Object[])tEnv.getObjRelation("Selections");
60 if (selections == null) {
61 throw new StatusException(Status.failed(
62 "Couldn't get relation 'Selections'"));
65 ObjCompare = (Comparator<Object>)tEnv.getObjRelation("Comparer");
68 @Override
69 protected void after() {
70 disposeEnvironment();
73 /**
74 * Listener implementation which just set flag when listener
75 * method is called.
77 public class MyChangeListener implements XSelectionChangeListener {
78 public void disposing( EventObject oEvent ) {}
79 public void selectionChanged(EventObject ev) {
80 log.println("listener called");
81 selectionChanged = true;
86 XSelectionChangeListener listener = new MyChangeListener();
88 /**
89 * Test adds listener to the object, then selects first and
90 * then second instances to be sure that selection was changed.<p>
91 * Has <b>OK</b> status if selection listener was called.
93 public void _addSelectionChangeListener(){
94 boolean res = true;
95 try {
96 selectionChanged = false;
97 oObj.addSelectionChangeListener(listener);
98 oObj.select(selections[0]);
99 oObj.select(selections[1]);
100 res = selectionChanged;
101 } catch (com.sun.star.lang.IllegalArgumentException ex) {
102 log.println("Exception occurred during addSelectionChangeListener()");
103 ex.printStackTrace(log);
104 res = false;
106 tRes.tested("addSelectionChangeListener()", res);
110 * Selects an instance from relation 'First'. <p>
111 * Has <b> OK </b> status if no exceptions were thrown. <p>
113 public void _select() {
114 boolean res = true;
115 boolean locRes = true;
116 boolean compRes = true;
117 Object oldSelection = null;
118 try {
119 for(int i = 0; i < selections.length; i++) {
120 oldSelection = oObj.getSelection();
121 locRes = oObj.select(selections[i]);
122 log.println("select #" + i + ": " + locRes);
123 Object curSelection = oObj.getSelection();
124 if (locRes) {
126 if (ObjCompare != null) {
127 compRes = ObjCompare.compare(selections[i], curSelection) == 0;
128 } else {
129 compRes = util.ValueComparer.equalValue(selections[i], curSelection);
131 log.println("selected object and current selection are equal: "+compRes);
132 if (!compRes && (selections[i]) instanceof Object[]){
133 if (((Object[])selections[i])[0] instanceof Integer) {
134 log.println("Getting: "+((Integer) ((Object[])curSelection)[0]).intValue());
135 log.println("Expected: "+((Integer) ((Object[])selections[i])[0]).intValue());
138 res &= compRes;
139 } else {
140 compRes = util.ValueComparer.equalValue(curSelection, oldSelection);
141 log.println("previous selection and current selection are equal: "+compRes);
142 res &= compRes;
145 } catch (com.sun.star.lang.IllegalArgumentException ex) {
146 log.println("Exception occurred during select()");
147 ex.printStackTrace(log);
148 res = false;
151 tRes.tested("select()", res);
155 * Test removes listener, then selects first and
156 * then second instances to be sure that selection was changed.<p>
157 * Has <b>OK</b> status if selection listener was not called.
158 * The following method tests are to be completed successfully before :
159 * <ul>
160 * <li> <code> addSelectionChangeListener() </code> : to have
161 * the listener added. </li>
162 * </ul>
164 public void _removeSelectionChangeListener() {
165 boolean res = false;
166 requiredMethod("addSelectionChangeListener()");
167 try {
168 selectionChanged = false;
169 oObj.removeSelectionChangeListener(listener);
170 oObj.select(selections[0]);
171 oObj.select(selections[1]);
172 res = !selectionChanged;
173 } catch (com.sun.star.lang.IllegalArgumentException ex) {
174 log.println("Exception occurred during removeSelectionChangeListener()");
175 ex.printStackTrace(log);
176 res = false;
178 tRes.tested("removeSelectionChangeListener()", res);
182 * First test changes selection of the object : if nothing is
183 * currently selected or first instance ('First' relation) is
184 * selected then selects second instance; if second instance
185 * is currently selected then the first instance is selected. <p>
186 * Then <code>getSelection</code> is called and values set and
187 * get are compared. Comparison has some special cases. For
188 * example if selection is a Cell, then the values contained
189 * in cells are compared. <p>
190 * Has <b>OK</b> status if selection changed properly.
192 public void _getSelection() {
193 requiredMethod("select()");
194 tRes.tested("getSelection()", true);
197 } // finish class _XSelectionSupplier