xref: /AOO41X/main/qadevOOo/tests/java/ifc/linguistic2/_XDictionaryList.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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.linguistic2;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.lang.EventObject;
33 import com.sun.star.lang.Locale;
34 import com.sun.star.linguistic2.DictionaryListEvent;
35 import com.sun.star.linguistic2.XDictionary;
36 import com.sun.star.linguistic2.XDictionaryList;
37 import com.sun.star.linguistic2.XDictionaryListEventListener;
38 
39 /**
40 * Testing <code>com.sun.star.linguistic2.XDictionaryList</code>
41 * interface methods:
42 * <ul>
43 *   <li><code>getCount()</code></li>
44 *   <li><code>getDictionaries()</code></li>
45 *   <li><code>getDictionaryByName()</code></li>
46 *   <li><code>addDictionary()</code></li>
47 *   <li><code>removeDictionary()</code></li>
48 *   <li><code>addDictionaryListEventListener()</code></li>
49 *   <li><code>removeDictionaryListEventListener()</code></li>
50 *   <li><code>beginCollectEvents()</code></li>
51 *   <li><code>endCollectEvents()</code></li>
52 *   <li><code>flushEvents()</code></li>
53 *   <li><code>createDictionary()</code></li>
54 * </ul> <p>
55 * @see com.sun.star.linguistic2.XDictionaryList
56 */
57 public class _XDictionaryList extends MultiMethodTest {
58 
59     public XDictionaryList oObj = null;
60     public XDictionary addedDic = null;
61 
62     /**
63     * Flag for testing of listeners.
64     */
65     public boolean listenerCalled = false;
66 
67     /**
68     * Class implements interface <code>XDictionaryListEventListener</code>
69     * for test method <code>addDictionaryListEventListener</code>.
70     * @see com.sun.star.linguistic2.XDictionaryListEventListener
71     */
72     public class MyDictionaryListEventListener implements
73             XDictionaryListEventListener {
74 
75         public void disposing ( EventObject oEvent ) {
76             log.println("Listener has been disposed");
77         }
78         public void processDictionaryListEvent( DictionaryListEvent aDicEvent) {
79             listenerCalled = true;
80         }
81     };
82 
83     XDictionaryListEventListener listener = new MyDictionaryListEventListener();
84 
85     short count = 0;
86 
87     /**
88     * Test calls the method and checks returned value. <p>
89     * Has <b> OK </b> status if returned value is greater than zero. <p>
90     */
91     public void _getCount() {
92         count = oObj.getCount();
93         tRes.tested("getCount()",(count > 0) );
94     }
95 
96     /**
97     * Test calls the method and checks number of obtained dictionaries
98     * with value that was returned by method <code>getCount</code>. <p>
99     * Has <b> OK </b> status if values are equal. <p>
100     * The following method tests are to be completed successfully before :
101     * <ul>
102     *  <li> <code> getCount() </code> : to have number of dictionaries </li>
103     * </ul>
104     */
105     public void _getDictionaries() {
106         requiredMethod("getCount()");
107 
108         XDictionary[] dics = oObj.getDictionaries();
109         boolean res = (dics.length == count);
110         if (!res) {
111             log.println("Expected: " + oObj.getCount());
112             log.println("Gained: " + dics.length);
113         }
114         tRes.tested("getDictionaries()", res);
115     }
116 
117     /**
118     * Test calls the method, makes some actions that leads to event
119     * <code>processDictionaryListEvent</code>, removes listener, checks flag
120     * <code>listenerCalled</code> and checks returned value. <p>
121     * Has <b> OK </b> status if returned value is true and value of flag
122     * <code>listenerCallled</code> is true. <p>
123     */
124     public void _addDictionaryListEventListener() {
125         listenerCalled = false;
126 
127         XDictionary xDic = oObj.createDictionary("ListenDic",
128             new Locale("en","US","WIN"),
129             com.sun.star.linguistic2.DictionaryType.POSITIVE,"");
130 
131         boolean res = oObj.addDictionaryListEventListener(listener, false);
132 
133         oObj.flushEvents();
134         oObj.addDictionary(xDic);
135         xDic.add("Positiv", false, "");
136         xDic.setActive(true);
137         oObj.flushEvents();
138         oObj.removeDictionary(xDic);
139 
140         oObj.removeDictionaryListEventListener(listener);
141 
142         tRes.tested("addDictionaryListEventListener()",listenerCalled && res);
143     }
144 
145     /**
146     * Test calls the method, makes some actions that leads to event
147     * <code>processDictionaryListEvent</code>, checks flag
148     * <code>listenerCalled</code> and checks returned value. <p>
149     * Has <b> OK </b> status if returned value is false and value of flag
150     * <code>listenerCallled</code> is false. <p>
151     */
152     public void _removeDictionaryListEventListener() {
153         listenerCalled = false;
154 
155         XDictionary xDic = oObj.createDictionary("ListenDic",
156             new Locale("en","US","WIN"),
157             com.sun.star.linguistic2.DictionaryType.POSITIVE,"");
158 
159         oObj.addDictionaryListEventListener(listener,false);
160 
161         oObj.flushEvents();
162         oObj.addDictionary(xDic);
163         xDic.add("Positiv", false,"");
164         xDic.setActive(true);
165 
166         listenerCalled = false;
167         boolean res = oObj.removeDictionaryListEventListener(listener);
168 
169         oObj.flushEvents();
170         oObj.removeDictionary(xDic);
171 
172         tRes.tested(
173             "removeDictionaryListEventListener()",
174             listenerCalled == false && res == true );
175     }
176 
177     /**
178     * Test creates new dictionary, adds the dictionary to list and compares
179     * number of dictionaries after adding with number of dictionaries before.<p>
180     * Has <b> OK </b> status if number of dictionaries after method call is
181     * greater than number of dictionaries before method call. <p>
182     */
183     public void _addDictionary() {
184         short previous = oObj.getCount();
185         addedDic = oObj.createDictionary("AddedDic",new Locale("en","US","WIN"),
186                         com.sun.star.linguistic2.DictionaryType.POSITIVE,"");
187         addedDic.add("Positiv",false,"");
188 
189         oObj.addDictionary(addedDic);
190 
191         short after = oObj.getCount();
192 
193         tRes.tested( "addDictionary()", (after > previous) );
194     }
195 
196     /**
197     * Test calls the method and compares number of dictionaries
198     * before method call and after. <p>
199     * Has <b> OK </b> status if number of dictionaries before method call is
200     * less than number of dictionaries after method call. <p>
201     */
202     public void _removeDictionary() {
203         short previous = oObj.getCount();
204         oObj.removeDictionary(addedDic);
205         short after = oObj.getCount();
206         tRes.tested("removeDictionary()",(after < previous) );
207     }
208 
209     /**
210     * Test calls the method and checks returned value. <p>
211     * Has <b> OK </b> status if returned value isn't null. <p>
212     */
213     public void _getDictionaryByName() {
214         XDictionary getting = oObj.getDictionaryByName("NegativDic");
215         tRes.tested("getDictionaryByName()", getting != null );
216     }
217 
218     /**
219     * Test calls the method and checks returned value. <p>
220     * Has <b> OK </b> status if returned value isn't null. <p>
221     */
222     public void _createDictionary() {
223         XDictionary tmpDic = oObj.createDictionary("AddedDic",
224             new Locale("en","US","WIN"),
225             com.sun.star.linguistic2.DictionaryType.POSITIVE,"");
226         tRes.tested("createDictionary()", tmpDic != null );
227     }
228 
229     /**
230     * Test creates dictionary, adds dictionary list event listener,
231     * begins collect events, makes some actions that leads to event
232     * <code>processDictionaryListEvent</code>, ends collect events,
233     * removes the listener and checks the flag <code>listenerCalled</code> . <p>
234     * Has <b> OK </b> status if value of the flag is true. <p>
235     */
236     public void _beginCollectEvents() {
237         listenerCalled = false;
238 
239         XDictionary xDic = oObj.createDictionary("ListenDic",
240             new Locale("en","US","WIN"),
241             com.sun.star.linguistic2.DictionaryType.POSITIVE,"");
242 
243         oObj.addDictionaryListEventListener(listener,false);
244         oObj.beginCollectEvents();
245 
246         oObj.addDictionary(xDic);
247         xDic.add("Positiv",false,"");
248         xDic.setActive(true);
249 
250         oObj.removeDictionary(xDic);
251         oObj.endCollectEvents();
252 
253         oObj.removeDictionaryListEventListener(listener);
254 
255         tRes.tested("beginCollectEvents()", listenerCalled );
256     }
257 
258     /**
259     * Test does nothing. <p>
260     * Has <b> OK </b> status if method
261     * <code>addDictionaryListEventListener()</code> was completed
262     * successfully. <p>
263     * The following method tests are to be completed successfully before :
264     * <ul>
265     *  <li> <code> addDictionaryListEventListener() </code> :
266     *  if listener adding worked, flushEvents was already used and worked </li>
267     * </ul>
268     */
269     public void _flushEvents() {
270         requiredMethod("addDictionaryListEventListener()");
271         // if listener adding worked, flushEvents was already used and worked
272         tRes.tested("flushEvents()",true);
273     }
274 
275     /**
276     * Test does nothing. <p>
277     * Has <b> OK </b> status if method
278     * <code>beginCollectEvents()</code> was completed successfully. <p>
279     * The following method tests are to be completed successfully before :
280     * <ul>
281     *  <li> <code> beginCollectEvents() </code> :
282     *  if beginCollectEvents() worked then endCollectEvents was already
283     *  used and worked </li>
284     * </ul>
285     */
286     public void _endCollectEvents() {
287         requiredMethod("beginCollectEvents()");
288         // if beginCollectEvents() worked, endCollectEvents
289         // was already used and worked
290         tRes.tested("endCollectEvents()",true);
291     }
292 
293 }  // finish class _XDictionaryList
294 
295 
296