1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 
29 import com.sun.star.awt.XComboBox;
30 
31 /**
32 * Testing <code>com.sun.star.awt.XComboBox</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> addItemListener()</code></li>
36 *  <li><code> removeItemListener()</code></li>
37 *  <li><code> addActionListener()</code></li>
38 *  <li><code> removeActionListener()</code></li>
39 *  <li><code> addItem()</code></li>
40 *  <li><code> addItems()</code></li>
41 *  <li><code> removeItems()</code></li>
42 *  <li><code> getItemCount()</code></li>
43 *  <li><code> getItem()</code></li>
44 *  <li><code> getItems()</code></li>
45 *  <li><code> getDropDownLineCount()</code></li>
46 *  <li><code> setDropDownLineCount()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.awt.XComboBox
50 */
51 public class _XComboBox extends MultiMethodTest {
52 
53 	public XComboBox oObj = null;
54 
55 	/**
56 	* Listener implementation which sets flags on appropriate method calls
57 	*/
58 	protected class TestActionListener
59 		implements com.sun.star.awt.XActionListener {
60 		public boolean disposingCalled = false;
61 		public boolean actionPerformedCalled = false;
62 
disposing(com.sun.star.lang.EventObject e)63 		public void disposing(com.sun.star.lang.EventObject e) {
64 			disposingCalled = true;
65 		}
66 
actionPerformed(com.sun.star.awt.ActionEvent e)67 		public void actionPerformed(com.sun.star.awt.ActionEvent e) {
68 			actionPerformedCalled = true;
69 		}
70 
71 	}
72 
73 	/**
74 	* Listener implementation which sets flags on appropriate method calls
75 	*/
76 	protected class TestItemListener
77 		implements com.sun.star.awt.XItemListener {
78 		public boolean disposingCalled = false;
79 		public boolean itemStateChangedCalled = false;
80 
disposing(com.sun.star.lang.EventObject e)81 		public void disposing(com.sun.star.lang.EventObject e) {
82 			disposingCalled = true;
83 		}
84 
itemStateChanged(com.sun.star.awt.ItemEvent e)85 		public void itemStateChanged(com.sun.star.awt.ItemEvent e) {
86 			itemStateChangedCalled = true;
87 		}
88 
89 	}
90 	private TestActionListener actionListener = new TestActionListener();
91 	private TestItemListener itemListener = new TestItemListener();
92 	short lineCount = 0;
93 	short itemCount = 0;
94 
95 	/**
96 	* !!! Can be checked only interactively !!!
97 	*/
_addItemListener()98 	public void _addItemListener() {
99 
100 		oObj.addItemListener(itemListener);
101 
102 		tRes.tested("addItemListener()", Status.skipped(true));
103 	}
104 
105 	/**
106 	* !!! Can be checked only interactively !!!
107 	*/
_removeItemListener()108 	public void _removeItemListener() {
109 		requiredMethod("addItemListener()");
110 
111 		oObj.removeItemListener(itemListener);
112 
113 		tRes.tested("removeItemListener()", Status.skipped(true));
114 	}
115 
116 	/**
117 	* !!! Can be checked only interactively !!!
118 	*/
_addActionListener()119 	public void _addActionListener() {
120 
121 		oObj.addActionListener(actionListener);
122 
123 		tRes.tested("addActionListener()", Status.skipped(true));
124 	}
125 
126 	/**
127 	* !!! Can be checked only interactively !!!
128 	*/
_removeActionListener()129 	public void _removeActionListener() {
130 		requiredMethod("addActionListener()");
131 
132 		oObj.removeActionListener(actionListener);
133 
134 		tRes.tested("removeActionListener()", Status.skipped(true));
135 	}
136 
137 	/**
138 	* Adds one item 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 1.<p>
141 	* The following method tests are to be completed successfully before :
142 	* <ul>
143 	*  <li> <code> getItemCount </code> </li>
144 	* </ul>
145 	*/
_addItem()146 	public void _addItem() {
147 		requiredMethod("getItemCount()");
148 
149 		boolean result = true;
150 		oObj.addItem("Item1", itemCount);
151 		result = oObj.getItemCount() == itemCount + 1;
152 
153 		tRes.tested("addItem()", result);
154 	}
155 
156 	/**
157 	* Adds one two items to the last position and check the number of
158 	* items after addition. <p>
159 	* Has <b>OK</b> status if the number of items increased by 2.<p>
160 	* The following method tests are to be executed before :
161 	* <ul>
162 	*  <li> <code> addItem </code> </li>
163 	* </ul>
164 	*/
_addItems()165 	public void _addItems() {
166 		executeMethod("addItem()");
167 
168 		boolean result = true;
169 		short oldCnt = oObj.getItemCount();
170 		oObj.addItems(new String[] { "Item2", "Item3" }, oldCnt);
171 		result = oObj.getItemCount() == oldCnt + 2;
172 
173 		tRes.tested("addItems()", result);
174 	}
175 
176 	/**
177 	* Gets the current number of items and tries to remove them all
178 	* then checks number of items. <p>
179 	* Has <b>OK</b> status if no items remains. <p>
180 	* The following method tests are to be executed before :
181 	* <ul>
182 	*  <li> <code> getItems </code> </li>
183 	*  <li> <code> getItem </code> </li>
184 	* </ul>
185 	*/
_removeItems()186 	public void _removeItems() {
187 		executeMethod("getItems()");
188 		executeMethod("getItem()");
189 
190 		boolean result = true;
191 		short oldCnt = oObj.getItemCount();
192 		oObj.removeItems((short) 0, oldCnt);
193 		result = oObj.getItemCount() == 0;
194 
195 		tRes.tested("removeItems()", result);
196 	}
197 
198 	/**
199 	* Just retrieves current number of items and stores it. <p>
200 	* Has <b>OK</b> status if the count is not less than 0.
201 	*/
_getItemCount()202 	public void _getItemCount() {
203 
204 		itemCount = oObj.getItemCount();
205 
206 		tRes.tested("getItemCount()", itemCount >= 0);
207 	}
208 
209 	/**
210 	* After <code>addItem</code> and <code>addItems</code> methods
211 	* test the following items must exist {..., "Item1", "Item2", "Item3"}
212 	* Retrieves the item from the position which was ititially the last.<p>
213 	* Has <b>OK</b> status if the "Item1" was retrieved. <p>
214 	* The following method tests are to be executed before :
215 	* <ul>
216 	*  <li> <code> addItems </code> </li>
217 	* </ul>
218 	*/
_getItem()219 	public void _getItem() {
220 		requiredMethod("addItems()");
221 
222 		boolean result = true;
223 		String item = oObj.getItem(itemCount);
224 		result = "Item1".equals(item);
225 
226 		tRes.tested("getItem()", result);
227 	}
228 
229 	/**
230 	* After <code>addItem</code> and <code>addItems</code> methods
231 	* test the following items must exist {..., "Item1", "Item2", "Item3"}
232 	* Retrieves all items. <p>
233 	* Has <b>OK</b> status if the last three items retrieved are
234 	* "Item1", "Item2" and "Item3". <p>
235 	* The following method tests are to be executed before :
236 	* <ul>
237 	*  <li> <code> addItems </code> </li>
238 	* </ul>
239 	*/
_getItems()240 	public void _getItems() {
241 		requiredMethod("addItems()");
242 
243 		boolean result = true;
244 		String[] items = oObj.getItems();
245 		for (int i = itemCount; i < (itemCount + 3); i++) {
246 			result &= ("Item" + (i + 1)).equals(items[i]);
247 		}
248 
249 		tRes.tested("getItems()", result);
250 	}
251 
252 	/**
253 	* Gets line count and stores it. <p>
254 	* Has <b>OK</b> status if no runtime exceptions occured.
255 	*/
_getDropDownLineCount()256 	public void _getDropDownLineCount() {
257 
258 		boolean result = true;
259 		lineCount = oObj.getDropDownLineCount();
260 
261 		tRes.tested("getDropDownLineCount()", result);
262 	}
263 
264 	/**
265 	* Sets a new value and then checks get value. <p>
266 	* Has <b>OK</b> status if set and get values are equal. <p>
267 	* The following method tests are to be completed successfully before :
268 	* <ul>
269 	*  <li> <code> getDropDownLineCount </code>  </li>
270 	* </ul>
271 	*/
_setDropDownLineCount()272 	public void _setDropDownLineCount() {
273 		requiredMethod("getDropDownLineCount()");
274 
275 		boolean result = true;
276 		oObj.setDropDownLineCount((short) (lineCount + 1));
277 		result = oObj.getDropDownLineCount() == lineCount + 1;
278 
279 		tRes.tested("setDropDownLineCount()", result);
280 	}
281 }