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