1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package ifc.awt;
20 
21 
22 import lib.MultiMethodTest;
23 import lib.Status;
24 
25 import com.sun.star.awt.XListBox;
26 
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
56 */
57 public class _XListBox extends MultiMethodTest {
58 
59     public XListBox oObj = null;
60 
61     /**
62     * Listener implementation which sets flags on appropriate method calls
63     */
64     protected static class TestActionListener implements com.sun.star.awt.XActionListener {
65 
disposing(com.sun.star.lang.EventObject e)66         public void disposing(com.sun.star.lang.EventObject e) {}
67 
actionPerformed(com.sun.star.awt.ActionEvent e)68         public void actionPerformed(com.sun.star.awt.ActionEvent e) {}
69 
70     }
71 
72     TestActionListener actionListener = new TestActionListener() ;
73 
74     /**
75     * Listener implementation which sets flags on appropriate method calls
76     */
77     protected static class TestItemListener implements com.sun.star.awt.XItemListener {
78 
disposing(com.sun.star.lang.EventObject e)79         public void disposing(com.sun.star.lang.EventObject e) {}
80 
itemStateChanged(com.sun.star.awt.ItemEvent e)81         public void itemStateChanged(com.sun.star.awt.ItemEvent e) {}
82     }
83 
84     TestItemListener itemListener = new TestItemListener() ;
85 
86     short lineCount = 0 ;
87     short itemCount = 0 ;
88 
89     /**
90     * Retrieves object relations.
91     */
92     @Override
before()93     public void before() {
94         itemCount = oObj.getItemCount();
95     }
96 
97     /**
98     * !!! Can be checked only interactively !!!
99     */
_addItemListener()100     public void _addItemListener() {
101 
102         oObj.addItemListener(itemListener) ;
103 
104         tRes.tested("addItemListener()", Status.skipped(true)) ;
105     }
106 
107     /**
108     * !!! Can be checked only interactively !!!
109     */
_removeItemListener()110     public void _removeItemListener() {
111         requiredMethod("addItemListener()") ;
112 
113         oObj.removeItemListener(itemListener) ;
114 
115         tRes.tested("removeItemListener()", Status.skipped(true)) ;
116     }
117 
118     /**
119     * !!! Can be checked only interactively !!!
120     */
_addActionListener()121     public void _addActionListener() {
122 
123         oObj.addActionListener(actionListener) ;
124 
125         tRes.tested("addActionListener()", Status.skipped(true)) ;
126     }
127 
128     /**
129     * !!! Can be checked only interactively !!!
130     */
_removeActionListener()131     public void _removeActionListener() {
132         requiredMethod("addActionListener()") ;
133 
134         oObj.removeActionListener(actionListener) ;
135 
136         tRes.tested("removeActionListener()", Status.skipped(true)) ;
137     }
138 
139     /**
140     * Adds one item to the last position and check the number of
141     * items after addition. <p>
142     * Has <b>OK</b> status if the number of items increased by 1.<p>
143     * The following method tests are to be completed successfully before :
144     * <ul>
145     *  <li> <code> getItemCount </code> </li>
146     * </ul>
147     */
_addItem()148     public void _addItem() {
149         requiredMethod("getItemCount()") ;
150 
151         boolean result = true ;
152         oObj.addItem("Item1", itemCount) ;
153         result = oObj.getItemCount() == itemCount + 1 ;
154 
155         tRes.tested("addItem()", result) ;
156     }
157 
158     /**
159     * Adds one two items to the last position and check the number of
160     * items after addition. <p>
161     * Has <b>OK</b> status if the number of items increased by 2.<p>
162     * The following method tests are to be executed before :
163     * <ul>
164     *  <li> <code> addItem </code> </li>
165     * </ul>
166     */
_addItems()167     public void _addItems() {
168         executeMethod("addItem()") ;
169 
170         boolean result = true ;
171         short oldCnt = oObj.getItemCount() ;
172         oObj.addItems(new String[] {"Item2", "Item3"}, oldCnt) ;
173         result = oObj.getItemCount() == oldCnt + 2 ;
174 
175         tRes.tested("addItems()", result) ;
176     }
177 
178     /**
179     * Gets the current number of items and tries to remove them all
180     * then checks number of items. <p>
181     * Has <b>OK</b> status if no items remains. <p>
182     * The following method tests are to be executed before :
183     * <ul>
184     *  <li> <code> getItems </code> </li>
185     *  <li> <code> getItem </code> </li>
186     * </ul>
187     */
_removeItems()188     public void _removeItems() {
189         executeMethod("getItems()") ;
190         executeMethod("getItem()") ;
191         executeMethod("getSelectedItemPos()") ;
192         executeMethod("getSelectedItemsPos()") ;
193         executeMethod("getSelectedItem()") ;
194         executeMethod("getSelectedItems()") ;
195 
196         boolean result = true ;
197         short oldCnt = oObj.getItemCount() ;
198         oObj.removeItems((short)0, oldCnt) ;
199         result = oObj.getItemCount() == 0 ;
200 
201         tRes.tested("removeItems()", result) ;
202     }
203 
204     /**
205     * Just retrieves current number of items and stores it. <p>
206     * Has <b>OK</b> status if the count is not less than 0.
207     */
_getItemCount()208     public void _getItemCount() {
209 
210         itemCount = oObj.getItemCount() ;
211 
212         tRes.tested("getItemCount()", itemCount >= 0) ;
213     }
214 
215     /**
216     * After <code>addItem</code> and <code>addItems</code> methods
217     * test the following items must exist {..., "Item1", "Item2", "Item3"}
218     * Retrieves the item from the position which was ititially the last.<p>
219     * Has <b>OK</b> status if the "Item1" was retrieved. <p>
220     * The following method tests are to be executed before :
221     * <ul>
222     *  <li> <code> addItems </code> </li>
223     * </ul>
224     */
_getItem()225     public void _getItem() {
226         requiredMethod("addItems()") ;
227 
228         boolean result = true ;
229         String item = oObj.getItem(itemCount) ;
230         result = "Item1".equals(item) ;
231 
232         tRes.tested("getItem()", result) ;
233     }
234 
235     /**
236     * After <code>addItem</code> and <code>addItems</code> methods
237     * test the following items must exist {..., "Item1", "Item2", "Item3"}
238     * Retrieves all items. <p>
239     * Has <b>OK</b> status if the last three items retrieved are
240     * "Item1", "Item2" and "Item3". <p>
241     * The following method tests are to be executed before :
242     * <ul>
243     *  <li> <code> addItems </code> </li>
244     * </ul>
245     */
_getItems()246     public void _getItems() {
247         requiredMethod("addItems()") ;
248 
249         boolean result = true ;
250         String[] items = oObj.getItems() ;
251         for (int i = itemCount; i < (itemCount + 3); i++) {
252             result &= ("Item" + (i+1 - itemCount)).equals(items[i]) ;
253         }
254 
255         tRes.tested("getItems()", result) ;
256     }
257 
258     /**
259     * Gets line count and stores it. <p>
260     * Has <b>OK</b> status if no runtime exceptions occurred.
261     */
_getDropDownLineCount()262     public void _getDropDownLineCount() {
263 
264         boolean result = true ;
265         lineCount = oObj.getDropDownLineCount() ;
266 
267         tRes.tested("getDropDownLineCount()", result) ;
268     }
269 
270     /**
271     * Sets a new value and then checks get value. <p>
272     * Has <b>OK</b> status if set and get values are equal. <p>
273     * The following method tests are to be completed successfully before :
274     * <ul>
275     *  <li> <code> getDropDownLineCount </code>  </li>
276     * </ul>
277     */
_setDropDownLineCount()278     public void _setDropDownLineCount() {
279         requiredMethod("getDropDownLineCount()") ;
280 
281         boolean result = true ;
282         oObj.setDropDownLineCount((short)(lineCount + 1)) ;
283         result = oObj.getDropDownLineCount() == lineCount + 1 ;
284 
285         tRes.tested("setDropDownLineCount()", result) ;
286     }
287 
288     /**
289     * Selects some item and gets selected item position. <p>
290     * Has <b> OK </b> status if position is equal to position set. <p>
291     * The following method tests are to be completed successfully before :
292     * <ul>
293     *  <li> <code> addItems </code> : to have some items </li>
294     * </ul>
295     */
_getSelectedItemPos()296     public void _getSelectedItemPos() {
297         requiredMethod("addItems()") ;
298 
299         boolean result = true ;
300         oObj.selectItemPos((short)1, true) ;
301         short pos = oObj.getSelectedItemPos() ;
302 
303         result = pos == 1 ;
304 
305         tRes.tested("getSelectedItemPos()", result) ;
306     }
307 
308     /**
309     * Clears all selections, then selects some items and gets selected
310     * item positions. <p>
311     * Has <b> OK </b> status if positions get are the same as were set.<p>
312     * The following method tests are to be completed successfully before :
313     * <ul>
314     *  <li> <code> selectItemsPos </code> </li>
315     * </ul>
316     */
_getSelectedItemsPos()317     public void _getSelectedItemsPos() {
318         requiredMethod("selectItemsPos()") ;
319 
320         boolean result = true ;
321         short cnt = oObj.getItemCount() ;
322         for (short i = 0; i < cnt; i++) {
323             oObj.selectItemPos(i, false) ;
324         }
325         oObj.selectItemsPos(new short[] {0, 2}, true) ;
326 
327         short[] items = oObj.getSelectedItemsPos() ;
328 
329         result = items != null && items.length == 2 &&
330             items[0] == 0 && items[1] == 2 ;
331 
332         tRes.tested("getSelectedItemsPos()", result) ;
333     }
334 
335     /**
336     * Unselects all items, selects some item and then gets selected item. <p>
337     * Has <b> OK </b> status if items selected and get are equal.
338     * The following method tests are to be completed successfully before :
339     * <ul>
340     *  <li> <code> addItems </code> : to have some items </li>
341     * </ul>
342     */
_getSelectedItem()343     public void _getSelectedItem() {
344         requiredMethod("addItems()") ;
345 
346         boolean result = true ;
347         short cnt = oObj.getItemCount() ;
348         for (short i = 0; i < cnt; i++) {
349             oObj.selectItemPos(i, false) ;
350         }
351         oObj.selectItem("Item3", true) ;
352         String item = oObj.getSelectedItem() ;
353 
354         result = "Item3".equals(item) ;
355 
356         tRes.tested("getSelectedItem()", result) ;
357     }
358 
359     /**
360     * Clears all selections, then selects some items positions and gets
361     *  selected items. <p>
362     * Has <b> OK </b> status if items get are the same as items on
363     * positions which were set.<p>
364     * The following method tests are to be completed successfully before :
365     * <ul>
366     *  <li> <code> selectItemsPos </code> </li>
367     *  <li> <code> getItem </code>: this method is used here for checking.
368     *   </li>
369     * </ul>
370     */
_getSelectedItems()371     public void _getSelectedItems() {
372         requiredMethod("selectItemsPos()") ;
373         requiredMethod("getItem()") ;
374 
375         boolean result = true ;
376         short cnt = oObj.getItemCount() ;
377         for (short i = 0; i < cnt; i++) {
378             oObj.selectItemPos(i, false) ;
379         }
380         oObj.selectItemsPos(new short[] {0, 2}, true) ;
381 
382         String[] items = oObj.getSelectedItems() ;
383         result = items != null && items.length == 2 &&
384             oObj.getItem((short)0).equals(items[0]) &&
385             oObj.getItem((short)2).equals(items[1]) ;
386 
387         tRes.tested("getSelectedItems()", result) ;
388     }
389 
390     /**
391     * Unselects all items, then selects a single item. <p>
392     * Has <b> OK </b> status if no runtime exceptions occurred
393     * The following method tests are to be completed successfully before :
394     * <ul>
395     *  <li> <code> addItems </code> : to have some items </li>
396     * </ul>
397     */
_selectItemPos()398     public void _selectItemPos() {
399         requiredMethod("addItems()") ;
400 
401         boolean result = true ;
402         short cnt = oObj.getItemCount() ;
403         for (short i = 0; i < cnt; i++) {
404             oObj.selectItemPos(i, false) ;
405         }
406         oObj.selectItemPos((short)1, true) ;
407 
408         tRes.tested("selectItemPos()", result) ;
409     }
410 
411     /**
412     * Just selects some items. <p>
413     * Has <b> OK </b> status if no runtime exceptions occurred
414     * The following method tests are to be completed successfully before :
415     * <ul>
416     *  <li> <code> addItems </code> : to have some items </li>
417     * </ul>
418     */
_selectItemsPos()419     public void _selectItemsPos() {
420         requiredMethod("addItems()") ;
421         requiredMethod("setMultipleMode()") ;
422 
423         boolean result = true ;
424         oObj.selectItemsPos(new short[] {0, 2}, true) ;
425 
426         tRes.tested("selectItemsPos()", result) ;
427     }
428 
429     /**
430     * Just selects an item. <p>
431     * Has <b> OK </b> status if no runtime exceptions occurred
432     * The following method tests are to be completed successfully before :
433     * <ul>
434     *  <li> <code> addItems </code> : to have some items </li>
435     * </ul>
436     */
_selectItem()437     public void _selectItem() {
438         requiredMethod("addItems()") ;
439 
440         boolean result = true ;
441         oObj.selectItem("Item3", true) ;
442 
443         tRes.tested("selectItem()", result) ;
444     }
445 
446     /**
447     * Checks if multiple mode is set. <p>
448     * Has <b> OK </b> status if multiple mode is set. <p>
449     * The following method tests are to be completed successfully before :
450     * <ul>
451     *  <li> <code> setMultipleMode </code>  </li>
452     * </ul>
453     */
_isMutipleMode()454     public void _isMutipleMode() {
455         requiredMethod("setMultipleMode()") ;
456 
457         boolean result = true ;
458         result = oObj.isMutipleMode() ;
459 
460         tRes.tested("isMutipleMode()", result) ;
461     }
462 
463     /**
464     * Sets multiple mode. <p>
465     * Has <b> OK </b> status if no runtime exceptions occurred
466     */
_setMultipleMode()467     public void _setMultipleMode() {
468 
469         boolean result = true ;
470         oObj.setMultipleMode(true) ;
471 
472         tRes.tested("setMultipleMode()", result) ;
473     }
474 
475     /**
476     * Just calls the method to make visible third item. <p>
477     * Has <b> OK </b> status if no runtime exceptions occurred.<p>
478     * The following method tests are to be completed successfully before :
479     * <ul>
480     *  <li> <code> addItems </code> </li>
481     * </ul>
482     */
_makeVisible()483     public void _makeVisible() {
484         requiredMethod("addItems()") ;
485 
486         boolean result = true ;
487         oObj.makeVisible((short)2) ;
488 
489         tRes.tested("makeVisible()", result) ;
490     }
491 }
492