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