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