1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc
.linguistic2
;
30 import lib
.MultiMethodTest
;
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
;
40 * Testing <code>com.sun.star.linguistic2.XDictionaryList</code>
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>
55 * @see com.sun.star.linguistic2.XDictionaryList
57 public class _XDictionaryList
extends MultiMethodTest
{
59 public XDictionaryList oObj
= null;
60 public XDictionary addedDic
= null;
63 * Flag for testing of listeners.
65 public boolean listenerCalled
= false;
68 * Class implements interface <code>XDictionaryListEventListener</code>
69 * for test method <code>addDictionaryListEventListener</code>.
70 * @see com.sun.star.linguistic2.XDictionaryListEventListener
72 public class MyDictionaryListEventListener
implements
73 XDictionaryListEventListener
{
75 public void disposing ( EventObject oEvent
) {
76 log
.println("Listener has been disposed");
78 public void processDictionaryListEvent( DictionaryListEvent aDicEvent
) {
79 listenerCalled
= true;
83 XDictionaryListEventListener listener
= new MyDictionaryListEventListener();
88 * Test calls the method and checks returned value. <p>
89 * Has <b> OK </b> status if returned value is greater than zero. <p>
91 public void _getCount() {
92 count
= oObj
.getCount();
93 tRes
.tested("getCount()",(count
> 0) );
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 :
102 * <li> <code> getCount() </code> : to have number of dictionaries </li>
105 public void _getDictionaries() {
106 requiredMethod("getCount()");
108 XDictionary
[] dics
= oObj
.getDictionaries();
109 boolean res
= (dics
.length
== count
);
111 log
.println("Expected: " + oObj
.getCount());
112 log
.println("Gained: " + dics
.length
);
114 tRes
.tested("getDictionaries()", res
);
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>
124 public void _addDictionaryListEventListener() {
125 listenerCalled
= false;
127 XDictionary xDic
= oObj
.createDictionary("ListenDic",
128 new Locale("en","US","WIN"),
129 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
131 boolean res
= oObj
.addDictionaryListEventListener(listener
, false);
134 oObj
.addDictionary(xDic
);
135 xDic
.add("Positiv", false, "");
136 xDic
.setActive(true);
138 oObj
.removeDictionary(xDic
);
140 oObj
.removeDictionaryListEventListener(listener
);
142 tRes
.tested("addDictionaryListEventListener()",listenerCalled
&& res
);
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>
152 public void _removeDictionaryListEventListener() {
153 listenerCalled
= false;
155 XDictionary xDic
= oObj
.createDictionary("ListenDic",
156 new Locale("en","US","WIN"),
157 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
159 oObj
.addDictionaryListEventListener(listener
,false);
162 oObj
.addDictionary(xDic
);
163 xDic
.add("Positiv", false,"");
164 xDic
.setActive(true);
166 listenerCalled
= false;
167 boolean res
= oObj
.removeDictionaryListEventListener(listener
);
170 oObj
.removeDictionary(xDic
);
173 "removeDictionaryListEventListener()",
174 listenerCalled
== false && res
== true );
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>
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,"");
189 oObj
.addDictionary(addedDic
);
191 short after
= oObj
.getCount();
193 tRes
.tested( "addDictionary()", (after
> previous
) );
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>
202 public void _removeDictionary() {
203 short previous
= oObj
.getCount();
204 oObj
.removeDictionary(addedDic
);
205 short after
= oObj
.getCount();
206 tRes
.tested("removeDictionary()",(after
< previous
) );
210 * Test calls the method and checks returned value. <p>
211 * Has <b> OK </b> status if returned value isn't null. <p>
213 public void _getDictionaryByName() {
214 XDictionary getting
= oObj
.getDictionaryByName("NegativDic");
215 tRes
.tested("getDictionaryByName()", getting
!= null );
219 * Test calls the method and checks returned value. <p>
220 * Has <b> OK </b> status if returned value isn't null. <p>
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 );
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>
236 public void _beginCollectEvents() {
237 listenerCalled
= false;
239 XDictionary xDic
= oObj
.createDictionary("ListenDic",
240 new Locale("en","US","WIN"),
241 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
243 oObj
.addDictionaryListEventListener(listener
,false);
244 oObj
.beginCollectEvents();
246 oObj
.addDictionary(xDic
);
247 xDic
.add("Positiv",false,"");
248 xDic
.setActive(true);
250 oObj
.removeDictionary(xDic
);
251 oObj
.endCollectEvents();
253 oObj
.removeDictionaryListEventListener(listener
);
255 tRes
.tested("beginCollectEvents()", listenerCalled
);
259 * Test does nothing. <p>
260 * Has <b> OK </b> status if method
261 * <code>addDictionaryListEventListener()</code> was completed
263 * The following method tests are to be completed successfully before :
265 * <li> <code> addDictionaryListEventListener() </code> :
266 * if listener adding worked, flushEvents was already used and worked </li>
269 public void _flushEvents() {
270 requiredMethod("addDictionaryListEventListener()");
271 // if listener adding worked, flushEvents was already used and worked
272 tRes
.tested("flushEvents()",true);
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 :
281 * <li> <code> beginCollectEvents() </code> :
282 * if beginCollectEvents() worked then endCollectEvents was already
283 * used and worked </li>
286 public void _endCollectEvents() {
287 requiredMethod("beginCollectEvents()");
288 // if beginCollectEvents() worked, endCollectEvents
289 // was already used and worked
290 tRes
.tested("endCollectEvents()",true);
293 } // finish class _XDictionaryList