Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / _XListBox.java
blob53531a3df459d02ae5dc13708efff73eb0097597
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;
22 import lib.MultiMethodTest;
23 import lib.Status;
25 import com.sun.star.awt.XListBox;
27 /**
28 * Testing <code>com.sun.star.awt.XListBox</code>
29 * interface methods :
30 * <ul>
31 * <li><code> addItemListener()</code></li>
32 * <li><code> removeItemListener()</code></li>
33 * <li><code> addActionListener()</code></li>
34 * <li><code> removeActionListener()</code></li>
35 * <li><code> addItem()</code></li>
36 * <li><code> addItems()</code></li>
37 * <li><code> removeItems()</code></li>
38 * <li><code> getItemCount()</code></li>
39 * <li><code> getItem()</code></li>
40 * <li><code> getItems()</code></li>
41 * <li><code> getSelectedItemPos()</code></li>
42 * <li><code> getSelectedItemsPos()</code></li>
43 * <li><code> getSelectedItem()</code></li>
44 * <li><code> getSelectedItems()</code></li>
45 * <li><code> selectItemPos()</code></li>
46 * <li><code> selectItemsPos()</code></li>
47 * <li><code> selectItem()</code></li>
48 * <li><code> isMutipleMode()</code></li>
49 * <li><code> setMultipleMode()</code></li>
50 * <li><code> getDropDownLineCount()</code></li>
51 * <li><code> setDropDownLineCount()</code></li>
52 * <li><code> makeVisible()</code></li>
53 * </ul> <p>
54 * Test is <b> NOT </b> multithread compliant. <p>
55 * @see com.sun.star.awt.XListBox
57 public class _XListBox extends MultiMethodTest {
59 public XListBox oObj = null;
61 /**
62 * Listener implementation which sets flags on appropriate method calls
64 protected class TestActionListener implements com.sun.star.awt.XActionListener {
65 public boolean disposingCalled = false ;
66 public boolean actionPerformedCalled = false ;
68 public void disposing(com.sun.star.lang.EventObject e) {
69 disposingCalled = true ;
72 public void actionPerformed(com.sun.star.awt.ActionEvent e) {
73 actionPerformedCalled = true ;
78 TestActionListener actionListener = new TestActionListener() ;
80 /**
81 * Listener implementation which sets flags on appropriate method calls
83 protected class TestItemListener implements com.sun.star.awt.XItemListener {
84 public boolean disposingCalled = false ;
85 public boolean itemStateChangedCalled = false ;
87 public void disposing(com.sun.star.lang.EventObject e) {
88 disposingCalled = true ;
91 public void itemStateChanged(com.sun.star.awt.ItemEvent e) {
92 itemStateChangedCalled = true ;
97 TestItemListener itemListener = new TestItemListener() ;
99 short lineCount = 0 ;
100 short itemCount = 0 ;
103 * Retrieves object relations.
105 @Override
106 public void before() {
107 itemCount = oObj.getItemCount();
111 * !!! Can be checked only interactively !!!
113 public void _addItemListener() {
115 oObj.addItemListener(itemListener) ;
117 tRes.tested("addItemListener()", Status.skipped(true)) ;
121 * !!! Can be checked only interactively !!!
123 public void _removeItemListener() {
124 requiredMethod("addItemListener()") ;
126 oObj.removeItemListener(itemListener) ;
128 tRes.tested("removeItemListener()", Status.skipped(true)) ;
132 * !!! Can be checked only interactively !!!
134 public void _addActionListener() {
136 oObj.addActionListener(actionListener) ;
138 tRes.tested("addActionListener()", Status.skipped(true)) ;
142 * !!! Can be checked only interactively !!!
144 public void _removeActionListener() {
145 requiredMethod("addActionListener()") ;
147 oObj.removeActionListener(actionListener) ;
149 tRes.tested("removeActionListener()", Status.skipped(true)) ;
153 * Adds one item to the last position and check the number of
154 * items after addition. <p>
155 * Has <b>OK</b> status if the number of items increased by 1.<p>
156 * The following method tests are to be completed successfully before :
157 * <ul>
158 * <li> <code> getItemCount </code> </li>
159 * </ul>
161 public void _addItem() {
162 requiredMethod("getItemCount()") ;
164 boolean result = true ;
165 oObj.addItem("Item1", itemCount) ;
166 result = oObj.getItemCount() == itemCount + 1 ;
168 tRes.tested("addItem()", result) ;
172 * Adds one two items to the last position and check the number of
173 * items after addition. <p>
174 * Has <b>OK</b> status if the number of items increased by 2.<p>
175 * The following method tests are to be executed before :
176 * <ul>
177 * <li> <code> addItem </code> </li>
178 * </ul>
180 public void _addItems() {
181 executeMethod("addItem()") ;
183 boolean result = true ;
184 short oldCnt = oObj.getItemCount() ;
185 oObj.addItems(new String[] {"Item2", "Item3"}, oldCnt) ;
186 result = oObj.getItemCount() == oldCnt + 2 ;
188 tRes.tested("addItems()", result) ;
192 * Gets the current number of items and tries to remove them all
193 * then checks number of items. <p>
194 * Has <b>OK</b> status if no items remains. <p>
195 * The following method tests are to be executed before :
196 * <ul>
197 * <li> <code> getItems </code> </li>
198 * <li> <code> getItem </code> </li>
199 * </ul>
201 public void _removeItems() {
202 executeMethod("getItems()") ;
203 executeMethod("getItem()") ;
204 executeMethod("getSelectedItemPos()") ;
205 executeMethod("getSelectedItemsPos()") ;
206 executeMethod("getSelectedItem()") ;
207 executeMethod("getSelectedItems()") ;
209 boolean result = true ;
210 short oldCnt = oObj.getItemCount() ;
211 oObj.removeItems((short)0, oldCnt) ;
212 result = oObj.getItemCount() == 0 ;
214 tRes.tested("removeItems()", result) ;
218 * Just retrieves current number of items and stores it. <p>
219 * Has <b>OK</b> status if the count is not less than 0.
221 public void _getItemCount() {
223 itemCount = oObj.getItemCount() ;
225 tRes.tested("getItemCount()", itemCount >= 0) ;
229 * After <code>addItem</code> and <code>addItems</code> methods
230 * test the following items must exist {..., "Item1", "Item2", "Item3"}
231 * Retrieves the item from the position which was ititially the last.<p>
232 * Has <b>OK</b> status if the "Item1" was retrieved. <p>
233 * The following method tests are to be executed before :
234 * <ul>
235 * <li> <code> addItems </code> </li>
236 * </ul>
238 public void _getItem() {
239 requiredMethod("addItems()") ;
241 boolean result = true ;
242 String item = oObj.getItem(itemCount) ;
243 result = "Item1".equals(item) ;
245 tRes.tested("getItem()", result) ;
249 * After <code>addItem</code> and <code>addItems</code> methods
250 * test the following items must exist {..., "Item1", "Item2", "Item3"}
251 * Retrieves all items. <p>
252 * Has <b>OK</b> status if the last three items retrieved are
253 * "Item1", "Item2" and "Item3". <p>
254 * The following method tests are to be executed before :
255 * <ul>
256 * <li> <code> addItems </code> </li>
257 * </ul>
259 public void _getItems() {
260 requiredMethod("addItems()") ;
262 boolean result = true ;
263 String[] items = oObj.getItems() ;
264 for (int i = itemCount; i < (itemCount + 3); i++) {
265 result &= ("Item" + (i+1 - itemCount)).equals(items[i]) ;
268 tRes.tested("getItems()", result) ;
272 * Gets line count and stores it. <p>
273 * Has <b>OK</b> status if no runtime exceptions occurred.
275 public void _getDropDownLineCount() {
277 boolean result = true ;
278 lineCount = oObj.getDropDownLineCount() ;
280 tRes.tested("getDropDownLineCount()", result) ;
284 * Sets a new value and then checks get value. <p>
285 * Has <b>OK</b> status if set and get values are equal. <p>
286 * The following method tests are to be completed successfully before :
287 * <ul>
288 * <li> <code> getDropDownLineCount </code> </li>
289 * </ul>
291 public void _setDropDownLineCount() {
292 requiredMethod("getDropDownLineCount()") ;
294 boolean result = true ;
295 oObj.setDropDownLineCount((short)(lineCount + 1)) ;
296 result = oObj.getDropDownLineCount() == lineCount + 1 ;
298 tRes.tested("setDropDownLineCount()", result) ;
302 * Selects some item and gets selected item position. <p>
303 * Has <b> OK </b> status if position is equal to position set. <p>
304 * The following method tests are to be completed successfully before :
305 * <ul>
306 * <li> <code> addItems </code> : to have some items </li>
307 * </ul>
309 public void _getSelectedItemPos() {
310 requiredMethod("addItems()") ;
312 boolean result = true ;
313 oObj.selectItemPos((short)1, true) ;
314 short pos = oObj.getSelectedItemPos() ;
316 result = pos == 1 ;
318 tRes.tested("getSelectedItemPos()", result) ;
322 * Clears all selections, then selects some items and gets selected
323 * item positions. <p>
324 * Has <b> OK </b> status if positions get are the same as were set.<p>
325 * The following method tests are to be completed successfully before :
326 * <ul>
327 * <li> <code> selectItemsPos </code> </li>
328 * </ul>
330 public void _getSelectedItemsPos() {
331 requiredMethod("selectItemsPos()") ;
333 boolean result = true ;
334 short cnt = oObj.getItemCount() ;
335 for (short i = 0; i < cnt; i++) {
336 oObj.selectItemPos(i, false) ;
338 oObj.selectItemsPos(new short[] {0, 2}, true) ;
340 short[] items = oObj.getSelectedItemsPos() ;
342 result = items != null && items.length == 2 &&
343 items[0] == 0 && items[1] == 2 ;
345 tRes.tested("getSelectedItemsPos()", result) ;
349 * Unselects all items, selects some item and then gets selected item. <p>
350 * Has <b> OK </b> status if items selected and get are equal.
351 * The following method tests are to be completed successfully before :
352 * <ul>
353 * <li> <code> addItems </code> : to have some items </li>
354 * </ul>
356 public void _getSelectedItem() {
357 requiredMethod("addItems()") ;
359 boolean result = true ;
360 short cnt = oObj.getItemCount() ;
361 for (short i = 0; i < cnt; i++) {
362 oObj.selectItemPos(i, false) ;
364 oObj.selectItem("Item3", true) ;
365 String item = oObj.getSelectedItem() ;
367 result = "Item3".equals(item) ;
369 tRes.tested("getSelectedItem()", result) ;
373 * Clears all selections, then selects some items positions and gets
374 * selected items. <p>
375 * Has <b> OK </b> status if items get are the same as items on
376 * positions which were set.<p>
377 * The following method tests are to be completed successfully before :
378 * <ul>
379 * <li> <code> selectItemsPos </code> </li>
380 * <li> <code> getItem </code>: this method is used here for checking.
381 * </li>
382 * </ul>
384 public void _getSelectedItems() {
385 requiredMethod("selectItemsPos()") ;
386 requiredMethod("getItem()") ;
388 boolean result = true ;
389 short cnt = oObj.getItemCount() ;
390 for (short i = 0; i < cnt; i++) {
391 oObj.selectItemPos(i, false) ;
393 oObj.selectItemsPos(new short[] {0, 2}, true) ;
395 String[] items = oObj.getSelectedItems() ;
396 result = items != null && items.length == 2 &&
397 oObj.getItem((short)0).equals(items[0]) &&
398 oObj.getItem((short)2).equals(items[1]) ;
400 tRes.tested("getSelectedItems()", result) ;
404 * Unselects all items, then selects a single item. <p>
405 * Has <b> OK </b> status if no runtime exceptions occurred
406 * The following method tests are to be completed successfully before :
407 * <ul>
408 * <li> <code> addItems </code> : to have some items </li>
409 * </ul>
411 public void _selectItemPos() {
412 requiredMethod("addItems()") ;
414 boolean result = true ;
415 short cnt = oObj.getItemCount() ;
416 for (short i = 0; i < cnt; i++) {
417 oObj.selectItemPos(i, false) ;
419 oObj.selectItemPos((short)1, true) ;
421 tRes.tested("selectItemPos()", result) ;
425 * Just selects some items. <p>
426 * Has <b> OK </b> status if no runtime exceptions occurred
427 * The following method tests are to be completed successfully before :
428 * <ul>
429 * <li> <code> addItems </code> : to have some items </li>
430 * </ul>
432 public void _selectItemsPos() {
433 requiredMethod("addItems()") ;
434 requiredMethod("setMultipleMode()") ;
436 boolean result = true ;
437 oObj.selectItemsPos(new short[] {0, 2}, true) ;
439 tRes.tested("selectItemsPos()", result) ;
443 * Just selects an item. <p>
444 * Has <b> OK </b> status if no runtime exceptions occurred
445 * The following method tests are to be completed successfully before :
446 * <ul>
447 * <li> <code> addItems </code> : to have some items </li>
448 * </ul>
450 public void _selectItem() {
451 requiredMethod("addItems()") ;
453 boolean result = true ;
454 oObj.selectItem("Item3", true) ;
456 tRes.tested("selectItem()", result) ;
460 * Checks if multiple mode is set. <p>
461 * Has <b> OK </b> status if multiple mode is set. <p>
462 * The following method tests are to be completed successfully before :
463 * <ul>
464 * <li> <code> setMultipleMode </code> </li>
465 * </ul>
467 public void _isMutipleMode() {
468 requiredMethod("setMultipleMode()") ;
470 boolean result = true ;
471 result = oObj.isMutipleMode() ;
473 tRes.tested("isMutipleMode()", result) ;
477 * Sets multiple mode. <p>
478 * Has <b> OK </b> status if no runtime exceptions occurred
480 public void _setMultipleMode() {
482 boolean result = true ;
483 oObj.setMultipleMode(true) ;
485 tRes.tested("setMultipleMode()", result) ;
489 * Just calls the method to make visible third item. <p>
490 * Has <b> OK </b> status if no runtime exceptions occurred.<p>
491 * The following method tests are to be completed successfully before :
492 * <ul>
493 * <li> <code> addItems </code> </li>
494 * </ul>
496 public void _makeVisible() {
497 requiredMethod("addItems()") ;
499 boolean result = true ;
500 oObj.makeVisible((short)2) ;
502 tRes.tested("makeVisible()", result) ;