2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc
.linguistic2
;
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.lang
.EventObject
;
24 import com
.sun
.star
.lang
.Locale
;
25 import com
.sun
.star
.linguistic2
.DictionaryListEvent
;
26 import com
.sun
.star
.linguistic2
.XDictionary
;
27 import com
.sun
.star
.linguistic2
.XDictionaryList
;
28 import com
.sun
.star
.linguistic2
.XDictionaryListEventListener
;
31 * Testing <code>com.sun.star.linguistic2.XDictionaryList</code>
34 * <li><code>getCount()</code></li>
35 * <li><code>getDictionaries()</code></li>
36 * <li><code>getDictionaryByName()</code></li>
37 * <li><code>addDictionary()</code></li>
38 * <li><code>removeDictionary()</code></li>
39 * <li><code>addDictionaryListEventListener()</code></li>
40 * <li><code>removeDictionaryListEventListener()</code></li>
41 * <li><code>beginCollectEvents()</code></li>
42 * <li><code>endCollectEvents()</code></li>
43 * <li><code>flushEvents()</code></li>
44 * <li><code>createDictionary()</code></li>
46 * @see com.sun.star.linguistic2.XDictionaryList
48 public class _XDictionaryList
extends MultiMethodTest
{
50 public XDictionaryList oObj
= null;
51 public XDictionary addedDic
= null;
54 * Flag for testing of listeners.
56 public boolean listenerCalled
= false;
59 * Class implements interface <code>XDictionaryListEventListener</code>
60 * for test method <code>addDictionaryListEventListener</code>.
61 * @see com.sun.star.linguistic2.XDictionaryListEventListener
63 public class MyDictionaryListEventListener
implements
64 XDictionaryListEventListener
{
66 public void disposing ( EventObject oEvent
) {
67 log
.println("Listener has been disposed");
69 public void processDictionaryListEvent( DictionaryListEvent aDicEvent
) {
70 listenerCalled
= true;
74 XDictionaryListEventListener listener
= new MyDictionaryListEventListener();
79 * Test calls the method and checks returned value. <p>
80 * Has <b> OK </b> status if returned value is greater than zero. <p>
82 public void _getCount() {
83 count
= oObj
.getCount();
84 tRes
.tested("getCount()",(count
> 0) );
88 * Test calls the method and checks number of obtained dictionaries
89 * with value that was returned by method <code>getCount</code>. <p>
90 * Has <b> OK </b> status if values are equal. <p>
91 * The following method tests are to be completed successfully before :
93 * <li> <code> getCount() </code> : to have number of dictionaries </li>
96 public void _getDictionaries() {
97 requiredMethod("getCount()");
99 XDictionary
[] dics
= oObj
.getDictionaries();
100 boolean res
= (dics
.length
== count
);
102 log
.println("Expected: " + oObj
.getCount());
103 log
.println("Gained: " + dics
.length
);
105 tRes
.tested("getDictionaries()", res
);
109 * Test calls the method, makes some actions that leads to event
110 * <code>processDictionaryListEvent</code>, removes listener, checks flag
111 * <code>listenerCalled</code> and checks returned value. <p>
112 * Has <b> OK </b> status if returned value is true and value of flag
113 * <code>listenerCalled</code> is true. <p>
115 public void _addDictionaryListEventListener() {
116 listenerCalled
= false;
118 XDictionary xDic
= oObj
.createDictionary("ListenDic",
119 new Locale("en","US","WIN"),
120 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
122 boolean res
= oObj
.addDictionaryListEventListener(listener
, false);
125 oObj
.addDictionary(xDic
);
126 xDic
.add("Positive", false, "");
127 xDic
.setActive(true);
129 oObj
.removeDictionary(xDic
);
131 oObj
.removeDictionaryListEventListener(listener
);
133 tRes
.tested("addDictionaryListEventListener()",listenerCalled
&& res
);
137 * Test calls the method, makes some actions that leads to event
138 * <code>processDictionaryListEvent</code>, checks flag
139 * <code>listenerCalled</code> and checks returned value. <p>
140 * Has <b> OK </b> status if returned value is false and value of flag
141 * <code>listenerCalled</code> is false. <p>
143 public void _removeDictionaryListEventListener() {
144 listenerCalled
= false;
146 XDictionary xDic
= oObj
.createDictionary("ListenDic",
147 new Locale("en","US","WIN"),
148 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
150 oObj
.addDictionaryListEventListener(listener
,false);
153 oObj
.addDictionary(xDic
);
154 xDic
.add("Positive", false,"");
155 xDic
.setActive(true);
157 listenerCalled
= false;
158 boolean res
= oObj
.removeDictionaryListEventListener(listener
);
161 oObj
.removeDictionary(xDic
);
164 "removeDictionaryListEventListener()",
165 !listenerCalled
&& res
);
169 * Test creates new dictionary, adds the dictionary to list and compares
170 * number of dictionaries after adding with number of dictionaries before.<p>
171 * Has <b> OK </b> status if number of dictionaries after method call is
172 * greater than number of dictionaries before method call. <p>
174 public void _addDictionary() {
175 short previous
= oObj
.getCount();
176 addedDic
= oObj
.createDictionary("AddedDic",new Locale("en","US","WIN"),
177 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
178 addedDic
.add("Positive",false,"");
180 oObj
.addDictionary(addedDic
);
182 short after
= oObj
.getCount();
184 tRes
.tested( "addDictionary()", (after
> previous
) );
188 * Test calls the method and compares number of dictionaries
189 * before method call and after. <p>
190 * Has <b> OK </b> status if number of dictionaries before method call is
191 * less than number of dictionaries after method call. <p>
193 public void _removeDictionary() {
194 short previous
= oObj
.getCount();
195 oObj
.removeDictionary(addedDic
);
196 short after
= oObj
.getCount();
197 tRes
.tested("removeDictionary()",(after
< previous
) );
201 * Test calls the method and checks returned value. <p>
202 * Has <b> OK </b> status if returned value isn't null. <p>
204 public void _getDictionaryByName() {
205 XDictionary getting
= oObj
.getDictionaryByName("NegativDic");
206 tRes
.tested("getDictionaryByName()", getting
!= null );
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 _createDictionary() {
214 XDictionary tmpDic
= oObj
.createDictionary("AddedDic",
215 new Locale("en","US","WIN"),
216 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
217 tRes
.tested("createDictionary()", tmpDic
!= null );
221 * Test creates dictionary, adds dictionary list event listener,
222 * begins collect events, makes some actions that leads to event
223 * <code>processDictionaryListEvent</code>, ends collect events,
224 * removes the listener and checks the flag <code>listenerCalled</code> . <p>
225 * Has <b> OK </b> status if value of the flag is true. <p>
227 public void _beginCollectEvents() {
228 listenerCalled
= false;
230 XDictionary xDic
= oObj
.createDictionary("ListenDic",
231 new Locale("en","US","WIN"),
232 com
.sun
.star
.linguistic2
.DictionaryType
.POSITIVE
,"");
234 oObj
.addDictionaryListEventListener(listener
,false);
235 oObj
.beginCollectEvents();
237 oObj
.addDictionary(xDic
);
238 xDic
.add("Positive",false,"");
239 xDic
.setActive(true);
241 oObj
.removeDictionary(xDic
);
242 oObj
.endCollectEvents();
244 oObj
.removeDictionaryListEventListener(listener
);
246 tRes
.tested("beginCollectEvents()", listenerCalled
);
250 * Test does nothing. <p>
251 * Has <b> OK </b> status if method
252 * <code>addDictionaryListEventListener()</code> was completed
254 * The following method tests are to be completed successfully before :
256 * <li> <code> addDictionaryListEventListener() </code> :
257 * if listener adding worked, flushEvents was already used and worked </li>
260 public void _flushEvents() {
261 requiredMethod("addDictionaryListEventListener()");
262 // if listener adding worked, flushEvents was already used and worked
263 tRes
.tested("flushEvents()",true);
267 * Test does nothing. <p>
268 * Has <b> OK </b> status if method
269 * <code>beginCollectEvents()</code> was completed successfully. <p>
270 * The following method tests are to be completed successfully before :
272 * <li> <code> beginCollectEvents() </code> :
273 * if beginCollectEvents() worked then endCollectEvents was already
274 * used and worked </li>
277 public void _endCollectEvents() {
278 requiredMethod("beginCollectEvents()");
279 // if beginCollectEvents() worked, endCollectEvents
280 // was already used and worked
281 tRes
.tested("endCollectEvents()",true);
284 } // finish class _XDictionaryList