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 import lib.MultiMethodTest;
22 import lib.Status;
23 
24 import com.sun.star.awt.XComboBox;
25 
26 /**
27 * Testing <code>com.sun.star.awt.XComboBox</code>
28 * interface methods :
29 * <ul>
30 *  <li><code> addItemListener()</code></li>
31 *  <li><code> removeItemListener()</code></li>
32 *  <li><code> addActionListener()</code></li>
33 *  <li><code> removeActionListener()</code></li>
34 *  <li><code> addItem()</code></li>
35 *  <li><code> addItems()</code></li>
36 *  <li><code> removeItems()</code></li>
37 *  <li><code> getItemCount()</code></li>
38 *  <li><code> getItem()</code></li>
39 *  <li><code> getItems()</code></li>
40 *  <li><code> getDropDownLineCount()</code></li>
41 *  <li><code> setDropDownLineCount()</code></li>
42 * </ul> <p>
43 * Test is <b> NOT </b> multithread compliant. <p>
44 * @see com.sun.star.awt.XComboBox
45 */
46 public class _XComboBox extends MultiMethodTest {
47 
48     public XComboBox oObj = null;
49 
50     /**
51     * Listener implementation which sets flags on appropriate method calls
52     */
53     protected static class TestActionListener
54         implements com.sun.star.awt.XActionListener {
55 
disposing(com.sun.star.lang.EventObject e)56         public void disposing(com.sun.star.lang.EventObject e) {}
57 
actionPerformed(com.sun.star.awt.ActionEvent e)58         public void actionPerformed(com.sun.star.awt.ActionEvent e) {}
59     }
60 
61     /**
62     * Listener implementation which sets flags on appropriate method calls
63     */
64     protected static class TestItemListener
65         implements com.sun.star.awt.XItemListener {
66 
disposing(com.sun.star.lang.EventObject e)67         public void disposing(com.sun.star.lang.EventObject e) {}
68 
itemStateChanged(com.sun.star.awt.ItemEvent e)69         public void itemStateChanged(com.sun.star.awt.ItemEvent e) {}
70     }
71     private final TestActionListener actionListener = new TestActionListener();
72     private final TestItemListener itemListener = new TestItemListener();
73     short lineCount = 0;
74     short itemCount = 0;
75 
76     /**
77     * !!! Can be checked only interactively !!!
78     */
_addItemListener()79     public void _addItemListener() {
80 
81         oObj.addItemListener(itemListener);
82 
83         tRes.tested("addItemListener()", Status.skipped(true));
84     }
85 
86     /**
87     * !!! Can be checked only interactively !!!
88     */
_removeItemListener()89     public void _removeItemListener() {
90         requiredMethod("addItemListener()");
91 
92         oObj.removeItemListener(itemListener);
93 
94         tRes.tested("removeItemListener()", Status.skipped(true));
95     }
96 
97     /**
98     * !!! Can be checked only interactively !!!
99     */
_addActionListener()100     public void _addActionListener() {
101 
102         oObj.addActionListener(actionListener);
103 
104         tRes.tested("addActionListener()", Status.skipped(true));
105     }
106 
107     /**
108     * !!! Can be checked only interactively !!!
109     */
_removeActionListener()110     public void _removeActionListener() {
111         requiredMethod("addActionListener()");
112 
113         oObj.removeActionListener(actionListener);
114 
115         tRes.tested("removeActionListener()", Status.skipped(true));
116     }
117 
118     /**
119     * Adds one item to the last position and check the number of
120     * items after addition. <p>
121     * Has <b>OK</b> status if the number of items increased by 1.<p>
122     * The following method tests are to be completed successfully before :
123     * <ul>
124     *  <li> <code> getItemCount </code> </li>
125     * </ul>
126     */
_addItem()127     public void _addItem() {
128         requiredMethod("getItemCount()");
129 
130         boolean result = true;
131         oObj.addItem("Item1", itemCount);
132         result = oObj.getItemCount() == itemCount + 1;
133 
134         tRes.tested("addItem()", result);
135     }
136 
137     /**
138     * Adds one two items to the last position and check the number of
139     * items after addition. <p>
140     * Has <b>OK</b> status if the number of items increased by 2.<p>
141     * The following method tests are to be executed before :
142     * <ul>
143     *  <li> <code> addItem </code> </li>
144     * </ul>
145     */
_addItems()146     public void _addItems() {
147         executeMethod("addItem()");
148 
149         boolean result = true;
150         short oldCnt = oObj.getItemCount();
151         oObj.addItems(new String[] { "Item2", "Item3" }, oldCnt);
152         result = oObj.getItemCount() == oldCnt + 2;
153 
154         tRes.tested("addItems()", result);
155     }
156 
157     /**
158     * Gets the current number of items and tries to remove them all
159     * then checks number of items. <p>
160     * Has <b>OK</b> status if no items remains. <p>
161     * The following method tests are to be executed before :
162     * <ul>
163     *  <li> <code> getItems </code> </li>
164     *  <li> <code> getItem </code> </li>
165     * </ul>
166     */
_removeItems()167     public void _removeItems() {
168         executeMethod("getItems()");
169         executeMethod("getItem()");
170 
171         boolean result = true;
172         short oldCnt = oObj.getItemCount();
173         oObj.removeItems((short) 0, oldCnt);
174         result = oObj.getItemCount() == 0;
175 
176         tRes.tested("removeItems()", result);
177     }
178 
179     /**
180     * Just retrieves current number of items and stores it. <p>
181     * Has <b>OK</b> status if the count is not less than 0.
182     */
_getItemCount()183     public void _getItemCount() {
184 
185         itemCount = oObj.getItemCount();
186 
187         tRes.tested("getItemCount()", itemCount >= 0);
188     }
189 
190     /**
191     * After <code>addItem</code> and <code>addItems</code> methods
192     * test the following items must exist {..., "Item1", "Item2", "Item3"}
193     * Retrieves the item from the position which was ititially the last.<p>
194     * Has <b>OK</b> status if the "Item1" was retrieved. <p>
195     * The following method tests are to be executed before :
196     * <ul>
197     *  <li> <code> addItems </code> </li>
198     * </ul>
199     */
_getItem()200     public void _getItem() {
201         requiredMethod("addItems()");
202 
203         boolean result = true;
204         String item = oObj.getItem(itemCount);
205         result = "Item1".equals(item);
206 
207         tRes.tested("getItem()", result);
208     }
209 
210     /**
211     * After <code>addItem</code> and <code>addItems</code> methods
212     * test the following items must exist {..., "Item1", "Item2", "Item3"}
213     * Retrieves all items. <p>
214     * Has <b>OK</b> status if the last three items retrieved are
215     * "Item1", "Item2" and "Item3". <p>
216     * The following method tests are to be executed before :
217     * <ul>
218     *  <li> <code> addItems </code> </li>
219     * </ul>
220     */
_getItems()221     public void _getItems() {
222         requiredMethod("addItems()");
223 
224         boolean result = true;
225         String[] items = oObj.getItems();
226         for (int i = itemCount; i < (itemCount + 3); i++) {
227             result &= ("Item" + (i + 1)).equals(items[i]);
228         }
229 
230         tRes.tested("getItems()", result);
231     }
232 
233     /**
234     * Gets line count and stores it. <p>
235     * Has <b>OK</b> status if no runtime exceptions occurred.
236     */
_getDropDownLineCount()237     public void _getDropDownLineCount() {
238 
239         boolean result = true;
240         lineCount = oObj.getDropDownLineCount();
241 
242         tRes.tested("getDropDownLineCount()", result);
243     }
244 
245     /**
246     * Sets a new value and then checks get value. <p>
247     * Has <b>OK</b> status if set and get values are equal. <p>
248     * The following method tests are to be completed successfully before :
249     * <ul>
250     *  <li> <code> getDropDownLineCount </code>  </li>
251     * </ul>
252     */
_setDropDownLineCount()253     public void _setDropDownLineCount() {
254         requiredMethod("getDropDownLineCount()");
255 
256         boolean result = true;
257         oObj.setDropDownLineCount((short) (lineCount + 1));
258         result = oObj.getDropDownLineCount() == lineCount + 1;
259 
260         tRes.tested("setDropDownLineCount()", result);
261     }
262 }
263