1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDictionaryList.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc
.linguistic2
;
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.lang
.EventObject
;
36 import com
.sun
.star
.lang
.Locale
;
37 import com
.sun
.star
.linguistic2
.DictionaryListEvent
;
38 import com
.sun
.star
.linguistic2
.XDictionary
;
39 import com
.sun
.star
.linguistic2
.XDictionaryList
;
40 import com
.sun
.star
.linguistic2
.XDictionaryListEventListener
;
43 * Testing <code>com.sun.star.linguistic2.XDictionaryList</code>
46 * <li><code>getCount()</code></li>
47 * <li><code>getDictionaries()</code></li>
48 * <li><code>getDictionaryByName()</code></li>
49 * <li><code>addDictionary()</code></li>
50 * <li><code>removeDictionary()</code></li>
51 * <li><code>addDictionaryListEventListener()</code></li>
52 * <li><code>removeDictionaryListEventListener()</code></li>
53 * <li><code>beginCollectEvents()</code></li>
54 * <li><code>endCollectEvents()</code></li>
55 * <li><code>flushEvents()</code></li>
56 * <li><code>createDictionary()</code></li>
58 * @see com.sun.star.linguistic2.XDictionaryList
60 public class _XDictionaryList
extends MultiMethodTest
{
62 public XDictionaryList oObj
= null;
63 public XDictionary addedDic
= null;
66 * Flag for testing of listeners.
68 public boolean listenerCalled
= false;
71 * Class implements interface <code>XDictionaryListEventListener</code>
72 * for test method <code>addDictionaryListEventListener</code>.
73 * @see com.sun.star.linguistic2.XDictionaryListEventListener
75 public class MyDictionaryListEventListener
implements
76 XDictionaryListEventListener
{
78 public void disposing ( EventObject oEvent
) {
79 log
.println("Listener has been disposed");
81 public void processDictionaryListEvent( DictionaryListEvent aDicEvent
) {
82 listenerCalled
= true;
86 XDictionaryListEventListener listener
= new MyDictionaryListEventListener();
91 * Test calls the method and checks returned value. <p>
92 * Has <b> OK </b> status if returned value is greater than zero. <p>
94 public void _getCount() {
95 count
= oObj
.getCount();
96 tRes
.tested("getCount()",(count
> 0) );
100 * Test calls the method and checks number of obtained dictionaries
101 * with value that was returned by method <code>getCount</code>. <p>
102 * Has <b> OK </b> status if values are equal. <p>
103 * The following method tests are to be completed successfully before :
105 * <li> <code> getCount() </code> : to have number of dictionaries </li>
108 public void _getDictionaries() {
109 requiredMethod("getCount()");
111 XDictionary
[] dics
= oObj
.getDictionaries();
112 boolean res
= (dics
.length
== count
);
114 log
.println("Expected: " + oObj
.getCount());
115 log
.println("Gained: " + dics
.length
);
117 tRes
.tested("getDictionaries()", res
);
121 * Test calls the method, makes some actions that leads to event
122 * <code>processDictionaryListEvent</code>, removes listener, checks flag
123 * <code>listenerCalled</code> and checks returned value. <p>
124 * Has <b> OK </b> status if returned value is true and value of flag
125 * <code>listenerCallled</code> is true. <p>
127 public void _addDictionaryListEventListener() {
128 listenerCalled
= false;
130 XDictionary xDic
= oObj
.createDictionary("ListenDic",
131 new Locale("en","US","WIN"),
132 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
134 boolean res
= oObj
.addDictionaryListEventListener(listener
, false);
137 oObj
.addDictionary(xDic
);
138 xDic
.add("Positiv", false, "");
139 xDic
.setActive(true);
141 oObj
.removeDictionary(xDic
);
143 oObj
.removeDictionaryListEventListener(listener
);
145 tRes
.tested("addDictionaryListEventListener()",listenerCalled
&& res
);
149 * Test calls the method, makes some actions that leads to event
150 * <code>processDictionaryListEvent</code>, checks flag
151 * <code>listenerCalled</code> and checks returned value. <p>
152 * Has <b> OK </b> status if returned value is false and value of flag
153 * <code>listenerCallled</code> is false. <p>
155 public void _removeDictionaryListEventListener() {
156 listenerCalled
= false;
158 XDictionary xDic
= oObj
.createDictionary("ListenDic",
159 new Locale("en","US","WIN"),
160 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
162 oObj
.addDictionaryListEventListener(listener
,false);
165 oObj
.addDictionary(xDic
);
166 xDic
.add("Positiv", false,"");
167 xDic
.setActive(true);
169 listenerCalled
= false;
170 boolean res
= oObj
.removeDictionaryListEventListener(listener
);
173 oObj
.removeDictionary(xDic
);
176 "removeDictionaryListEventListener()",
177 listenerCalled
== false && res
== true );
181 * Test creates new dictionary, adds the dictionary to list and compares
182 * number of dictionaries after adding with number of dictionaries before.<p>
183 * Has <b> OK </b> status if number of dictionaries after method call is
184 * greater than number of dictionaries before method call. <p>
186 public void _addDictionary() {
187 short previous
= oObj
.getCount();
188 addedDic
= oObj
.createDictionary("AddedDic",new Locale("en","US","WIN"),
189 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
190 addedDic
.add("Positiv",false,"");
192 oObj
.addDictionary(addedDic
);
194 short after
= oObj
.getCount();
196 tRes
.tested( "addDictionary()", (after
> previous
) );
200 * Test calls the method and compares number of dictionaries
201 * before method call and after. <p>
202 * Has <b> OK </b> status if number of dictionaries before method call is
203 * less than number of dictionaries after method call. <p>
205 public void _removeDictionary() {
206 short previous
= oObj
.getCount();
207 oObj
.removeDictionary(addedDic
);
208 short after
= oObj
.getCount();
209 tRes
.tested("removeDictionary()",(after
< previous
) );
213 * Test calls the method and checks returned value. <p>
214 * Has <b> OK </b> status if returned value isn't null. <p>
216 public void _getDictionaryByName() {
217 XDictionary getting
= oObj
.getDictionaryByName("NegativDic");
218 tRes
.tested("getDictionaryByName()", getting
!= null );
222 * Test calls the method and checks returned value. <p>
223 * Has <b> OK </b> status if returned value isn't null. <p>
225 public void _createDictionary() {
226 XDictionary tmpDic
= oObj
.createDictionary("AddedDic",
227 new Locale("en","US","WIN"),
228 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
229 tRes
.tested("createDictionary()", tmpDic
!= null );
233 * Test creates dictionary, adds dictionary list event listener,
234 * begins collect events, makes some actions that leads to event
235 * <code>processDictionaryListEvent</code>, ends collect events,
236 * removes the listener and checks the flag <code>listenerCalled</code> . <p>
237 * Has <b> OK </b> status if value of the flag is true. <p>
239 public void _beginCollectEvents() {
240 listenerCalled
= false;
242 XDictionary xDic
= oObj
.createDictionary("ListenDic",
243 new Locale("en","US","WIN"),
244 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
246 oObj
.addDictionaryListEventListener(listener
,false);
247 oObj
.beginCollectEvents();
249 oObj
.addDictionary(xDic
);
250 xDic
.add("Positiv",false,"");
251 xDic
.setActive(true);
253 oObj
.removeDictionary(xDic
);
254 oObj
.endCollectEvents();
256 oObj
.removeDictionaryListEventListener(listener
);
258 tRes
.tested("beginCollectEvents()", listenerCalled
);
262 * Test does nothing. <p>
263 * Has <b> OK </b> status if method
264 * <code>addDictionaryListEventListener()</code> was completed
266 * The following method tests are to be completed successfully before :
268 * <li> <code> addDictionaryListEventListener() </code> :
269 * if listener adding worked, flushEvents was already used and worked </li>
272 public void _flushEvents() {
273 requiredMethod("addDictionaryListEventListener()");
274 // if listener adding worked, flushEvents was already used and worked
275 tRes
.tested("flushEvents()",true);
279 * Test does nothing. <p>
280 * Has <b> OK </b> status if method
281 * <code>beginCollectEvents()</code> was completed successfully. <p>
282 * The following method tests are to be completed successfully before :
284 * <li> <code> beginCollectEvents() </code> :
285 * if beginCollectEvents() worked then endCollectEvents was already
286 * used and worked </li>
289 public void _endCollectEvents() {
290 requiredMethod("beginCollectEvents()");
291 // if beginCollectEvents() worked, endCollectEvents
292 // was already used and worked
293 tRes
.tested("endCollectEvents()",true);
296 } // finish class _XDictionaryList