1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 19 package ifc.linguistic2; 20 21 import lib.MultiMethodTest; 22 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; 29 30 /** 31 * Testing <code>com.sun.star.linguistic2.XDictionaryList</code> 32 * interface methods: 33 * <ul> 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> 45 * </ul> <p> 46 * @see com.sun.star.linguistic2.XDictionaryList 47 */ 48 public class _XDictionaryList extends MultiMethodTest { 49 50 public XDictionaryList oObj = null; 51 public XDictionary addedDic = null; 52 53 /** 54 * Flag for testing of listeners. 55 */ 56 public boolean listenerCalled = false; 57 58 /** 59 * Class implements interface <code>XDictionaryListEventListener</code> 60 * for test method <code>addDictionaryListEventListener</code>. 61 * @see com.sun.star.linguistic2.XDictionaryListEventListener 62 */ 63 public class MyDictionaryListEventListener implements 64 XDictionaryListEventListener { 65 disposing( EventObject oEvent )66 public void disposing ( EventObject oEvent ) { 67 log.println("Listener has been disposed"); 68 } processDictionaryListEvent( DictionaryListEvent aDicEvent)69 public void processDictionaryListEvent( DictionaryListEvent aDicEvent) { 70 listenerCalled = true; 71 } 72 } 73 74 XDictionaryListEventListener listener = new MyDictionaryListEventListener(); 75 76 short count = 0; 77 78 /** 79 * Test calls the method and checks returned value. <p> 80 * Has <b> OK </b> status if returned value is greater than zero. <p> 81 */ _getCount()82 public void _getCount() { 83 count = oObj.getCount(); 84 tRes.tested("getCount()",(count > 0) ); 85 } 86 87 /** 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 : 92 * <ul> 93 * <li> <code> getCount() </code> : to have number of dictionaries </li> 94 * </ul> 95 */ _getDictionaries()96 public void _getDictionaries() { 97 requiredMethod("getCount()"); 98 99 XDictionary[] dics = oObj.getDictionaries(); 100 boolean res = (dics.length == count); 101 if (!res) { 102 log.println("Expected: " + oObj.getCount()); 103 log.println("Gained: " + dics.length); 104 } 105 tRes.tested("getDictionaries()", res); 106 } 107 108 /** 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> 114 */ _addDictionaryListEventListener()115 public void _addDictionaryListEventListener() { 116 listenerCalled = false; 117 118 XDictionary xDic = oObj.createDictionary("ListenDic", 119 new Locale("en","US","WIN"), 120 com.sun.star.linguistic2.DictionaryType.POSITIVE,""); 121 122 boolean res = oObj.addDictionaryListEventListener(listener, false); 123 124 oObj.flushEvents(); 125 oObj.addDictionary(xDic); 126 xDic.add("Positive", false, ""); 127 xDic.setActive(true); 128 oObj.flushEvents(); 129 oObj.removeDictionary(xDic); 130 131 oObj.removeDictionaryListEventListener(listener); 132 133 tRes.tested("addDictionaryListEventListener()",listenerCalled && res); 134 } 135 136 /** 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> 142 */ _removeDictionaryListEventListener()143 public void _removeDictionaryListEventListener() { 144 listenerCalled = false; 145 146 XDictionary xDic = oObj.createDictionary("ListenDic", 147 new Locale("en","US","WIN"), 148 com.sun.star.linguistic2.DictionaryType.POSITIVE,""); 149 150 oObj.addDictionaryListEventListener(listener,false); 151 152 oObj.flushEvents(); 153 oObj.addDictionary(xDic); 154 xDic.add("Positive", false,""); 155 xDic.setActive(true); 156 157 listenerCalled = false; 158 boolean res = oObj.removeDictionaryListEventListener(listener); 159 160 oObj.flushEvents(); 161 oObj.removeDictionary(xDic); 162 163 tRes.tested( 164 "removeDictionaryListEventListener()", 165 !listenerCalled && res ); 166 } 167 168 /** 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> 173 */ _addDictionary()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,""); 179 180 oObj.addDictionary(addedDic); 181 182 short after = oObj.getCount(); 183 184 tRes.tested( "addDictionary()", (after > previous) ); 185 } 186 187 /** 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> 192 */ _removeDictionary()193 public void _removeDictionary() { 194 short previous = oObj.getCount(); 195 oObj.removeDictionary(addedDic); 196 short after = oObj.getCount(); 197 tRes.tested("removeDictionary()",(after < previous) ); 198 } 199 200 /** 201 * Test calls the method and checks returned value. <p> 202 * Has <b> OK </b> status if returned value isn't null. <p> 203 */ _getDictionaryByName()204 public void _getDictionaryByName() { 205 XDictionary getting = oObj.getDictionaryByName("NegativDic"); 206 tRes.tested("getDictionaryByName()", getting != null ); 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 */ _createDictionary()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 ); 218 } 219 220 /** 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> 226 */ _beginCollectEvents()227 public void _beginCollectEvents() { 228 listenerCalled = false; 229 230 XDictionary xDic = oObj.createDictionary("ListenDic", 231 new Locale("en","US","WIN"), 232 com.sun.star.linguistic2.DictionaryType.POSITIVE,""); 233 234 oObj.addDictionaryListEventListener(listener,false); 235 oObj.beginCollectEvents(); 236 237 oObj.addDictionary(xDic); 238 xDic.add("Positive",false,""); 239 xDic.setActive(true); 240 241 oObj.removeDictionary(xDic); 242 oObj.endCollectEvents(); 243 244 oObj.removeDictionaryListEventListener(listener); 245 246 tRes.tested("beginCollectEvents()", listenerCalled ); 247 } 248 249 /** 250 * Test does nothing. <p> 251 * Has <b> OK </b> status if method 252 * <code>addDictionaryListEventListener()</code> was completed 253 * successfully. <p> 254 * The following method tests are to be completed successfully before : 255 * <ul> 256 * <li> <code> addDictionaryListEventListener() </code> : 257 * if listener adding worked, flushEvents was already used and worked </li> 258 * </ul> 259 */ _flushEvents()260 public void _flushEvents() { 261 requiredMethod("addDictionaryListEventListener()"); 262 // if listener adding worked, flushEvents was already used and worked 263 tRes.tested("flushEvents()",true); 264 } 265 266 /** 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 : 271 * <ul> 272 * <li> <code> beginCollectEvents() </code> : 273 * if beginCollectEvents() worked then endCollectEvents was already 274 * used and worked </li> 275 * </ul> 276 */ _endCollectEvents()277 public void _endCollectEvents() { 278 requiredMethod("beginCollectEvents()"); 279 // if beginCollectEvents() worked, endCollectEvents 280 // was already used and worked 281 tRes.tested("endCollectEvents()",true); 282 } 283 284 } // finish class _XDictionaryList 285 286 287